下面是个例子,你可以参考一下,其中ID是主键
set nocount on
create table tt(id int,x int,y int)
insert tt select 1,1,1go
create view v_tt
as
select id,x,y=null from tt
go
create trigger t_v_tt on v_tt
INSTEAD OF insert,delete,update
as delete tt where id in(select id from deleted)
insert tt select * from insertedgo
select id,x,y from v_tt
Update v_tt set x = 2,y = 3
select id,x,y from v_tt
insert v_tt select 4,5,6
select id,x,y from v_tt
delete v_tt where id = 1
select id,x,y from v_tt
go
drop table tt
drop view v_tt
/*
id x y
----------- ----------- -----------
1 1 NULLid x y
----------- ----------- -----------
1 2 NULLid x y
----------- ----------- -----------
1 2 NULL
4 5 NULLid x y
----------- ----------- -----------
4 5 NULL
*/
set nocount on
create table tt(id int,x int,y int)
insert tt select 1,1,1go
create view v_tt
as
select id,x,y=null from tt
go
create trigger t_v_tt on v_tt
INSTEAD OF insert,delete,update
as delete tt where id in(select id from deleted)
insert tt select * from insertedgo
select id,x,y from v_tt
Update v_tt set x = 2,y = 3
select id,x,y from v_tt
insert v_tt select 4,5,6
select id,x,y from v_tt
delete v_tt where id = 1
select id,x,y from v_tt
go
drop table tt
drop view v_tt
/*
id x y
----------- ----------- -----------
1 1 NULLid x y
----------- ----------- -----------
1 2 NULLid x y
----------- ----------- -----------
1 2 NULL
4 5 NULLid x y
----------- ----------- -----------
4 5 NULL
*/
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货