MSSQL Server 對已經存在的 table 增加識別 id 欄位 (從1開始)
Posted on November 7th, 2014
Sql Server add auto increment primary key to existing table
No - you have to do it the other way around: add it right from the get go as INT IDENTITY
- it will be filled with identity values when you do this:
ALTER TABLE dbo.YourTable
ADD ID INT IDENTITY
and then you can make it the primary key:
ALTER TABLE dbo.YourTable
ADD CONSTRAINT PK_YourTable
PRIMARY KEY(ID)