How do I add the identity property to an existing column in SQL Server

后端 未结 6 1252
夕颜
夕颜 2020-12-09 02:22

In SQL Server (in my case, 2005) how can I add the identity property to an existing table column using T-SQL?

Something like:

alter table tblFoo 
            


        
6条回答
  •  忘掉有多难
    2020-12-09 02:39

    I don't beleive you can do that. Your best bet is to create a new identity column and copy the data over using an identity insert command (if you indeed want to keep the old values).

    Here is a decent article describing the process in detail: http://www.mssqltips.com/tip.asp?tip=1397

提交回复
热议问题