0
0
SQLquery~10 mins

Database design best practices 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 with a primary key.

SQL
CREATE TABLE users (id INT [1] PRIMARY KEY, name VARCHAR(100));
Drag options to blanks, or click blank then click option'
AAUTO_INCREMENT
BUNIQUE
CNOT NULL
DDEFAULT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE alone does not auto-generate values.
NOT NULL only prevents nulls but does not auto-increment.
2fill in blank
medium

Complete the code to add a foreign key constraint.

SQL
ALTER TABLE orders ADD CONSTRAINT fk_user_id FOREIGN KEY (user_id) [1] users(id);
Drag options to blanks, or click blank then click option'
AJOINS
BLINKS
CCONNECTS
DREFERENCES
Attempts:
3 left
💡 Hint
Common Mistakes
Using LINKS or CONNECTS are not valid SQL keywords.
JOINS are used in queries, not in constraints.
3fill in blank
hard

Fix the error in the table creation by completing the code.

SQL
CREATE TABLE products (product_id INT PRIMARY KEY, price [1] DECIMAL(10, 2));
Drag options to blanks, or click blank then click option'
AUNIQUE
BAUTO_INCREMENT
CNOT NULL
DDEFAULT
Attempts:
3 left
💡 Hint
Common Mistakes
Using UNIQUE on price is not typical.
AUTO_INCREMENT is only for integer keys.
4fill in blank
hard

Fill both blanks to create a normalized table with a unique constraint.

SQL
CREATE TABLE employees (emp_id INT PRIMARY KEY, email VARCHAR(255) [1] [2]);
Drag options to blanks, or click blank then click option'
AUNIQUE
BNOT NULL
CDEFAULT
DAUTO_INCREMENT
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting NOT NULL allows empty emails.
Missing UNIQUE allows duplicate emails.
5fill in blank
hard

Fill all three blanks to create a table with a composite primary key and a foreign key.

SQL
CREATE TABLE enrollment (student_id INT, course_id INT, semester VARCHAR(10), PRIMARY KEY ([1], [2]), FOREIGN KEY (student_id) [3] students(id));
Drag options to blanks, or click blank then click option'
Astudent_id
Bcourse_id
CREFERENCES
Dsemester
Attempts:
3 left
💡 Hint
Common Mistakes
Using semester as part of the primary key is not typical here.
Forgetting REFERENCES causes foreign key errors.