-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTriggers.sql
More file actions
executable file
·29 lines (25 loc) · 907 Bytes
/
Triggers.sql
File metadata and controls
executable file
·29 lines (25 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**********************************************************************************************/
-- Create a trigger to audit changes to the product colors
CREATE TRIGGER TR_Product_Color_UPDATE
ON dbo.Product
FOR UPDATE
AS
BEGIN
SET NOCOUNT ON;
IF UPDATE(Color) BEGIN
INSERT dbo.ProductColorAudit (ProductID, OldColor, NewColor)
SELECT i.ProductID, d.Color, i.Color
FROM inserted AS i
INNER JOIN deleted AS d
ON i.ProductID = d.ProductID;
END;
END;
GO
/**********************************************************************************************/
-- what triggers are installed?
SELECT type, name, parent_class_desc FROM sys.triggers
WHERE parent_class_desc = 'DATABASE'
UNION
SELECT type, name, parent_class_desc FROM sys.server_triggers
WHERE parent_class_desc = 'SERVER'
/**********************************************************************************************/