表A 表B
a b c d e f g
x y 0 1 0 0 0
当c更新为1时,把这一行数据插到B中,结果如下
表A 表B
a b c d e f g
x y 1 1 0 0 0
x y 0 0IF EXISTS(Select Name From Sysobjects Where Name='aa' And Type='TR')
DROP TRIGGER aa
go
CREATE TRIGGER aa
on
A
after update
as
if update(c)
declare @a varchar(50),@b as varchar(50)
select @a = a,@b = b from inserted
inser into B (d,e,f,g)~~??这里下去应该怎么写啊??因为d和e能从inserted中找到,但是f和g要赋0~~
a b c d e f g
x y 0 1 0 0 0
当c更新为1时,把这一行数据插到B中,结果如下
表A 表B
a b c d e f g
x y 1 1 0 0 0
x y 0 0IF EXISTS(Select Name From Sysobjects Where Name='aa' And Type='TR')
DROP TRIGGER aa
go
CREATE TRIGGER aa
on
A
after update
as
if update(c)
declare @a varchar(50),@b as varchar(50)
select @a = a,@b = b from inserted
inser into B (d,e,f,g)~~??这里下去应该怎么写啊??因为d和e能从inserted中找到,但是f和g要赋0~~
select a,b,0,0 from inserted
select @a = a,@b = b from inserted 这两句可以不要了,否则同时更新多个的时候会出问题
DROP TRIGGER aa
go
CREATE TRIGGER aa
on
A
after update
as
if update(c)
inser into B (d,e,f,g)
select a,b,0,0 from inserted
go
select a,b,0,0 from inserted where 条件
CREATE TRIGGER aa
on
A
after update
as
if update(c)
begin
inser into B (d,e,f,g)
select a,b,0,0 from inserted
end
select a,b,0,0 from inserted如果g的值我是从另外一张表C里面找的值呢,C和A,B没有任何关系
a b c d e f g FormName g
x y 0 1 0 0 0 A XY
B yx当c更新为1时,把这一行数据插到B中,结果如下
表A 表B
a b c d e f g
x y 1 1 0 0 0
x y 0 yx C和A,B没有字段上什么关系,只是根据你插入的那张表,如果你插入A表则g等于xy 如果插入B表则g等于yx这样子
DROP TRIGGER aa
go
CREATE TRIGGER aa
on
A
after update
as
if update(c)
inser into B (d,e,f,g)
select a,b,0,0 from inserted
go