在不动用sp_configure的情况下,如何 =》去掉列的自增长,并保留原数据

时间:2022-05-07
本文章向大家介绍在不动用sp_configure的情况下,如何 =》去掉列的自增长,并保留原数据,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

应用场景:权限不够(只是某个用户,权限很低,不能使用sp_configure

执行

附录:

update BackupShopMenu set TempId=MId
alter table BackupShopMenu drop column MId
exec sp_rename 'BackupShopMenu.TempId', 'MId', 'column'
alter table BackupShopMenu alter column MId int not null --如果你的字段是可以为null就不需要这段了

网上参考: 如何用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 ' 
---------------------------------------------