Advertisement
Google Ad Slot: content-top
MySQL CREATE INDEX
MySQL CREATE INDEX
In MySQL, an index is used to improve the performance of database queries by allowing faster data retrieval. It creates a structure that helps locate data efficiently without scanning the entire table.
Why Use Indexes?
- Speeds up SELECT queries.
- Enhances performance for JOIN operations.
- Efficient for WHERE, ORDER BY, and GROUP BY operations.
- Indexes are automatically used by the MySQL optimizer.
CREATE INDEX Syntax
Creates an index on a table. Duplicate values are allowed:
CREATE INDEX index_name ON table_name (column1, column2);
MySQL CREATE INDEX Example
The SQL statement below creates an index named "idx_student_name" on the "name" column in the "students" table:
If you want to create an index on a combination of columns, you can list the column names within the parentheses, separated by commas:
DROP INDEX Statement
The DROP INDEX statement is used to delete an index in a table.