现在的位置: 首页 > 综合 > 正文

如何用sql语句去掉列的自增长(identity)

2013年10月06日 ⁄ 综合 ⁄ 共 504字 ⁄ 字号 评论关闭

 

如何用sql语句去掉列的自增长(identity)

**无法通过alter把现有自增字段改为非自增
比如alter   table   a   alter   id   int,自增属性不会去掉
通过修改系统表可以做到(此法可能有不可预知的结果,慎之...)
sp_configure   'allow   updates ',   1
GO
reconfigure   with   override
GO
update   syscolumns   set   colstat   =   colstat   &   0x0000  
where     id=object_id( '表名 ')   and   name= '字段名 '
GO
sp_configure   'allow   updates ',   0

---------------------------------------------
--折中的办法
alter   table   a   add   xxx   int
update   a   set   xxx=id
alter   table   a   drop   column   id
exec   sp_rename   'xxx ',   'id ',   'column '
---------------------------------------------

抱歉!评论已关闭.