CREATE TABLE TestTable (ID int, Data nvarchar(50))
GO

-- INSERT Trigger

INSERT TestTable VALUES (1,'Hello World')

-- FOR UPDATE Trigger

UPDATE TestTable SET ID = 1
UPDATE TestTable SET Data = 'Hello Israel'

-- DELETE Trigger (rollback)

SELECT * FROM TestTable
DELETE TestTable

-- AFTER UPDATE Trigger

UPDATE TestTable SET Data = 'Hello Israel'

-- DDL Trigger - CREATE TABLE

CREATE TRIGGER clrCreateTableTrigger
 ON DATABASE FOR CREATE_TABLE 
 AS EXTERNAL NAME [CoolDBObjects].[Triggers].[clrCreateTableTrigger]

CREATE TABLE TestTable2 (ID int, Data nvarchar(50))

DROP TABLE TestTable2

DROP TRIGGER clrCreateTableTrigger ON DATABASE

-- DDL Trigger - CREATE VIEW

CREATE TRIGGER clrCreateViewTrigger
 ON DATABASE FOR CREATE_VIEW 
 AS EXTERNAL NAME [CoolDBObjects].[Triggers].[clrCreateViewTrigger]

CREATE VIEW TestView AS SELECT * FROM TestTable

DROP VIEW TestView

DROP TRIGGER clrCreateViewTrigger ON DATABASE

-- Done

DROP TABLE TestTable
GO
