create table vwicbill_26(id int,fauxqty int) create table vwicbill_25(id int,fauxqty int) insert into vwicbill_25 values(1 , 10) insert into vwicbill_25 values(2 , 20) go create trigger my_trig on vwicbill_26 for insert as begin declare @cnt1 as int declare @cnt2 as int select @cnt1 = fauxqty from inserted select @cnt2 = isnull(n.fauxqty,0) from inserted m , vwicbill_25 n where m.id = n.id if @cnt1 > @cnt2 begin print '超界了' delete from vwicbill_26 where id = (select id from inserted) end end goinsert into vwicbill_26 values(1 , 5)insert into vwicbill_26 values(2 , 25)select * from vwicbill_26drop table vwicbill_25, vwicbill_26/*(所影响的行数为 1 行) (所影响的行数为 1 行) (所影响的行数为 1 行)超界了(所影响的行数为 1 行) (所影响的行数为 1 行)id fauxqty ----------- ----------- 1 5(所影响的行数为 1 行) */
create table vwicbill_26(id int,fauxqty int)
create table vwicbill_25(id int,fauxqty int)
insert into vwicbill_25 values(1 , 10)
insert into vwicbill_25 values(2 , 20)
go
create trigger my_trig on vwicbill_26 for insert
as
begin
declare @cnt1 as int
declare @cnt2 as int
select @cnt1 = fauxqty from inserted
select @cnt2 = isnull(n.fauxqty,0) from inserted m , vwicbill_25 n where m.id = n.id
if @cnt1 > @cnt2
begin
print '超界了'
delete from vwicbill_26 where id = (select id from inserted)
end
end
goinsert into vwicbill_26 values(1 , 5)insert into vwicbill_26 values(2 , 25)select * from vwicbill_26drop table vwicbill_25, vwicbill_26/*(所影响的行数为 1 行)
(所影响的行数为 1 行)
(所影响的行数为 1 行)超界了(所影响的行数为 1 行)
(所影响的行数为 1 行)id fauxqty
----------- -----------
1 5(所影响的行数为 1 行)
*/