Complete the code to create an index on the column 'email' in the 'users' table.
CREATE INDEX [1] ON users(email);The index name is usually descriptive. Here, users_email_idx is a common naming style for indexes.
Complete the query to find users with the last name 'Smith' using the index.
SELECT * FROM users WHERE last_name [1] 'Smith';
The = operator is used to find exact matches, which can use an index efficiently.
Fix the error in the query to use the index on 'email' correctly.
SELECT * FROM users WHERE email [1] '%@example.com';
The LIKE operator with a wildcard is used to find emails ending with '@example.com'. Note: Leading wildcards may prevent full index usage in some databases.
Fill both blanks to create a unique index on the 'username' column in the 'accounts' table.
CREATE [1] INDEX [2] ON accounts(username);
The UNIQUE keyword creates a unique index, preventing duplicate usernames. accounts_username_idx is a descriptive name following common conventions.
Fill all three blanks to write a query that uses the index on 'created_at' to find records after '2023-01-01'.
SELECT [1] FROM orders WHERE created_at [2] '[3]';
The query selects all columns (*) where the date is greater than (>) '2023-01-01'. This range query can efficiently use an index on 'created_at'.