首页 > 其他 > 详细

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

时间:2016-04-10 10:15:56      阅读:208      评论:0      收藏:0      [点我收藏+]

 

应用场景:权限不够(只是某个用户,权限很低,不能使用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 ‘ 
---------------------------------------------

 

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

原文:http://www.cnblogs.com/dunitian/p/5373361.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!