--触发器测试
--第一个文件:建库加数据

use master
go

if exists(select * from sysdatabases where name = 'testForTrigger')
 drop database testForTrigger
go

create database testForTrigger
go

use testForTrigger
go
create table Table_A
(
A_ID int primary key,
a int
)
go
create table Table_B
(
B_ID int primary key,
b int
)
go
insert into Table_A values(1,0)
go
insert into Table_B values(1,0)
go

--第二个文件:添加触发器
create trigger update_For_Table_B
on Table_A
for update
as
begin
 update Table_B set b=b+1 where B_ID =(select top 1 A_ID from inserted)
end
--第三个文件:测试
update Table_A set a=a+1 Where A_ID =1
go
select * From Table_A
go
select * From Table_B
go