Created
June 9, 2020 12:37
-
-
Save sandeep540/36709ce88d5ee60c70f9c83c8214d252 to your computer and use it in GitHub Desktop.
SQL Trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TRIGGER User_log_INSERT on dbo.Users | |
AFTER INSERT AS | |
BEGIN | |
INSERT INTO dbo.Users_log | |
( uuid, firstname, lastname, age, social, gender, action, changeuser, modifiedOn) | |
SELECT i.uuid, i.firstname, i.lastname, i.age, i.social, i.gender, 'INSERTED', SUSER_NAME(), GETDATE() FROM inserted i | |
END | |
CREATE TRIGGER User_log_UPDATE on dbo.Users | |
AFTER UPDATE AS | |
BEGIN | |
INSERT INTO dbo.Users_log | |
( uuid, firstname, lastname, age, social, gender, action, changeuser, modifiedOn) | |
SELECT i.uuid, i.firstname, i.lastname, i.age, i.social, i.gender, 'UPDATED', SUSER_NAME(), GETDATE() FROM inserted i | |
END | |
CREATE TRIGGER User_log_DELETE on dbo.Users | |
AFTER DELETE AS | |
BEGIN | |
INSERT INTO dbo.Users_log | |
( uuid, firstname, lastname, age, social, gender, action, changeuser, modifiedOn) | |
SELECT i.uuid, i.firstname, i.lastname, i.age, i.social, i.gender, 'UPDATED', SUSER_NAME(), GETDATE() FROM deleted i | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment