patternsqlMinor
Why is Clustered Index on Primary Key compulsory?
Viewed 0 times
clusteredwhyprimarycompulsoryindexkey
Problem
Why Primary Key constraint creates Clustered Index on the PK column by default?
Can we create a table which has a primary key, but NO clustered index. I need PK constraint to maintain the unique values + not null on the column, but i do not want a clustered index as
there are too inserts in this table.
I have read that having clustered index has performance impacts on inserts.
Can we create a table which has a primary key, but NO clustered index. I need PK constraint to maintain the unique values + not null on the column, but i do not want a clustered index as
there are too inserts in this table.
I have read that having clustered index has performance impacts on inserts.
Solution
Why Primary Key constraint creates Clustered Index on the PK column by default?
That is what MS-SQL-Server programmers decided the default to be. A good clustered index is one that has unique values (as the Primary Key), is narrow (as most primary keys are or at least should be) and is ever-increasing. So, most of the times, the primary key is a good (or the best) choice for the clustered key (there can be at most one clustered key per table).
Can we create a table which has a primary key, but NO clustered index?
Yes, you can. By explicitely defining all indices and especially the primary key as non-clustered. If you think that you don't need a clustered key on a table, you can do that and have the primary key as non-clustered. The unique and not null constraints will still be enforced.
That is what MS-SQL-Server programmers decided the default to be. A good clustered index is one that has unique values (as the Primary Key), is narrow (as most primary keys are or at least should be) and is ever-increasing. So, most of the times, the primary key is a good (or the best) choice for the clustered key (there can be at most one clustered key per table).
Can we create a table which has a primary key, but NO clustered index?
Yes, you can. By explicitely defining all indices and especially the primary key as non-clustered. If you think that you don't need a clustered key on a table, you can do that and have the primary key as non-clustered. The unique and not null constraints will still be enforced.
Context
StackExchange Database Administrators Q#22916, answer score: 7
Revisions (0)
No revisions yet.