0
0
SQLquery~10 mins

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

SQL
CREATE UNIQUE INDEX [1] ON users(email);
Drag options to blanks, or click blank then click option'
Aunique_email_index
Busers_email_idx
Cidx_email_unique
Demail_idx
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-descriptive index name.
Omitting the UNIQUE keyword (not applicable here but common).
2fill in blank
medium

Complete the code to insert a new user with email 'test@example.com' into the 'users' table.

SQL
INSERT INTO users (name, email) VALUES ('Alice', [1]);
Drag options to blanks, or click blank then click option'
A'test@example.com'
B'alice@example.com'
C'user@example.com'
D'example@test.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different email than specified.
Forgetting to put quotes around the email.
3fill in blank
hard

Fix the error in the query to select all users with unique emails.

SQL
SELECT * FROM users WHERE email [1] (SELECT email FROM users GROUP BY email HAVING COUNT(*) = 1);
Drag options to blanks, or click blank then click option'
AIN
B=
CLIKE
DNOT IN
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which expects a single value.
Using 'LIKE' which is for pattern matching.
4fill in blank
hard

Fill both blanks to create a unique index on 'username' and 'email' columns in the 'accounts' table.

SQL
CREATE UNIQUE INDEX [1] ON accounts([2]);
Drag options to blanks, or click blank then click option'
Aidx_username_email_unique
Busername
Cusername, email
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using only one column instead of both.
Using a non-descriptive index name.
5fill in blank
hard

Fill all three blanks to select emails that appear more than once in the 'subscribers' table.

SQL
SELECT [1], COUNT([2]) FROM subscribers GROUP BY [3] HAVING COUNT(email) > 1;
Drag options to blanks, or click blank then click option'
Aemail
B*
Attempts:
3 left
💡 Hint
Common Mistakes
Counting the email column inside COUNT() instead of '*'.
Grouping by a different column than selected.