SQL clustered index and non-clustered index

What is Clustered index in SQL?

SQL clustered index helps sorting and storing data in the table or view based on their key values, in each sql table we can have only one clustered index.

clustered index is a data structure that improves speed of data retrieval, primary key is an example of clustered index.

When we create a primary key on sql table, clustered index is automatically created, clustered index can also be created on a view.

sql clustered index

Is primary key and clustered index is the same?

When we create primary key on any column or columns, one clustered index is created automatically for that column, which helps searching and sorting data faster.

However, conceptually they are not same, also two are different objects in sql database.

Primary is unique and not null, the field is to make sure that every row in that table is unique, and can be retrieved by using the primary key unique value. and clustered index is for sorting and retrieving data faster.

Can we create index other than creating a primary key ?

Yes, we can create sql clustered and non-clustered index manually, but, one table can have only one clustered index

create sql index

To create index, open your object explorer in SQL server management studio, expand node under table, right click on Indexes, and then create the type of index on any column of that table.

As you can see in above picture, while creating primary key on client table (column clientId), one clustered index is automatically created, however, we can create index other than creating primary key, see in above picture we have created a non-clustered index on a different column of same table.

Learn more about how you can create Index in SQL Server.

You may be interested in following posts.

 
Hire SQL Developer
SQL Clustered and non-clustered index
SQL Training: For any group or corporate training, please contact us at webtrainingroom(at)gmail.
SQL job Interview Questions Answers
Course in Demand
SQL database development tutorials for learning sql query, data manipulation language, working with MS SQL Server.
Clustered and non-clustered index
MS SQL Examples | Join MS SQL Course