Skip to content

Instantly share code, notes, and snippets.

@adgedenkers
Created March 5, 2024 16:13
Show Gist options
  • Save adgedenkers/f222cac21b5d6f333a69e3fada9c7144 to your computer and use it in GitHub Desktop.
Save adgedenkers/f222cac21b5d6f333a69e3fada9c7144 to your computer and use it in GitHub Desktop.
New SQL Tables
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