Bird
0
0

Which of the following statements correctly adds a UNIQUE constraint when creating a new table?

easy📝 Conceptual Q2 of 15
SQL - Table Constraints
Which of the following statements correctly adds a UNIQUE constraint when creating a new table?
ACREATE TABLE users (id INT, email VARCHAR(100) NOT NULL);
BCREATE TABLE users (id INT, email VARCHAR(100) PRIMARY KEY);
CCREATE TABLE users (id INT, email VARCHAR(100) UNIQUE);
DCREATE TABLE users (id INT, email VARCHAR(100) FOREIGN KEY);
Step-by-Step Solution
Solution:
  1. Step 1: Review syntax for UNIQUE constraint in CREATE TABLE

    Adding UNIQUE after the column type enforces uniqueness on that column.
  2. Step 2: Eliminate other options

    PRIMARY KEY also enforces uniqueness but is different; NOT NULL only disallows NULLs; FOREIGN KEY is unrelated.
  3. Final Answer:

    CREATE TABLE users (id INT, email VARCHAR(100) UNIQUE); -> Option C
  4. Quick Check:

    UNIQUE syntax in column definition = correct [OK]
Quick Trick: Add UNIQUE right after column type to enforce uniqueness [OK]
Common Mistakes:
MISTAKES
  • Using PRIMARY KEY instead of UNIQUE
  • Confusing NOT NULL with UNIQUE
  • Trying to use FOREIGN KEY to enforce uniqueness

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes