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
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.
CREATE TABLE Employee
EmployeeID INT NOT NULL PRIMARY KEY,
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.
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.
EmployeeID INT NOT NULL PRIMARY KEY NONCLUSTERED,
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.