MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL INDEX Constraint

In MySQL, INDEX constraint are used to speed up data retrieval from database table. To create INDEX in MySQL, CREATE INDEX statement is used to create indexes in tables. MySQL allows to create multiple-column INDEX.

MySQL INDEX Syntax

To create indexes in tables using CREATE INDEX statement, use the following syntax:

Syntax

CREATE INDEX indexname
ON tablename (col1);

Parameters:

indexname: Name of the INDEX, you want to create.

tablename: The table name from which you want to fetch records.

col1: The column name on which you want to create index.

MySQL INDEX Constraint example

The following MySQL, creates a INDEX on "custId" column for "tblCustomer" table:

Example

CREATE INDEX idex_custId
ON tblCustomer (custId);

MySQL UNIQUE INDEX Syntax

To create unique index in table using CREATE UNIQUE INDEX statement, use the following syntax:

Syntax

CREATE UNIQUE INDEX indexname
ON tablename (col1);

MySQL UNIQUE INDEX Constraint example

The following MySQL, creates a UNIQUE INDEX on "custId" column for "tblCustomer" table:

Example

CREATE UNIQUE INDEX idex_custId
ON tblCustomer (custId);

MySQL DROP a INDEX Constraint example

The following MySQL, dropping INDEX constraint "idex_custId" from "tblCustomer" table:

Example

ALTER TABLE tblCustomer
DROP INDEX idex_custId;