Bird
0
0

Consider this table creation statement:

medium📝 Debug Q14 of 15
SQL - Table Constraints

Consider this table creation statement:

CREATE TABLE products (
product_id INT PRIMARY KEY,
product_name VARCHAR(50) NOT NULL,
price DECIMAL(5,2)
);

Which of the following statements will cause an error?

AINSERT INTO products (product_id, product_name, price) VALUES (1, 'Pen', 1.50);
BINSERT INTO products (product_id, price) VALUES (2, 2.00);
CINSERT INTO products (product_id, product_name) VALUES (3, 'Notebook');
DINSERT INTO products (product_id, product_name, price) VALUES (4, 'Eraser', NULL);
Step-by-Step Solution
Solution:
  1. Step 1: Identify columns with NOT NULL constraint

    Only product_name has NOT NULL, so it must have a value on insert.
  2. Step 2: Check each insert statement

    INSERT INTO products (product_id, price) VALUES (2, 2.00); omits product_name, so it tries to insert NULL, causing an error. Others provide product_name.
  3. Final Answer:

    INSERT missing NOT NULL column product_name causes error. -> Option B
  4. Quick Check:

    NOT NULL columns must be included in insert [OK]
Quick Trick: Always provide values for NOT NULL columns on insert [OK]
Common Mistakes:
MISTAKES
  • Ignoring NOT NULL columns in insert
  • Assuming NULL allowed if column omitted
  • Confusing NULL and empty string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes