insert into 表a(a,b,c)values('a','b','c') insert into 表b(a,b,c)values('a','b','c')
谢谢我的意思是如何将这两个insert语句联合起来
操作两个表,一般用到transaction create sp_InsertInTwoTable @p1 int, @p2 int as begin transaction if(@@error=0) begin insert into table_1 (c1) values (@p1) end if(@@error=0) begin insert into table_2 (c2) values (@p2) endif(@@error>0) begin rollback end else begin commit end return end
insert into 表b(a,b,c)values('a','b','c')
create sp_InsertInTwoTable
@p1 int,
@p2 int
as
begin transaction
if(@@error=0)
begin
insert into table_1 (c1) values (@p1)
end
if(@@error=0)
begin
insert into table_2 (c2) values (@p2)
endif(@@error>0)
begin
rollback
end
else
begin
commit
end
return
end