请教一个修改已插入表中的identity值的记录的方法

iamme81 2009-02-20 02:34:56
现有表a结构
create table a(a int identity(1,1),b int)
insert a values(1)
insert a values(1)
.
.
.

表中的记录为
a b
1 1
2 1
现要将a为2的记录修改为a等于2000,而a为identity属性的字段,一般情况下不允许修改,请问在不变动表结构的情况下有没有办法暂时去掉限制使可以修改此值。
...全文
51 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jia_guijun 2009-02-20
  • 打赏
  • 举报
回复
先装自增标识关闭,然后复制一条记录,再删除原来记录,开启自增标识
begin tran
set identity_insert t on
insert t(a,b) select 2000,b from t where a=2
delete t where a=2
set identity_insert t off
commit
jia_guijun 2009-02-20
  • 打赏
  • 举报
回复
begin tran
set identity_insert a on
insert a(aid,aname) select 2000,aname from a where aid=2
delete a where aid=2
set identity_insert a off
commit
jia_guijun 2009-02-20
  • 打赏
  • 举报
回复
begin tran
set identity_insert t on
insert t(a,b) select 2000,b from t where a=2
delete t where a=2
set identity_insert t off
commit
水族杰纶 2009-02-20
  • 打赏
  • 举报
回复
--你可以增加一列
alter table a
add id int
go
update a set id=a*1
go

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧