日期:2014-05-18  浏览次数:20470 次

存储过程中的set identity_insert <table> on的作用?
set   identity_insert   <table>   on的作用?
      请老师解释一下!
      谢谢了!!
    给分的!!

------解决方案--------------------
create table test(id int identity(1,1), value int)
go

insert test(id, value) select 2,3
/*
服务器: 消息 8101,级别 16,状态 1,行 1
仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'test ' 中为标识列指定显式值。
*/
go

set identity_insert test on
go

insert test(id, value) select 2,3
/*
(所影响的行数为 1 行)
*/
set identity_insert test off
go

select * from test
/*
id value
2 2
*/

drop table test