Friday, 15 February 2013

How to Create an Index in SQL Server

SQL Server Index
An index can be created in a table to find data more quickly and efficiently.The users cannot see the indexes, they are just used to speed up searches/queries.
Note: Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So you should only create Indexes on columns(of a table) that will be frequently searched against or use in the Order by Clause.
To Creates an Index on a table which allows Duplicate values :
Syntax :
CREATE INDEX Index_name ON Table_name (Column_name)

To Creates a Unique Index on a table which does not allows Duplicate values :
Syntax:
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 below SQL statement creates an index named "CIndex" on the "LastName" column in the "Customers" table:
CREATE INDEX CIndex ON Customers (LastName)
If you want to create a Composite Index on a combination of columns, you can list the column names within the parentheses, separated by commas.
CREATE INDEX CIndex ON Customers (LastName, FirstName)

No comments:

Post a Comment

Hi User, Thank You for Visiting My Blog. Please Post Your Feedback/Comments/Query.

Subscribe to Blog Posts by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts