0
0
SQLquery~10 mins

UNIQUE constraint 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 add a UNIQUE constraint on the email column.

SQL
CREATE TABLE users (id INT PRIMARY KEY, email VARCHAR(255) [1]);
Drag options to blanks, or click blank then click option'
AUNIQUE
BPRIMARY KEY
CNOT NULL
DCHECK
Attempts:
3 left
💡 Hint
Common Mistakes
Using PRIMARY KEY instead of UNIQUE for email column.
Forgetting to add any constraint, allowing duplicates.
2fill in blank
easy

Complete the code to add a UNIQUE constraint on the code column.

SQL
CREATE TABLE products (id INT PRIMARY KEY, code VARCHAR(50) [1]);
Drag options to blanks, or click blank then click option'
ACHECK
BUNIQUE
CPRIMARY KEY
DNOT NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using PRIMARY KEY instead of UNIQUE for code column.
Forgetting to add any constraint, allowing duplicates.
3fill in blank
medium

Complete the code to add a UNIQUE constraint to the username column after table creation.

SQL
ALTER TABLE users ADD CONSTRAINT [1] UNIQUE (username);
Drag options to blanks, or click blank then click option'
Aunique_username
Bcheck_username
Cpk_username
Dfk_username
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pk_' prefix which is for primary keys.
Using 'fk_' which is for foreign keys.
4fill in blank
hard

Fill both blanks to create a UNIQUE constraint on two columns: first_name and last_name.

SQL
ALTER TABLE employees ADD CONSTRAINT [1] [2] (first_name, last_name);
Drag options to blanks, or click blank then click option'
Aunique_fullname
BPRIMARY KEY
CUNIQUE
DCHECK
Attempts:
3 left
💡 Hint
Common Mistakes
Using PRIMARY KEY instead of UNIQUE for multiple columns.
Not naming the constraint.
5fill in blank
hard

Fill all three blanks to create a table with a UNIQUE constraint on the email column and a PRIMARY KEY on id.

SQL
CREATE TABLE customers ([1] INT [2], email VARCHAR(255) [3]);
Drag options to blanks, or click blank then click option'
Aid
BPRIMARY KEY
CUNIQUE
DNOT NULL
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to add PRIMARY KEY to id.
Not adding UNIQUE to email.