Introduction
Indexes help the database find data faster, like a shortcut in a book's table of contents.
CREATE INDEX index_name ON table_name (column_name); -- For unique values: CREATE UNIQUE INDEX index_name ON table_name (column_name);
CREATE INDEX idx_lastname ON employees (last_name);
CREATE UNIQUE INDEX idx_email ON users (email);
CREATE INDEX idx_name_dob ON persons (last_name, date_of_birth);
CREATE TABLE books ( id INT PRIMARY KEY, title VARCHAR(100), author VARCHAR(50), published_year INT ); CREATE INDEX idx_author ON books (author); -- Query to test the index EXPLAIN SELECT * FROM books WHERE author = 'Jane Austen';
email in a table named users?products with columns id, name, and category, what will be the effect of this query?CREATE UNIQUE INDEX idx_name ON products (name);
CREATE INDEX idx_age ON employees age;
age, causing syntax error.orders table with columns order_id, customer_id, and order_date. You often query orders by customer_id and order_date. Which index creation will best improve query speed without allowing duplicate entries for the same customer on the same date?customer_id and order_date, so a composite index on both is best.Pass the test and this pattern moves unknown