0

when i create primary key on a column 'FirstName', is a clustered index automatically created for this column?

2 Answers 2

1

Yes - this is default SQL Server behavior.

It doesn't have to be that way - if you create your PK using T-SQL script, you can also choose to make it a non-clustered PK and put the clustering key on another column.

ALTER TABLE dbo.YourTable
    ADD CONSTRAINT PK_YourTable
    PRIMARY KEY NONCLUSTERED(FirstName)

CREATE CLUSTERED INDEX CIX_YourTable
    ON dbo.YourTable(SomeOtherColumn)

In this case, FirstName would be the (non-clustered) primary key on your table, while SomeOtherColumn would be the clustering key for that same table.

Sign up to request clarification or add additional context in comments.

Comments

1

Depends on what you specify when you create the key. Indexes are automatically created for key constraints by SQL Server but as part of the constraint syntax you can specify either CLUSTERED or NONCLUSTERED.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.