How to add a new identity column to a table in SQL Server?

后端 未结 3 1093
执念已碎
执念已碎 2020-12-31 00:11

I am using SQL Server 2008 Enterprise. I want to add an identity column (as unique clustered index and primary key) to an existing table. Integer based auto-increasing by 1

3条回答
  •  没有蜡笔的小新
    2020-12-31 01:07

    you can use -

    alter table  add ident INT IDENTITY
    

    This adds ident column to your table and adds data starting from 1 and incrementing by 1.

    To add clustered index -

    CREATE CLUSTERED INDEX  on (ident) 
    

提交回复
热议问题