0
0
SQLquery~10 mins

Why constraints matter in SQL - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a table with a primary key constraint.

SQL
CREATE TABLE employees (id INT [1], name VARCHAR(100));
Drag options to blanks, or click blank then click option'
ACHECK
BFOREIGN KEY
CUNIQUE
DPRIMARY KEY
Attempts:
3 left
💡 Hint
Common Mistakes
Using FOREIGN KEY instead of PRIMARY KEY
Forgetting to add any constraint
2fill in blank
medium

Complete the code to add a NOT NULL constraint to the email column.

SQL
CREATE TABLE users (user_id INT PRIMARY KEY, email VARCHAR(255) [1]);
Drag options to blanks, or click blank then click option'
AUNIQUE
BCHECK
CNOT NULL
DDEFAULT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE instead of NOT NULL
Leaving the column without any constraint
3fill in blank
hard

Fix the error in the constraint syntax to ensure age is always 18 or older.

SQL
CREATE TABLE members (member_id INT PRIMARY KEY, age INT CHECK (age [1] 18));
Drag options to blanks, or click blank then click option'
A>=
B<
C=
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than operator which allows younger ages
Using equality operator which only allows exactly 18
4fill in blank
hard

Fill both blanks to create a foreign key constraint linking orders to customers.

SQL
CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT, CONSTRAINT fk_customer FOREIGN KEY ([1]) REFERENCES [2](id));
Drag options to blanks, or click blank then click option'
Acustomer_id
Borders
Ccustomers
Dorder_id
Attempts:
3 left
💡 Hint
Common Mistakes
Referencing the wrong table
Using the wrong column name for the foreign key
5fill in blank
hard

Fill all three blanks to create a table with a unique constraint and a default value.

SQL
CREATE TABLE products (product_id INT PRIMARY KEY, sku VARCHAR(50) [1], stock INT [2] 0, CONSTRAINT unique_sku [3] (sku));
Drag options to blanks, or click blank then click option'
AUNIQUE
BDEFAULT
DCHECK
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing UNIQUE and CHECK constraints
Forgetting to set a default value for stock