inserted,deleted是在触发器中使用的两个临时表,当执行insert操作时,在inserted中存储着当前插入的记录,在执行delete操作时,在deleted中存储着当前删除的记录,当执行update时,在inserted中存储着修改后的记录,在deleted中存储着修改前的记录。复制代码代码如下:setANSI_NULLSONsetQUOTED_IDENTIFIERONgoALTERTRIGGER[dnt_user_add]ON[dbo].[dnt_users]AFTERINSERTASBEGINSETNOCOUNTON;insertinto[dnt_userfields](uid)selectuidfrominsertedEND删除:复制代码代码如下:SETANSI_NULLSONGOSETQUOTED_IDENTIFIERONGOCREATETRIGGER[dnt_users_del]ON[dnt_users]AFTERDELETEASBEGINSETNOCOUNTON;delete[dnt_userfields]fromdeletedwhere[dnt_userf
inserted,deleted是在触发器中使用的两个临时表,当执行insert操作时,在inserted中存储着当前插入的记录,在执行delete操作时,在deleted中存储着当前删除的记录,当执行update时,在inserted中存储着修改后的记录,在deleted中存储着修改前的记录。
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [dnt_user_add]
ON [dbo].[dnt_users]
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
insert into [dnt_userfields](uid)
select uid from inserted
END
删除:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dnt_users_del]
ON [dnt_users]
AFTER DELETE
AS
BEGIN
SET NOCOUNT ON;
delete [dnt_userfields] from deleted where [dnt_userfields].uid=deleted.uid
END
GO
修改:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dnt_users_up]
ON [dnt_users]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
UPDATE [dnt_userfields] Set icq = inserted.uid from inserted where [dnt_userfields].uid = inserted.uid
END
GO
声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!