SQL Unique Key

6.What happens when you insert duplicate value in a UNIQUE column?
  • A. It overwrites
  • B. It inserts NULL
  • C. It throws an error
  • D. It updates the value

It throws an error

It throws an error

7.Which of the following is true about UNIQUE vs PRIMARY KEY?
  • A. Both allow duplicates
  • B. UNIQUE can have NULLs, PRIMARY cannot
  • C. UNIQUE is faster
  • D. PRIMARY KEY can be multiple per table

UNIQUE can have NULLs, PRIMARY cannot

UNIQUE can have NULLs, PRIMARY cannot

8.What would be the result of the given code?
CREATE TABLE login ( user_id INT, username VARCHAR(50) UNIQUE ); INSERT INTO login VALUES (1, 'ashu'); INSERT INTO login VALUES (2, 'ashu');
  • A. Both inserted
  • B. Second row rejected
  • C. Username becomes NULL
  • D. AUTO_INCREMENT

Second row rejected

Second row rejected

9.What happens to the below code?
CREATE TABLE employee ( emp_id INT, email VARCHAR(50) UNIQUE ); ALTER TABLE employee DROP CONSTRAINT email;
  • A. Unique removed
  • B. Error: constraint not found
  • C. Column deleted
  • D. Table dropped

Error: constraint not found

Error: constraint not found

10.Which statement defines a UNIQUE constraint during table creation?
  • A. column_name UNIQUE
  • B. UNIQUE(column_name)
  • C. CONSTRAINT u UNIQUE(column_name)
  • D. All of the above

All of the above

All of the above