Search This Blog

Non Clustered Index on Primary Key in SQL

Non Clustered Index on Primary Key in SQL

I believe all developer are aware of this fact that by Default Primary key creates Clustered index on the Column and there is only one clustered index per table.

But sometimes you want to have a NONclustered index in your Primary key column .

Below is the Script
.
--while creating table you can define it

create table test
(IDNum int identity (1,1) PRIMARY KEY NONCLUSTERED ,
 EmployeeName varchar(50)
 ) 

--Or you can alter the table to add Primary Key with NonClustered Index.

alter table Test
add  CONSTRAINT [PK_EmployeeName] PRIMARY KEY NONCLUSTERED 
(
[IdNum] ASC
) ON [PRIMARY]






No comments:

Post a Comment