首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

存储过程中的set identity_insert <table> on的作用?解决方法

2012-01-06 
存储过程中的set identity_insert table on的作用?setidentity_inserttableon的作用?请老师解释一下!

存储过程中的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
/*
idvalue
22
*/

drop table test

热点排行