Friday, 14 June 2013

What is index in sql

The CREATE INDEX statement is used to create indexes in tables.
Indexes  are used in the database application to find data fast; .

 Indexes

We Create index in a table to find data more quickly 

 indexes are not visible to the user, they are just used to speed up searches/queries.
Note: The  disadvantage of the index is , it takes more time at the  in  Updating a table with indexes  updating a table without (because the indexes also need an update). So you should only create indexes on columns (and tables) that will be frequently searched against.

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)
Note: The syntax for creating indexes varies amongst different databases. Therefore: Check the syntax for creating indexes in your database.

CREATE INDEX Example

The SQL statement below creates an index named "PIndex" on the "LastName" column in the "Persons" table:
CREATE INDEX PIndex
ON Persons (LastName)
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 PIndex
ON Persons (LastName, FirstName)

0 comments:

Post a Comment