致远人员档案员工离职触发器,客户应收款修改

测试例子

  哪张表需要触发修改其它表的内容 就在这张中执行,数据库使用的是sqlserver2008

创建触发器

create trigger [MyUser_trigger]
on [dbo].[MyUser]
for insert,delete
as
begin
if exists ( select * from sysobjects where name = 'temp' and type = 'U')
drop table temp
select identity(int,1,1) as rowid,UserName into temp from MyUser
end

-- 开始新建过程
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[MyUser_trigger]
on [dbo].[MyUser]
for insert,delete
as
begin

--同时插入数据
declare @id int,@name varchar(50),@age varchar(50),@address varchar(50); --声明
select @id= id,@name=name,@age=age,@address=address from MyUser    --获取到插入的数据并且给变量赋值
--insert into MyUserb values(@id,@name,@age,@address)       --将数据插入到指定的表中
UPDATE MyUserb SET address=@address where name=@name and age=@age

end
go

测试完成标准sql

create trigger [formmain_0084_trigger]
on [dbo].[formmain_0016]
for insert
as
begin
if exists ( select * from sysobjects where name = 'temp' and type = 'U')
drop table temp
select identity(int,1,1) as rowid,field0001 into temp from formmain_0016
end

--开始写触发内容

--开始新建过程
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[formmain_0084_trigger]
on [dbo].[formmain_0016]
for insert
as
begin

--同时插入数据
declare @field0001 varchar(100),@field0007 decimal(18),@field0027 varchar(100),@field0006 datetime; --声明 姓名,身份证号,在职状态,离职日期
select @field0001=field0001,@field0007=field0007,@field0027=field0027,@field000from formmain_0016 6=field0006    --获取到插入的数据并且给变量赋值
UPDATE formmain_0084 SET field0020=@field0027,field0021=@field0006 where field0003=@field0001 and field0007=@field0007

end
go

注意事项:
流程审批结束之后再触发

客户应收款信息变更触发器

主表0096 明细表0097

--创建主表0096触发器
create trigger [formmain_0096_trigger]
on [dbo].[formmain_0096]
for insert
as
begin
if exists ( select * from sysobjects where name = 'temp' and type = 'U')
drop table temp
select identity(int,1,1) as rowid,field0001 into temp from formmain_0096
end

--新建触发过程和内容
--开始新建过程
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[formmain_0096_trigger]
on [dbo].[formmain_0096]
for insert
as
begin

--同时插入数据
declare @field0001 varchar(100),@field0007 decimal(18),@field0027 varchar(100),@field0006 datetime; --声明 姓名,身份证号,在职状态,离职日期
select @field0001=field0001,@field0007=field0007,@field0027=field0027,@field000from formmain_0016 6=field0006    --获取到插入的数据并且给变量赋值
UPDATE formmain_0084 SET field0020=@field0027,field0021=@field0006 where field0003=@field0001 and field0007=@field0007

end
go
posted @ 2022-09-22 10:40  西北后生  阅读(37)  评论(0编辑  收藏  举报