日期:2014-05-19  浏览次数:20560 次

由于对id用了标识自增,操作sqlserver中的数据后,id都会变,能不能让它不变?
由于对id用了标识自增,操作sqlserver中的数据后,id都会变。为了加入数据时方便,所以用了自增,但是我不想每次修改一条数据,该数据的id就会变一次。有方法解决吗?   还是不能用自增这一属性?

------解决方案--------------------
drop table tbtest
go
create table tbtest(id int identity(1,1),name varchar(20))
insert into tbtest
select '11 '
union select '22 '
union select '33 '

update tbtest
set id=3
where id=1
/*
服务器: 消息 8102,级别 16,状态 1,行 1
无法更新标识列 'id '。
*/

楼主可以用事件探查器跟踪一下,看下发出的是什么语句