SQL Server add auto increment primary key to existing table

1

ALTER TABLE dbo.YourTable
   ADD ID INT IDENTITY

2

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

 

Or by one line

ALTER TABLE dbo.YourTable
   ADD ID INT IDENTITY
       CONSTRAINT PK_YourTable PRIMARY KEY CLUSTERED

 

See--

https://stackoverflow.com/questions/4862385/sql-server-add-auto-increment-primary-key-to-existing-table

posted on 2021-07-01 15:28  J·Marcus  阅读(51)  评论(0编辑  收藏  举报

导航