34,593
社区成员
发帖
与我相关
我的任务
分享
CREATE TRIGGER reminder
ON table1
FOR UPDATE
AS
insert into table2 select id,... from deleted where status=6
create table a
(
id int primary key identity(1,1),
name varchar(10)
)
create table b
(
id int primary key identity(1,1),
aid int,
name varchar(10)
)
insert a
select 'a1' union all
select 'a2'
insert into b
select 1,'b01' union all
select 2,'b02'
drop trigger trig_a
create trigger trig_a
on a
for update
as
declare @id int
select @id=id from inserted
update b set name = 'ok' where aid = @id
go
update a set name = 'a3' where id = 1
select * from a
select * from b
/**
id name
----------- ----------
1 a3
2 a3
(所影响的行数为 2 行)
id aid name
----------- ----------- ----------
1 1 ok
2 2 b03
(所影响的行数为 2 行)
**/
drop table a
drop table b
create table a
(
id int primary key identity(1,1),
name varchar(50)
)
create table b
(
id int primary key identity(1,1),
aid int
)
insert a
select 'a1' union all
select 'a2'
CREATE TRIGGER reminder
ON a
FOR update
AS
insert into b
select id from a where id in(select top 1 id from deleted )
go
update a set name = 'qaz1105836858' where id = 2
CREATE TRIGGER reminder
ON table1
FOR UPDATE
AS
insert into table2 select id,col,... from table1 where status=6
CREATE TRIGGER reminder
ON 表
FOR update
AS
insert into table2
select id from table1 where id in(select * from deleted)
go
create table a
(
id int primary key identity(1,1),
name varchar(10)
)
create table b
(
id int primary key identity(1,1),
aid int,
name varchar(10)
)
insert a
select 'a1' union all
select 'a2'
insert into b
select 1,'b01' union all
select 2,'b02'
create trigger trig_a
on a
for update
as
declare @id i
SELECT @id=IDENT_CURRENT('a')
update b set name = 'b03' where aid = @id
go
update a set name = 'a3' where id = 2
select * from a
select * from b
/**
id name
----------- ----------
1 a1
2 a3
(所影响的行数为 2 行)
id aid name
----------- ----------- ----------
1 1 b01
2 2 b03
(所影响的行数为 2 行)
**/
CREATE TRIGGER reminder
ON 表
FOR update
AS
--sql语句
go