SQL - Table ConstraintsWhich 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);Check Answer
Step-by-Step SolutionSolution:Step 1: Review syntax for UNIQUE constraint in CREATE TABLEAdding UNIQUE after the column type enforces uniqueness on that column.Step 2: Eliminate other optionsPRIMARY KEY also enforces uniqueness but is different; NOT NULL only disallows NULLs; FOREIGN KEY is unrelated.Final Answer:CREATE TABLE users (id INT, email VARCHAR(100) UNIQUE); -> Option CQuick Check:UNIQUE syntax in column definition = correct [OK]Quick Trick: Add UNIQUE right after column type to enforce uniqueness [OK]Common Mistakes:MISTAKESUsing PRIMARY KEY instead of UNIQUEConfusing NOT NULL with UNIQUETrying to use FOREIGN KEY to enforce uniqueness
Master "Table Constraints" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Joins - Why advanced joins matter - Quiz 14medium Aggregate Functions - Why aggregation is needed - Quiz 2easy Aggregate Functions - SUM function - Quiz 4medium GROUP BY and HAVING - GROUP BY with ORDER BY - Quiz 12easy LEFT and RIGHT JOIN - Multiple LEFT JOINs in one query - Quiz 14medium Set Operations - Set operation column matching rules - Quiz 8hard Table Relationships - One-to-many relationship design - Quiz 10hard Table Relationships - ER diagram to table mapping - Quiz 6medium Views - Dropping and altering views - Quiz 15hard Views - Views for security and abstraction - Quiz 15hard