How to Create Clustered Index in SQL

In this article I am going to explain how to create clustered index in SQL.
  • 2245

Introduction

Index in SQL is used to quickly access the data from table or view. Indexes are created on table or view. Database have large amount of data like thousands of tables and view. When we try to access this data it takes more time.

SQL provide a way known as index through we can access a specific data quickly. CREATE INDEX statement is used to create a index.

Type of index in SQL

  • Clustered index
  • Non clustered index
  • Unique index
  • Columnstore index

What is Clustered Index

A clustered index in SQL sorts and stores the data rows of the view or table in order based on the clustered index key. In clustered index, physical and logical address are same. CREATE CLUSTERED INDEX statement is used to create clustered index.

Statement that create cluster index

USE vipendra

GO

-- Create a new table with three columns.

CREATE TABLE dbo.studentinfo

    (s_id int NOT NULL,

     s_name nchar(10) NULL,

     s_address nvarchar(50) NULL);

GO

-- Create a clustered index called student_index

-- on the dbo.TestTable table using the TestCol1 column.

CREATE CLUSTERED INDEX student_index

    ON dbo.studentinfo (s_id);

GO


© 2019 DotNetHeaven. All rights reserved.