close[x]


MySQL

MySQL-Home MySQL-Environment setup MySQL- Workbench MySQL-Basic syntax MySQL-Operator MySQL-Data type MySQL-Comments MySQL-Create DB MySQL-Drop DB MySQL-Select DB MySQL-Create Table MySQL-Drop table MySQL-Truncate MySQL-Primary Key MySQL-Foreign Key MySQL-Null MySQL-Increment MySQL-Having MySQL-Top MySQL-Insert Statement MySQL-Select Statement MySQL-Alter Statement MySQL-Where MySQL-And & Or MySQL-Default values MySQL-Exists MySQL-Order by MySQL-View MySQL-Update Statement MySQL-Delete Statement MySQL-Like MySQL-Sort MySQL-Limit MySQL-Min MySQL-Max MySQL-Group MySQL-In MySQL-Between MySQL-Union MySQL-Count MySQL-Average MySQL-Sum MySQL-Date & Time MySQL-Import MySQL-Export MySQL-Index MySQL-Temporary MySQL-Join MySQL-Full Join MySQL-Inner Join MySQL-Left Join MySQL-Right Join MySQL-Store Procedure MySQL-Injection MySQL-PHP connection



learncodehere.com




MySQL - Indexes

Indexes are special lookup tables that the database search engine can use to speed up data retrieval.

The users cannot see the indexes, they are just used to speed up searches/queries.

An index helps to speed up SELECT queries and WHERE clauses


Syntax : CREATE INDEX


--Creates an index on a table. Duplicate values are allowed:

CREATE INDEX index_name
ON table_name (column1, column2, ...);

--We can also create unique index:
--Creates a unique index on a table. Duplicate values are not allowed:

CREATE UNIQUE INDEX index_name
ON table_name (column1, column2, ...);
                

The SQL statement below creates an index named "idx_SUBJECT" on the "SUBJECT" column in the "Students" table:


Example : CREATE INDEX


CREATE INDEX idx_SUBJECT
ON Students (SUBJECT);      


If you want to create an index on a combination of columns, you can list the column names within the parentheses, separated by commas:


Example : CREATE INDEX


CREATE INDEX idx_INFO
ON Students (SUBJECT,NAME);
 

DROP INDEX Statement

The DROP INDEX statement is used to delete an index in a table.


Syntax : DROP INDEX


 DROP INDEX index_name;