create table ta (id int identity(1,1),col int) go create table tb (id int identity(1,1),col int) go insert into ta(col) select 1 insert into ta(col) select 1 go create proc sp_insert @d int asbegin traninsert into ta(col) select @d insert into tb(col) select @@identity if @d > 8 rollback else commit tran go exec sp_insert 6 select * from ta select * from tb /*id col ----------- ----------- 1 1 2 1 3 6(所影响的行数为 3 行)id col ----------- ----------- 1 3(所影响的行数为 1 行)*/ exec sp_insert 9select * from ta select * from tb/* (所影响的行数为 1 行)id col ----------- ----------- 1 1 2 1 3 6(所影响的行数为 3 行)id col ----------- ----------- 1 3(所影响的行数为 1 行)*/ drop table ta,tb drop proc sp_insert
[Quote=引用 6 楼 happyflystone 的回复:] SQL codecreate table ta (id int identity(1,1),col int) go create table tb (id int identity(1,1),col int) go insert into ta(col) select 1 insert into ta(col) select 1 go create proc sp_insert @d int asbegin traninsert into ta(col) select @d insert into tb(col) select @@identity if @d > 8 rollback else commit tran go exec sp_insert 6 select * from ta select * f… [/Quo 这我是明白的,但我浪沸了一个增量的值,ID已经是不连续的
go
create table tb (id int identity(1,1),col int)
go
insert into ta(col) select 1
insert into ta(col) select 1
go
create proc sp_insert
@d int
asbegin traninsert into ta(col) select @d
insert into tb(col) select @@identity
if @d > 8
rollback
else
commit tran
go
exec sp_insert 6
select * from ta
select * from tb
/*id col
----------- -----------
1 1
2 1
3 6(所影响的行数为 3 行)id col
----------- -----------
1 3(所影响的行数为 1 行)*/
exec sp_insert 9select * from ta
select * from tb/*
(所影响的行数为 1 行)id col
----------- -----------
1 1
2 1
3 6(所影响的行数为 3 行)id col
----------- -----------
1 3(所影响的行数为 1 行)*/
drop table ta,tb
drop proc sp_insert
SQL codecreate table ta (id int identity(1,1),col int)
go
create table tb (id int identity(1,1),col int)
go
insert into ta(col) select 1
insert into ta(col) select 1
go
create proc sp_insert
@d int
asbegin traninsert into ta(col) select @d
insert into tb(col) select @@identity
if @d > 8
rollback
else
commit tran
go
exec sp_insert 6
select * from ta
select * f…
[/Quo
这我是明白的,但我浪沸了一个增量的值,ID已经是不连续的