question

minijebu avatar image
minijebu asked

Clustered index by default

In the below T-sql code, CREATE TABLE PERSON ( PERSON_ID INT NOT NULL PRIMARY KEY CLUSTERED, FIRST_NAME VARCHAR(255) NOT NULL, LAST_NAME VARCHAR(255) NOT NULL); Go If i dont specify the word CLUSTERED,wont sql engine still create a clustered index on PERSON_ID since Primary key is defined on it ?
clustered-index
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JohnM avatar image
JohnM answered
That is correct. As per the documentation, https://msdn.microsoft.com/en-us/library/ms174979.aspx, a primary key contraint will default to clustered and a unique constraint will default to non-clustered. Hope that helps!
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

100% agreement. I'd just add that it's important to know that you have the choice. The primary key isn't always the best choice for the clustered index.
2 Likes 2 ·
Thanks JohnM and Thank you Grant Fritchey.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.