请邹建大哥进来指点下你的帖子里有关identity的问题
zjcxc(邹建)大哥原帖:
要将已有的字段改为identity是不行了,如果你怕数据丢失,就用临时表来解决:
begin tran
--备份你的原来数据
select * into #temp from 你的表
--重建要设置为identity的字段
alter table 你的表 drop id
alter table 你的表 add id int identity(1,1)
--恢复数据
set identity_insert 你的表 on
insert into 你的表select * from #temp
set identity_insert 你的表 off
--删除临时表
drop table #temp
我的代码:
select * into #temp from identable
alter table identable drop column key_col
exec addcolumn 'identable','key_col','int identity',1 ---在key_col原来的位置上插入
delete from identable
set identity_insert identable on
insert into identable select * from #temp
set identity_insert identable off
drop table #temp
错误提示:
Server: Msg 8101, Level 16, State 1, Line 6
An explicit value for the identity column in table 'identable' can only be specified when a column list is used and IDENTITY_INSERT is ON.
为什么会提示说identity_insert没有打开?我是想把原来表identable中key_col字段改成自增字段,且原表中key_col有数据存在.zjcxc(邹建)大哥帮帮忙指点指点,应该怎么修改