0
0
MySQLquery~5 mins

NOT NULL and DEFAULT constraints in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the NOT NULL constraint do in a MySQL table?
The NOT NULL constraint ensures that a column cannot have a NULL value. It means every row must have a value for that column.
Click to reveal answer
beginner
What is the purpose of the DEFAULT constraint in MySQL?
The DEFAULT constraint sets a default value for a column when no value is provided during data insertion.
Click to reveal answer
intermediate
Can a column have both NOT NULL and DEFAULT constraints? What happens if you insert a row without specifying that column's value?
Yes, a column can have both. If you insert a row without specifying the column's value, MySQL uses the DEFAULT value instead of NULL.
Click to reveal answer
beginner
Write a simple MySQL column definition using NOT NULL and DEFAULT constraints for a column named status with default value 'active'.
status VARCHAR(20) NOT NULL DEFAULT 'active'
Click to reveal answer
intermediate
What happens if you try to insert a NULL value into a NOT NULL column without a DEFAULT value?
MySQL will return an error and reject the insert because the column cannot accept NULL and no default value is provided.
Click to reveal answer
What does the NOT NULL constraint prevent?
AInserting NULL values into a column
BInserting duplicate values
CInserting default values
DDeleting rows
If a column has a DEFAULT value and you insert a row without specifying that column, what happens?
AThe insert fails
BThe column is left empty
CThe column is set to NULL
DThe column gets the default value
Which statement is true about a column defined as INT NOT NULL DEFAULT 0?
AIt can store NULL values
BIt must always have a value, defaulting to 0 if none is given
CIt cannot have a default value
DIt automatically increments
What error occurs if you insert NULL into a NOT NULL column without a default?
ASyntax error
BDuplicate entry error
CConstraint violation error
DNo error
Which constraint helps ensure a column always has a meaningful value?
ANOT NULL
BUNIQUE
CDEFAULT
DCHECK
Explain in your own words what the NOT NULL and DEFAULT constraints do in a database table.
Think about what happens when you insert data without specifying a column's value.
You got /3 concepts.
    Describe a real-life example where using NOT NULL and DEFAULT constraints would be helpful.
    Imagine a signup form where some fields must never be empty.
    You got /3 concepts.