Which statement is true for primary key and a unique key?

  1. Both are same.

  2. A table can have multiple primary key and unique key.

  3. Primary keys does not allow null values, but unique key allows only one null value.

  4. Both does not allow null values


Correct Option: C

AI Explanation

To answer this question, we need to understand the concepts of primary key and unique key in a database.

A primary key is a column or a set of columns that uniquely identifies each row in a table. It is used to enforce entity integrity and ensure that each row in the table is unique.

A unique key, on the other hand, is a constraint that ensures that the values in a column or a set of columns are unique. Unlike a primary key, a unique key can allow null values.

Let's go through each option to understand why it is correct or incorrect:

Option A) Both are the same - This option is incorrect because primary key and unique key are not the same. While they both enforce uniqueness, there are differences in their behavior.

Option B) A table can have multiple primary keys and unique keys - This option is incorrect. A table can have only one primary key, which uniquely identifies each row. However, it can have multiple unique keys, which enforce uniqueness on different columns or combinations of columns.

Option C) Primary keys do not allow null values, but unique keys allow only one null value - This option is correct. Primary keys do not allow null values because they are used to uniquely identify each row. Unique keys, on the other hand, can allow one null value. This means that while unique keys enforce uniqueness, they allow one row to have a null value in the column(s) covered by the unique key.

Option D) Both do not allow null values - This option is incorrect. As mentioned earlier, primary keys do not allow null values, but unique keys can allow one null value.

Based on the explanations above, the correct answer is Option C. Primary keys do not allow null values, but unique keys allow only one null value.

Find more quizzes: