如何将Identity属性添加到SQL Server中的现有列 [英] How do I add the identity property to an existing column in SQL Server

查看:330
本文介绍了如何将Identity属性添加到SQL Server中的现有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server(以我为例,2005)中,如何使用T-SQL将identity属性添加到现有表列中?

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

类似的东西:

alter table tblFoo 
    alter column bar identity(1,1)

推荐答案

我不相信您可以这样做.最好的选择是创建一个新的identity列,并使用identity insert命令复制数据(如果您确实想保留旧值).

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).

这是一篇不错的文章,详细描述了该过程: http://www.mssqltips.com/tip.asp?tip=1397

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

这篇关于如何将Identity属性添加到SQL Server中的现有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆