34,590
社区成员
发帖
与我相关
我的任务
分享
--插入前
SET IDENTITY_INSERT TB ON
--插入后
SET IDENTITY_INSERT TB OFF
# --(2)当设置identity_insert选项值为 ON的时候,可以插入id.
# create table #te
# (
# id int identity(1,1),
# col1 varchar(10)
# )
# insert into #te values ('aa')
# insert into #te values ('bb')
# select * from #te
# set identity_insert #te on
# insert into #te(id,col1) values (10,'ff')
#
# set identity_insert #te off
# insert into #te values ('hh')
# --(3)当使用identity_insert插入一个最小的id,之后在在插入新的值,不会以那个小的值进行递增的
# create table #TF
# (
# id int identity(1,1),
# col1 int
# )
# insert into #TF select 1
# union all select 2
# union all select 3
#
# set identity_insert #TF on
# insert into #TF (id,col1) select 1,10
# set identity_insert #TF off
# insert into #TF select 4
# select * from #TF
SET IDENTITY_INSERT TB ON
SET IDENTITY_INSERT TB OFF