Skip to content

Instantly share code, notes, and snippets.

@max-mulawa
max-mulawa / CustomerTrigger.cs
Created April 19, 2011 18:39
CLRTriggers 4
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
using Weather.com.Client;
using Weather.com.Client.WeatherConditions.Forecasts;
using Weather.com.Client.WeatherConditions.Location;
namespace Mulawa.SqlServer.CLRTriggers
{
@max-mulawa
max-mulawa / DML_Trigger_Snippet_1.sql
Created April 19, 2011 19:00
DML Trigger Snippet 1
use master;
GO
CREATE DATABASE TriggerDatabase;
GO
use TriggerDatabase;
GO
CREATE TABLE dbo.Customers
(
CustomerName Varchar(10) NOT NULL
)
@max-mulawa
max-mulawa / DML_Trigger_Snippet2.sql
Created April 20, 2011 09:24
DML Trigger Snippet 2
CREATE VIEW dbo.vCustomers
AS
SELECT CustomerName FROM dbo.Customers
GO
CREATE TRIGGER dbo.vCustomers_AfterDelete
ON dbo.vCustomers
INSTEAD OF DELETE
AS
BEGIN
DELETE c
@max-mulawa
max-mulawa / DML_Trigger_Sinppet_3.sql
Created April 20, 2011 09:30
DML Trigger Sinppet 3
CREATE TRIGGER dbo.Customers_AfterUpdate
ON dbo.Customers
AFTER UPDATE
AS
BEGIN
PRINT 'After Update'
END
GO
DISABLE TRIGGER dbo.Customers_AfterUpdate ON dbo.Customers;
GO
@max-mulawa
max-mulawa / DML_Trigger_Snippet_3.sql
Created April 20, 2011 09:32
DML Trigger Snippet 3
CREATE TRIGGER dbo.Customers_AfterUpdate
ON dbo.Customers
AFTER UPDATE
AS
BEGIN
PRINT 'After Update'
END
GO
DISABLE TRIGGER dbo.Customers_AfterUpdate
ON dbo.Customers;
@max-mulawa
max-mulawa / DML_Trigger_Snippet_3.sql
Created April 20, 2011 09:34
DML Trigger Snippet 4
SELECT t.*, te.*
FROM sys.triggers t
INNER JOIN sys.trigger_events te
ON t.object_id = te.object_id
@max-mulawa
max-mulawa / DML_Trigger_Snippet_5.sql
Created April 20, 2011 09:42
DML Trigger Snippet 5
CREATE TABLE dbo.CustomerNameAudit
(
CustomerName Varchar(10) NOT NULL,
ChangeDate DATETIME DEFAULT(GETDATE()) NOT NULL
)
GO
CREATE TRIGGER dbo.Customers_AfterUpdateInsertAudit
ON dbo.Customers
AFTER UPDATE, INSERT
AS
@max-mulawa
max-mulawa / DML Trigger Snippet 6.sql
Created April 20, 2011 09:45
DML Trigger Snippet 6
CREATE TRIGGER dbo.Customers_stopUpdates
ON dbo.Customers
AFTER UPDATE
AS
BEGIN
RAISERROR ('Cutomers table cannot be updated.', 16, 1)
ROLLBACK TRAN
END
GO
DROP TRIGGER dbo.Customers_stopUpdates;
@max-mulawa
max-mulawa / DML Trigger Snippet 7.sql
Created April 20, 2011 09:47
DML Trigger Snippet 7
CREATE TRIGGER dbo.Customers_stopUpdates
ON dbo.Customers
INSTEAD OF UPDATE
AS
BEGIN
RAISERROR ('Cutomers table cannot be updated.', 16, 1)
ROLLBACK TRAN
END
GO
DROP TRIGGER dbo.Customers_stopUpdates
@max-mulawa
max-mulawa / WeatherClient1.cs
Created April 20, 2011 19:15
WeatherClient 1
WeatherClient client = new WeatherClient(
"[Partner Id here]"
, "[License Key here]");
List<Location>= client.GetLocation("Warsaw,Poland");