SqlServer-触发器
程序员文章站
2022-06-29 12:32:11
这两触发器比较精简,容易理解 1、简单触发器 CREATE TRIGGER [dbo].[TriggerLog] ON [dbo].[Users] AFTER UPDATEAS BEGIN SET NOCOUNT ON; Insert into dbo.[log](LogContent) selec ......
这两触发器比较精简,容易理解
1、简单触发器
create trigger [dbo].[triggerlog]
on [dbo].[users]
after update
as
begin
set nocount on;
insert into dbo.[log](logcontent) select '修改前:'+deleted.username+deleted.userrealname+'修改后:'+inserted.username+inserted.userrealname from deleted,inserted
end
2、触发器-包含类型转换
create trigger [dbo].[triggerlog]
on [dbo].[base_user]
after update
as
begin
-- set nocount on added to prevent extra result sets from
-- interfering with select statements.
set nocount on;
insert into [dbo].[log](logname) select '修改前:' +deleted.account+deleted.[password]+convert(varchar,deleted.coin)+'修改后:'+inserted.account+inserted.[password]+convert(varchar,inserted.coin) from deleted,inserted
-- convert(数据类型,值)
end
go