Bird
0
0

How can you modify the users table to ensure the email column cannot be NULL and has a default value of 'unknown@example.com'?

hard📝 Application Q9 of 15
SQL - Table Constraints

How can you modify the users table to ensure the email column cannot be NULL and has a default value of 'unknown@example.com'?

AALTER TABLE users SET email NOT NULL DEFAULT 'unknown@example.com';
BALTER TABLE users ADD CONSTRAINT email NOT NULL DEFAULT 'unknown@example.com';
CALTER TABLE users CHANGE email NOT NULL DEFAULT 'unknown@example.com';
DALTER TABLE users MODIFY email VARCHAR(100) NOT NULL DEFAULT 'unknown@example.com';
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to modify column constraints and defaults

    You must use MODIFY with the data type, NOT NULL, and DEFAULT value.
  2. Step 2: Check syntax correctness

    ALTER TABLE users MODIFY email VARCHAR(100) NOT NULL DEFAULT 'unknown@example.com'; correctly uses ALTER TABLE ... MODIFY column datatype NOT NULL DEFAULT value.
  3. Final Answer:

    ALTER TABLE users MODIFY email VARCHAR(100) NOT NULL DEFAULT 'unknown@example.com'; -> Option D
  4. Quick Check:

    Use MODIFY with NOT NULL and DEFAULT to change column [OK]
Quick Trick: Use MODIFY with datatype, NOT NULL, and DEFAULT [OK]
Common Mistakes:
MISTAKES
  • Using ADD CONSTRAINT incorrectly
  • Using CHANGE or SET with wrong syntax
  • Omitting data type in MODIFY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes