Complete the code to create an index on the 'email' column of the 'users' table.
CREATE INDEX [1] ON users(email);The index name should be unique and descriptive. 'users_email_idx' is a common naming convention.
Complete the code to select rows where 'last_name' is 'Smith' using the index.
SELECT * FROM employees 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 'created_at' for filtering recent records.
SELECT * FROM orders WHERE created_at [1] '2023-01-01';
Using '>=' selects records created on or after the date, which can use the index efficiently.
Fill both blanks to create a composite index on 'category' and 'price' columns.
CREATE INDEX [1] ON products([2], price);
The index name 'idx_category_price' clearly describes the columns. The first column in the index is 'category'.
Fill all three blanks to write a query that uses an index to find products priced above 100 in category 'Electronics'.
SELECT * FROM products WHERE [1] = 'Electronics' AND [2] [3] 100;
The query filters by category 'Electronics' and price greater than 100, which can use an index on (category, price).