Create Index in MySQL with example
To add indexes to columns in a table, you can use the CREATE INDEX statement in SQL. Indexing helps speed up query performance by allowing the database engine to locate and retrieve data more efficiently.
Here's an example of how you can add indexes to the name column in the users table.
CREATE INDEX idx_users_name on users (name);
In above MySQL query:
idx_users_name is the name of the index for the id column.
users is the name of the table.
(name) indicates the column for which the index is created.
Output
mysql> CREATE INDEX idx_users_name on users (name); Query OK, 0 rows affected (0.62 sec) Records: 0 Duplicates: 0 Warnings: 0
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Sql
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- Get full name of a person in SQL using function
- Get create table Query from existing table in phpMyAdmin
- How to create view in MySQL database
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- How to create a new table from existing table in SQL
- Check constraint in MySQL
- How to check the MySQL version
- How to show database tables in mysql using command line
- SQL query to delete all rows older than 30 days
- Get comma separated ids from table using MySQL
- Database connection using mySQLi with object-oriented
- Change existing MySQL table column id to autoincrement
- How to retrieve data from two tables with one SQL statement
- Insert multiple rows in a single MySQL query
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- Clear the terminal screen in MySQL within the Windows powershell
- How to get yesterday's date in MySQL ?
- How to get a list of MySQL views?
- SQL query to delete records older than 6 months
- Difference between SQL and NoSQL databases
- How to create function in MySQL ?
- How to drop function in MySQL ?
- Get number of connections being used by a specific user in MySQL
- Cannot drop index 'fk_role_id': needed in a foreign key constraint