Column names and types must be inside parentheses after the table name.
Step 2: Verify other parts
Data types and table name are valid, and semicolon is present.
Final Answer:
Missing parentheses around column definitions. -> Option B
Quick Check:
Columns must be inside ( ) [OK]
Hint: Always use parentheses around columns in CREATE TABLE [OK]
Common Mistakes:
Omitting parentheses around columns
Using wrong data types without error
Confusing table name rules
5. You want to create a table Products with columns product_id (integer, unique), product_name (text), and price (decimal). Which SQL statement correctly enforces uniqueness on product_id using PRIMARY KEY?
hard
A. CREATE TABLE Products (product_id INT UNIQUE, product_name TEXT, price DECIMAL);
C. CREATE TABLE Products (product_id INT PRIMARY KEY, product_name TEXT, price DECIMAL);
D. CREATE TABLE Products (product_id INT, product_name TEXT UNIQUE, price DECIMAL);
Solution
Step 1: Understand uniqueness constraints
Both UNIQUE and PRIMARY KEY enforce uniqueness, but PRIMARY KEY also disallows NULLs and is preferred for IDs.
Step 2: Analyze options for correct uniqueness on product_id
CREATE TABLE Products (product_id INT UNIQUE, product_name TEXT, price DECIMAL); uses UNIQUE on product_id, which works but PRIMARY KEY is better. CREATE TABLE Products (product_id INT PRIMARY KEY, product_name TEXT, price DECIMAL); uses PRIMARY KEY on product_id, which is the best practice.
Final Answer:
CREATE TABLE Products (product_id INT PRIMARY KEY, product_name TEXT, price DECIMAL); -> Option C
Quick Check:
PRIMARY KEY = unique + not null [OK]
Hint: Use PRIMARY KEY for unique IDs [OK]
Common Mistakes:
Putting UNIQUE on wrong column
Confusing UNIQUE with PRIMARY KEY
Not enforcing uniqueness on ID column
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.