日期:2014-05-17 浏览次数:20611 次
create table tbl_1(OrderID int identity(1,1),[User] nvarchar(30));
create table tbl_2(ID int identity(1,1),ProductID int ,OrderID int);
alter table tbl_1 add constraint pk_tbl_1 primary key clustered(
OrderID
)
go
alter table tbl_2 add constraint pk_tbl_2 primary key clustered(
ID
)
go
alter table tbl_2 add constraint fk_tbl_2_1 foreign key (OrderID)
references tbl_1(OrderID)
go
create procedure spCSDN
as
begin
declare @OrderID int
begin tran
insert into tbl_1([user])
select 'csdn'
set @OrderID=@@IDENTITY
insert into tbl_2(ProductID,OrderID)
select 1,@OrderID union
select 2,@OrderID
commit tran
end;
go
exec spCSDN
go
select * from tbl_1
select * from tbl_2