欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SqlServer-触发器

程序员文章站 2023-11-23 10:39:04
这两触发器比较精简,容易理解 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