Wednesday, 4 May 2016

How to create the CLUSTERED INDEX in SQL server ?

To create the Clustered index in SQL server , we can follow up the two ways.

  • Using T-SQL Query
  • Using SQL Management studio


Using T-SQL Query
Syntax:
CREATE CLUSTERED INDEX [INDEX NAME]
ON [TABLE NAME](COLUMN NAME)

Example:
CREATE CLUSTERED INDEX IX_UID
ON Student (UID)

IX_UID --> Refers the Index name
UID --> Refers the index column name

Now the Index will be created on the UID column of Student table.

Using SQL Management studio

Connect to the SQL instance and select the database.
Expand the database and right click the Indexes folder and select New Index --> Clustered Index as shown below.



After selection the below screen will appear, there you can see the index name (highlighted in Red colour) as shown below.



You can also change the index name to a meaningful one to easily identify the index and then Click the add button to select the index column.

Select the required column to create the index and click OK button.(You can also choose the multiple columns to create the clustered index(also known as Cover indexes)) as shown below.



Then click the OK button in New index pop up window as shown below.


Finally the clustered index will be created in the table as shown below.


You can notice that the index will be mentioned as Clustered in bracket to identify the clustered index.

No comments:

Post a Comment