日期:2014-05-17 浏览次数:20735 次
/*
drop table a
drop table b
go
*/
create table A(ID int identity(1,1) primary key,Avalue varchar(10))
create table B(ID int identity(1,1) primary key,AID int,Bvalue varchar(10))
go
/*
drop view AB_view
go
*/
create view AB_view
as
select A.*, B.Bvalue from A join B on (A.ID = B.AID)
go
--drop trigger AB_tr on AB_view
create trigger AB_tr on AB_view instead of insert
as
begin
insert into a(Avalue)
select Avalue
from
(
select distinct id,Avalue
from inserted i
)t
insert into b(aid,Bvalue)
select scope_identity(),Bvalue
from inserted i
end
go
insert into AB_view (Avalue, Bvalue) values ('A3', 'B3')
select * from a
/*
ID Avalue
1 A3
*/
select * from b
/*
ID AID Bvalue
1 1 B3
*/
create table A(ID int identity(1,1),Avalue varchar(15))
create table B(ID int identity(1,1),AID int,Bvalue varchar(15))
create view AB_view
as
select A.*,B.Bvalue from A join B on A.ID=B.AID
create trigger AB_tr on AB_view
instead of insert
as
begin
declare @ta table(ID int)
insert into A(Avalue)
output inserted.ID into @ta
select Avalue from inserted
insert into B(AID,Bvalue)
select (select ID f