CREATE TRIGGER trg_A1_update ON A1
FOR UPDATE
AS
BEGIN
IF UPDATE(age)
update A2 set age=inserted.age
END
FOR UPDATE
AS
BEGIN
IF UPDATE(age)
update A2 set age=inserted.age
END
解决方案 »
- 一个存储过程的问题
- 请教一个DTS导入的vbs写法
- 100分求一sql语句
- 请教一下如何根据接收到的'2006-12'进行查询数据库日期段为'2006-12'月开头的数据
- 怎样查询出各个分组内ID最大的那条记录?
- 如何利用sql查询语句备份数据库!
- ColumnNameColumnValue行转列的问题
- 谁能帮我写个存储过程?
- 请问,如何联查两个数据库中的表,谢谢!
- 统计一段星期的数据的sql,高手请进
- 我想用 PROFILER 来 TRACE 一个特定软件对我服务器的所有动作,遇到一些问题请帮忙
- 全部家当100分喷血大放送,在线等~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
GO
CREATE TRIGGER A1_update ON A1
FOR UPDATE
AS
IF UPDATE(age)
BEGIN
update b
set b.age=a.age
from A1 a, A2 b
where a.name=b.name and a.age<>b.age
END
GO
CREATE TRIGGER trg_A1_update ON A1
FOR UPDATE
AS
BEGIN
IF UPDATE(age)
update A2 set age=inserted.age where Name=inserted.name
END
BEGIN declare @n varchar(50)
declare @a tinyint select @n=[name] from deleted
select @a=age from inserted update A2
set age=@a
where [name]=@n END
create trigger t_update on A1
for update
as
if update(age)
update A2 set age=b.age
from A2 a join inserted b on a.name=b.name
go
create table A1(name varchar(10),age int)
insert into A1
select 'Kevin',12
union all select 'Tony',29create table A2(name varchar(10),age int,sex char(2))
insert into A2
select 'Kevin',12,'男'
union all select 'Tony',29,'男'
go--同步处理的触发器:
create trigger t_update on A1
for update
as
if update(age)
update A2 set age=b.age
from A2 a join inserted b on a.name=b.name
go--更新测试1:单记录更新
update A1 set age=18 where name='Kevin'--显示测试结果
select * from A1
select * from A2--更新测试2:多记录更新
update A1 set age=age+1--显示测试结果
select * from A1
select * from A2
go--删除测试环境
drop table A1,A2/*--测试结果--更新测试1:单记录更新的测试结果
name age
---------- -----------
Kevin 18
Tony 29(所影响的行数为 2 行)name age sex
---------- ----------- ----
Kevin 18 男
Tony 29 男(所影响的行数为 2 行)
--更新测试2:多记录更新的测试结果
name age
---------- -----------
Kevin 19
Tony 30(所影响的行数为 2 行)name age sex
---------- ----------- ----
Kevin 19 男
Tony 30 男(所影响的行数为 2 行)
--*/
for update as
if exists(select * from inserted where name='kevin' and age='18')
begin
update a2 set age='18'
from inserted join a2 on inserted.name=a2.name
end