SQL Primary Key

1.What will happen?
CREATE TABLE students ( id INT PRIMARY KEY, name VARCHAR(50) ); INSERT INTO students VALUES (1, 'Alice'); INSERT INTO students VALUES (1, 'Bob');
  • A. Both rows inserted
  • B. Second insert overwrites
  • C. Error due to duplicate PRIMARY KEY
  • D. Table auto-increments

Error due to duplicate PRIMARY KEY

Error due to duplicate PRIMARY KEY

2.What will be the Output?
CREATE TABLE test ( id INT, name VARCHAR(20), PRIMARY KEY (id) ); INSERT INTO test VALUES (NULL, 'Ravi');
  • A. NULL inserted
  • B. Error: NULL not allowed in PRIMARY KEY
  • C. Default value is assigned
  • D. Column is auto-generated

Error: NULL not allowed in PRIMARY KEY

Error: NULL not allowed in PRIMARY KEY

3.What is a PRIMARY KEY used for?
  • A. To create indexes
  • B. To allow duplicate rows
  • C. To uniquely identify records
  • D. To auto-increment columns

To uniquely identify records

To uniquely identify records

4.Can a table have more than one PRIMARY KEY?
  • A. Yes
  • B. No

No

No

5.Which of the following is true about PRIMARY KEY?
  • A. Allows NULL values
  • B. Allows duplicates
  • C. Combines NOT NULL + UNIQUE
  • D. Has no constraints

Combines NOT NULL + UNIQUE

Combines NOT NULL + UNIQUE