CREATE INDEX IN SQL


Indexes allow the database application to find data fast without reading the entire table.

The CREATE INDEX statement is used to create indexes in tables

Indexes

An index can be created in a table to find data more rapidly and efficiently.users cannot see the indexes, they are just used to speed up searches/queries.

SQL CREATE INDEX Syntax

Creates an index on a table. Duplicate values are allowed:
CREATE INDEX index_name ON table_name (column_name)

SQL CREATE UNIQUE INDEX Syntax

Creates a unique index on a table. Duplicate values are not allowed:
CREATE UNIQUE INDEX index_name ON table_name (column_name)

CREATE INDEX Example

The SQL statement below creates an index named "EmpIndex " on the "Emp_id" column in the "EmpMaster" table:

CREATE INDEX EmpIndex ON EmpMaster (Emp_id)

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

CREATE INDEX EmpIndex ON EmpMaster(Emp_id, Emp_Name)

For More details on SQL INDEX please check



Why we can't execute a stored procedure from a User Defined function(UDF)

Functions cannot "touch" any database but read them only. Stored procedures can do anything and everything with databases. You ...