5. You want to create a table orders with columns order_id (integer, primary key), customer_id (integer), and order_date (date). Which statement correctly creates this table with order_id as the primary key and ensures customer_id cannot be empty?
hard
A. CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT NOT NULL, order_date DATE);
B. CREATE TABLE orders (order_id INT, customer_id INT, order_date DATE, PRIMARY KEY order_id, NOT NULL customer_id);
C. CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT, order_date DATE NOT NULL);
D. CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT NULL, order_date DATE);
Solution
Step 1: Define primary key correctly
The order_id column must be declared as INT PRIMARY KEY inside the column definition.
Step 2: Ensure customer_id is NOT NULL
To prevent empty values, add NOT NULL after customer_id INT.
Step 3: Check order_date data type
order_date should be DATE without NOT NULL if empty dates allowed.
Final Answer:
CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT NOT NULL, order_date DATE); -> Option A
Quick Check:
Primary key + NOT NULL constraint syntax correct [OK]
Hint: Use NOT NULL to prevent empty columns [OK]
Common Mistakes:
Placing NOT NULL outside column definition
Incorrect PRIMARY KEY syntax
Confusing NULL and NOT NULL
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.