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

后端 未结 3 1081
执念已碎
执念已碎 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条回答
  •  旧时难觅i
    2020-12-31 00:57

    Not always you have permissions for DBCC commands.

    Solution #2:

    create table #tempTable1 (Column1 int)
    declare @new_seed varchar(20) = CAST((select max(ID) from SomeOtherTable) as varchar(20))
    exec (N'alter table #tempTable1 add ID int IDENTITY('+@new_seed+', 1)')
    

提交回复
热议问题