表 z_attribute 表 z_attribute_backup
两个表字段相同 对表z_attribute 应用触发器
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
但是我想加个条件 就是如果INSERT,update 表z_attribute时 字段 原因 = '进店'时 触发器 不起作用(就是不insert into z_attribute_backup)
如何在这个触发器里实现??
求明白人解惑!~!
8 个解决方案
#1
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
if not exists(Select * from inserted where 原因 = '进店')
begin
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
end
go
FOR INSERT,update
AS
if not exists(Select * from inserted where 原因 = '进店')
begin
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
end
go
#2
--或者意思是
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
where 原因 <>'进店'
go
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
where 原因 <>'进店'
go
#3
for--为条件
insert,update,delete--分为三个条件
insert,update,delete--分为三个条件
#4
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
declare @str varchar(500)
set @str=(select 原因 from inserted)
if @str= '进店'
begin
--不处理
end
else
begin
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
end
FOR INSERT,update
AS
declare @str varchar(500)
set @str=(select 原因 from inserted)
if @str= '进店'
begin
--不处理
end
else
begin
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
end
#5
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted where 原因 <> '进店'
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted where 原因 <> '进店'
#6
WangZWang(先来) 的是插入的纪录中只要有 原因 = '进店' 就不处理这组数据了,
aw511(点点星灯) 考虑的不全面,你的语句只考虑每回插入一条的情况,如果要是批量就会有问题了。
aw511(点点星灯) 考虑的不全面,你的语句只考虑每回插入一条的情况,如果要是批量就会有问题了。
#7
CREATE TRIGGER insert_backup ON z_attribute
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted where 原因 <> '进店'
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted where 原因 <> '进店'
#8
学习. :)
#1
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
if not exists(Select * from inserted where 原因 = '进店')
begin
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
end
go
FOR INSERT,update
AS
if not exists(Select * from inserted where 原因 = '进店')
begin
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
end
go
#2
--或者意思是
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
where 原因 <>'进店'
go
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
where 原因 <>'进店'
go
#3
for--为条件
insert,update,delete--分为三个条件
insert,update,delete--分为三个条件
#4
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
declare @str varchar(500)
set @str=(select 原因 from inserted)
if @str= '进店'
begin
--不处理
end
else
begin
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
end
FOR INSERT,update
AS
declare @str varchar(500)
set @str=(select 原因 from inserted)
if @str= '进店'
begin
--不处理
end
else
begin
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted
end
#5
CREATE TRIGGER insert_backup ON [dbo].[z_attribute]
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted where 原因 <> '进店'
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted where 原因 <> '进店'
#6
WangZWang(先来) 的是插入的纪录中只要有 原因 = '进店' 就不处理这组数据了,
aw511(点点星灯) 考虑的不全面,你的语句只考虑每回插入一条的情况,如果要是批量就会有问题了。
aw511(点点星灯) 考虑的不全面,你的语句只考虑每回插入一条的情况,如果要是批量就会有问题了。
#7
CREATE TRIGGER insert_backup ON z_attribute
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted where 原因 <> '进店'
FOR INSERT,update
AS
insert into z_attribute_backup(userid,部门,班组,岗位,行政级别,人事属性,原因)
select userid,部门,班组,岗位,行政级别,人事属性,原因 from inserted where 原因 <> '进店'
#8
学习. :)