In SQL Server, should I create an index for an identity column, or is it created automatically?

后端 未结 3 882
Happy的楠姐
Happy的楠姐 2020-12-10 11:03

I believe when I create an identity column it gets indexed automatically, but I\'m not 100% sure.

Should I create an index for an identity

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 11:49

    If you create a column with a PRIMARY KEY constraint, a clustered index will be created by default (assuming this is a new table and no such index is already defined).

    Being an IDENTITY field has nothing to do with it.

    So, to answer you question - if you are going to query/sort with this field and it is not a primary key, you should define an index on it (rule of thumb, always test for your scenario).

提交回复
热议问题