How To Create Non Clustered Primary Key in SQL Server

How To Create Non Clustered Primary Key in SQL Server

In this tutorial i am going to explain about How To Create Non Clustered Primary Key in SQL Server. In my previous tutorial i have explained about

Implementation :

Now we will see the implementation of How To Create Non Clustered Primary Key in SQL Server. Whenever we create the primary key in any column by default clustered index will be created. Lets see it with an example. Below for demo purpose i am creating sample table with primary key column.

Now if you run the sp_help procedure on Employee table you can see clustered index is created on EmployeeId column by default since we created primary key.

How To Create Non Clustered Primary Key in SQL Server



Then how to create primary key with the non clustered index. It is simple. A table can have only one clustered index defined on it. So before creating primary key ,create the clustered index on any other column and then create primary key.  Since clustered index is already created, it will create the non clustered primary key.  Otherwise we can mention what type of index need to be created  while creating primary key. Refer the below script.

Conclusion:

Hope you learned How To Create Non Clustered Primary Key in SQL Server. Do you like this tutorial? Help us to improve. Please post your comments and feedback below.

Leave a Reply

Your email address will not be published. Required fields are marked *