0
0
SQLquery~10 mins

One-to-many relationship design in SQL - Interactive Code Practice

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

Complete the code to create a table named 'orders' with a primary key column 'order_id'.

SQL
CREATE TABLE orders (order_id [1]);
Drag options to blanks, or click blank then click option'
AINT PRIMARY KEY
BVARCHAR(255)
CFLOAT
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using VARCHAR instead of INT for the primary key.
Not specifying PRIMARY KEY.
2fill in blank
medium

Complete the code to add a foreign key column 'customer_id' to the 'orders' table.

SQL
ALTER TABLE orders ADD COLUMN customer_id [1];
Drag options to blanks, or click blank then click option'
AINT
BDATE
CTEXT
DBOOLEAN
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different data type than the referenced primary key.
Using a non-numeric type for IDs.
3fill in blank
hard

Fix the error in the foreign key constraint syntax to link 'customer_id' in 'orders' to 'id' in 'customers'.

SQL
ALTER TABLE orders ADD CONSTRAINT fk_customer FOREIGN KEY (customer_id) REFERENCES customers([1]);
Drag options to blanks, or click blank then click option'
Acustomer_id
Border_id
Cid
Dorder_date
Attempts:
3 left
💡 Hint
Common Mistakes
Referencing a non-primary key column.
Using the foreign key column name instead of the referenced column.
4fill in blank
hard

Fill both blanks to create a 'customers' table with a primary key 'id' and a 'name' column.

SQL
CREATE TABLE customers (id [1], name [2]);
Drag options to blanks, or click blank then click option'
AINT PRIMARY KEY
BVARCHAR(100)
CTEXT
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using DATE for the name column.
Not setting the primary key on 'id'.
5fill in blank
hard

Fill all three blanks to insert a new order with order_id 101, customer_id 5, and order_date '2024-06-01'.

SQL
INSERT INTO orders (order_id, customer_id, order_date) VALUES ([1], [2], '[3]');
Drag options to blanks, or click blank then click option'
A100
B5
C2024-06-01
D101
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping order_id and customer_id values.
Not quoting the date string.