3. SQL-Indexes
“Indexes are used to retrieve data from the
database more quickly than otherwise. The
users cannot see the indexes, they are just
used to speed up searches/queries.”
4. Create Indexes In MySql
The CREATE INDEX statement is used
to create indexes in tables.
Syntax
CREATE INDEX index_name ON table_name (column1, column2, ...);
Example
CREATE INDEX empsalary ON employee(ID, salary);
5. Create Indexes
creating table time
CREATE INDEX index_name
ON table_name (column1, column2, ...);
Example
CREATE INDEX index_name
ON table_name (column1, column2, ...);
Syntax
6. Show Indexes from Database
You can specify the database name if you are not
connected to any database or you want to get the
index information of a table in a different
database:
SHOW INDEXES FROM table_name
IN database_name;
SHOW INDEXES FROM Employee IN Mount;
Example
Syntax
7. Drop Indexes In MySql
The DROP INDEX statement is used to
delete an index in a table.
Syntax
DROP INDEX index_name
ON table_name;
Example
DROP INDEX index_name
ON table_name;
8. Rename the Index Name
We can also rename an index using command .
Alter table tableName
Rename Index Index_Name To New Index_Name;
Example
Syntax
Alter table tableName
Rename Index Index_Name To New Index_Name;
9. Show Indexes
SHOW INDEX returns table index information.
SHOW INDEX FROM TableName;
SHOW INDEX FROM mytable;
Example
Syntax
10. Show Indexes from Database
The following query is similar to the one above
SHOW INDEXES FROM database_name . table_name;
SHOW INDEXES FROM Mount . Employee;
Example
Syntax
11. Advantages of indexes
1. Speed up SELECT query
2. Helps to make a row unique or without duplicates(Primary ,
Unique)
3. If index is set to fill-text index, then we can search against
large string values. for example to find a word from a
sentence etc.
12. Disadvantages of indexes
1.Indexes take additional disk space.
2.indexes slow down INSERT,UPDATE and DELETE,
but will speed up UPDATE if the WHERE condition
has an indexed field. INSERT, UPDATE and
DELETE becomes slower because on each operation
the indexes must also be updated.