--新增触发器
CREATE TRIGGER t_insert_itemnumber
on sys_user
for INSERT
AS
declare @user_id varchar(50)
BEGIN
select @user_id=user_id from inserted
update sys_user set user_app_pwd=123 where user_id = @user_id
END
GO
--修改触发器
Create trigger [dbo].[t_update_itemnumber]
on [dbo].[T_Data_Scales]
for update
as
begin
Declare @ID varchar(50)
Declare @FName varchar(50)
Declare @OldFName varchar(50)
--更新前的数据
select @OldFName = F_Item from deleted;
--更新后的数据
SELECT @ID = F_ID,@FName = F_Item FROM inserted
IF(@OldFName <> @FName)
BEGIN
update T_Data_Scales set F_ItemNumber=(SELECT T.FNUMBER F_ItemValue FROM AIS2021..T_BD_MATERIAL t
LEFT JOIN AIS2021..T_BD_MATERIAL_L t1 on t.FMASTERID = t1.FMATERIALID
WHERE t.F_HYKD_CHECKBOX = 1 AND t.FUSEORGID = 100004 AND t1.FName = @FName)
WHERE F_ID = @ID
END
end
GO
(SqlServer)触发器 (新增修改)
于 2019-10-30 09:38:09 首次发布