0
0
MySQLquery~10 mins

Unique indexes in MySQL - 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 unique index on the column 'email' in the 'users' table.

MySQL
CREATE UNIQUE INDEX [1] ON users(email);
Drag options to blanks, or click blank then click option'
Aidx_users_email
Bidx_email_unique
Cemail_index
Dunique_email
Attempts:
3 left
💡 Hint
Common Mistakes
Using a name that is already used by another index.
Forgetting to specify UNIQUE keyword (though here it's part of the statement).
2fill in blank
medium

Complete the code to add a unique constraint on the 'username' column in the 'accounts' table.

MySQL
ALTER TABLE accounts ADD CONSTRAINT [1] UNIQUE (username);
Drag options to blanks, or click blank then click option'
Ausername_unique
Busername_key
Cunique_username
Dunique_key
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like 'unique_key' which is not descriptive.
Using a name that conflicts with existing constraints.
3fill in blank
hard

Fix the error in the code to create a unique index on 'phone_number' in the 'contacts' table.

MySQL
CREATE [1] INDEX idx_phone ON contacts(phone_number);
Drag options to blanks, or click blank then click option'
AFULLTEXT
BPRIMARY
CFOREIGN
DUNIQUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using PRIMARY or FOREIGN which are for different constraints.
Omitting the UNIQUE keyword.
4fill in blank
hard

Fill both blanks to create a unique index named 'idx_unique_code' on the 'code' column of the 'products' table.

MySQL
CREATE [1] INDEX [2] ON products(code);
Drag options to blanks, or click blank then click option'
AUNIQUE
Bidx_code
Cidx_unique_code
DPRIMARY
Attempts:
3 left
💡 Hint
Common Mistakes
Using PRIMARY instead of UNIQUE.
Using a different index name than requested.
5fill in blank
hard

Fill all three blanks to add a unique constraint named 'uc_email' on the 'email' column of the 'subscribers' table.

MySQL
ALTER TABLE [1] ADD CONSTRAINT [2] [3] (email);
Drag options to blanks, or click blank then click option'
Asubscribers
Buc_email
CUNIQUE
Dusers
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong table name.
Using a generic constraint name.
Omitting the UNIQUE keyword.