Created
March 5, 2024 16:13
-
-
Save adgedenkers/f222cac21b5d6f333a69e3fada9c7144 to your computer and use it in GitHub Desktop.
New SQL Tables
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 TABLE table_name ( | |
id INT PRIMARY KEY IDENTITY(1,1) | |
,title VARCHAR(15) | |
,created DATETIME NOT NULL DEFAULT GETDATE() | |
,updated DATETIME NULL | |
,is_active INT NOT NULL DEFAULT 1 | |
); | |
GO | |
CREATE TRIGGER trg_UpdatedTableName | |
ON table_name | |
AFTER UPDATE | |
AS | |
BEGIN | |
SET NOCOUNT ON; | |
IF TRIGGER_NESTLEVEL() > 1 RETURN; | |
UPDATE table_name | |
SET updated = GETDATE() | |
FROM inserted i | |
WHERE table_name.id = i.id | |
END; | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment