CREATE trigger tri_test on tb1 after insert as declare @billcode varchar(12) declare @paymethod varchar(5) select @billcode=billcode ,@paymethod=paymethod from inserted if @paymethod='7006' begin insert into zztopp(zz) select billcode from inserted end go
for 触发器就是after 触发器
if object_id('ta') is not null drop table ta if object_id('tb') is not null drop table tb create table ta ( a int,b int) create table tb (c int) go create trigger t_ta on ta for insert as begin set nocount on insert into tb select b from inserted where a=7006 set nocount off end go insert into ta select 7006,8888 go select * from ta select * from tb /* a b 7006 8888c 8888 */
zztopp是有触发器,如果这样的话有没有其他办法呢
如果不影响逻辑关系可以使触发器暂时失效(第一句),再恢复(2),不推荐这样使用 ALTER TABLE zztopp DISABLE TRIGGER ALL ALTER TABLE zztopp ENABLETRIGGER ALL
on tb1
after insert
as
declare @billcode varchar(12)
declare @paymethod varchar(5)
select @billcode=billcode ,@paymethod=paymethod from inserted
if @paymethod='7006'
begin
insert into zztopp(zz) select billcode from inserted
end
go
if object_id('tb') is not null drop table tb
create table ta ( a int,b int)
create table tb (c int)
go
create trigger t_ta on ta
for insert
as
begin
set nocount on
insert into tb select b from inserted where a=7006
set nocount off
end
go
insert into ta select 7006,8888
go
select * from ta
select * from tb
/*
a b
7006 8888c
8888
*/
ALTER TABLE zztopp DISABLE TRIGGER ALL
ALTER TABLE zztopp ENABLETRIGGER ALL
我想在tb1表有billcode跟paymethod字段,我想单插入paymethod值为7006是将billcode插入到zztopp表中,
按以下语句执行后如paymethod不为7006时tb1能插入,zztopp表没插入,但是如为7006时zztopp表是插入了,
但tb1表反而没插入,为什么呢? 这段文字我看的都头晕。。奇怪,怎么读起来就怎么不顺呢。 。是我理解错误了吗
”我想在tb1表有billcode跟paymethod字段,我想单插入paymethod值为7006是将billcode插入到zztopp表中,“