Inserted and deleted are two temporary tables used in the trigger. When the insert operation is executed, the inserted records are stored in inserted. When the delete operation is executed, the deleted records are stored in deleted. When update is executed, the modified records are stored in inserted and the pre-modified records are stored in deleted.
Copy codeThe Code is as follows:
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
Delete:
Copy codeThe Code is as follows:
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
Modify:
Copy codeThe Code is as follows:
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