Recall & Review
beginner
What does the
NOT NULL constraint do in a database?It ensures that a column cannot have
NULL values, meaning every row must have a value for that column.Click to reveal answer
beginner
How do you add a
NOT NULL constraint to a column when creating a table?Use
column_name datatype NOT NULL in the CREATE TABLE statement.Click to reveal answer
intermediate
Can a column with a
NOT NULL constraint accept empty strings ('')?Yes,
NOT NULL only prevents NULL values, but empty strings are considered valid values.Click to reveal answer
beginner
What happens if you try to insert a row without a value for a
NOT NULL column?The database will reject the insert and return an error because the column requires a value.
Click to reveal answer
intermediate
How can you add a
NOT NULL constraint to an existing column?Use an
ALTER TABLE statement like ALTER TABLE table_name ALTER COLUMN column_name SET NOT NULL; (syntax may vary by SQL dialect).Click to reveal answer
What does the
NOT NULL constraint prevent?✗ Incorrect
The
NOT NULL constraint stops NULL values from being inserted into the column.Which SQL keyword is used to define a column that cannot be NULL?
✗ Incorrect
The
NOT NULL keyword specifies that the column must have a value.If a column is defined as
NOT NULL, what happens if you try to insert a row without a value for that column?✗ Incorrect
The database rejects the insert because the column requires a non-NULL value.
Can a
NOT NULL column contain an empty string ('')?✗ Incorrect
Empty strings are valid values and different from NULL, so they are allowed.
How do you add a
NOT NULL constraint to an existing column in most SQL databases?✗ Incorrect
The standard way is to use
ALTER COLUMN column_name SET NOT NULL, but syntax can vary by database.Explain what the NOT NULL constraint does and why it is useful in a database.
Think about what happens if a column must always have a value.
You got /3 concepts.
Describe how you would add a NOT NULL constraint to a column in an existing table.
Consider how to change a column's rules after the table is created.
You got /3 concepts.