0
0
SQLquery~20 mins

NOT NULL constraint behavior in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NOT NULL Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What happens when inserting NULL into a NOT NULL column?
Consider a table Users with a column username defined as VARCHAR(50) NOT NULL. What will be the result of this query?
INSERT INTO Users (username) VALUES (NULL);
SQL
CREATE TABLE Users (id INT PRIMARY KEY, username VARCHAR(50) NOT NULL);
INSERT INTO Users (id, username) VALUES (1, 'Alice');
INSERT INTO Users (username) VALUES (NULL);
AThe insertion fails with a NOT NULL constraint violation error.
BThe insertion succeeds and stores NULL in the username column.
CThe insertion succeeds and stores an empty string ('') in the username column.
DThe insertion succeeds but the username column is automatically set to a default value.
Attempts:
2 left
💡 Hint
Think about what NOT NULL means for a column's values.
query_result
intermediate
2:00remaining
What is the output of selecting rows with NULL in a NOT NULL column?
Given a table Products with a price column defined as DECIMAL NOT NULL, what will this query return?
SELECT * FROM Products WHERE price IS NULL;
SQL
CREATE TABLE Products (id INT PRIMARY KEY, price DECIMAL NOT NULL);
INSERT INTO Products VALUES (1, 10.5), (2, 20.0);
ANo rows are returned because price cannot be NULL.
BAll rows are returned because price IS NULL matches all values.
CAn error occurs because price is NOT NULL and cannot be checked for NULL.
DOnly rows with price 0 are returned.
Attempts:
2 left
💡 Hint
Think about whether NULL values can exist in a NOT NULL column.
📝 Syntax
advanced
2:00remaining
Which table definition correctly enforces NOT NULL on a column?
Which of the following SQL statements correctly creates a table with a NOT NULL constraint on the email column?
ACREATE TABLE Contacts (id INT, email VARCHAR(100) NULL NOT);
BCREATE TABLE Contacts (id INT, email VARCHAR(100) NOT NULL NULL);
CCREATE TABLE Contacts (id INT, email VARCHAR(100) NOT NULL);
DCREATE TABLE Contacts (id INT, email VARCHAR(100) NOTNULL);
Attempts:
2 left
💡 Hint
Check the correct syntax for NOT NULL in SQL column definitions.
optimization
advanced
2:00remaining
How does NOT NULL constraint affect query performance?
Which statement best describes how a NOT NULL constraint on a column can impact query performance?
ANOT NULL constraints have no impact on query performance.
BNOT NULL constraints slow down queries because the database must check for NULL values.
CNOT NULL constraints cause the database to store extra metadata, reducing performance.
DNOT NULL constraints allow the database to optimize queries by skipping NULL checks, improving performance.
Attempts:
2 left
💡 Hint
Think about how knowing a column cannot be NULL helps the database.
🧠 Conceptual
expert
3:00remaining
Why might a NOT NULL constraint be preferred over a default value?
Which reason best explains why a database designer might choose to use a NOT NULL constraint without a default value on a column?
ATo allow NULL values but treat them as zero internally.
BTo ensure that every row explicitly provides a meaningful value, avoiding hidden defaults.
CTo automatically fill missing values with the current timestamp.
DTo improve storage efficiency by compressing NULL values.
Attempts:
2 left
💡 Hint
Consider the difference between forcing explicit input and silently filling values.