SQL - Table ConstraintsWhich of the following is the correct syntax to add a NOT NULL constraint to a column named email in SQL?AALTER TABLE users ALTER COLUMN email SET NOT NULL;BALTER TABLE users ADD CONSTRAINT email NOT NULL;CALTER TABLE users MODIFY email NOT NULL;DALTER TABLE users CHANGE email TO NOT NULL;Check Answer
Step-by-Step SolutionSolution:Step 1: Recall SQL syntax for NOT NULL constraintTo set a column NOT NULL, the standard syntax is ALTER TABLE table ALTER COLUMN column SET NOT NULL.Step 2: Match syntax with optionsALTER TABLE users ALTER COLUMN email SET NOT NULL; matches the correct syntax. Options A, B, and D use incorrect or invalid syntax.Final Answer:ALTER TABLE users ALTER COLUMN email SET NOT NULL; -> Option AQuick Check:ALTER COLUMN ... SET NOT NULL = Correct syntax [OK]Quick Trick: Use ALTER COLUMN ... SET NOT NULL to add NOT NULL [OK]Common Mistakes:MISTAKESUsing ADD CONSTRAINT without naming the constraintUsing MODIFY or CHANGE which are not standard SQLConfusing syntax with other SQL dialects
Master "Table Constraints" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Joins - CROSS JOIN cartesian product - Quiz 2easy GROUP BY and HAVING - HAVING clause for filtering groups - Quiz 15hard GROUP BY and HAVING - GROUP BY single column - Quiz 9hard LEFT and RIGHT JOIN - LEFT JOIN preserving all left rows - Quiz 14medium LEFT and RIGHT JOIN - RIGHT JOIN execution behavior - Quiz 12easy LEFT and RIGHT JOIN - LEFT JOIN with NULL result rows - Quiz 5medium Set Operations - EXCEPT (MINUS) for differences - Quiz 9hard Subqueries - Subquery in FROM clause (derived table) - Quiz 15hard Table Constraints - FOREIGN KEY constraint - Quiz 5medium Table Relationships - ER diagram to table mapping - Quiz 6medium