This file contains hidden or 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
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 | |
{ |
This file contains hidden or 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
use master; | |
GO | |
CREATE DATABASE TriggerDatabase; | |
GO | |
use TriggerDatabase; | |
GO | |
CREATE TABLE dbo.Customers | |
( | |
CustomerName Varchar(10) NOT NULL | |
) |
This file contains hidden or 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 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 |
This file contains hidden or 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 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 |
This file contains hidden or 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 TRIGGER dbo.Customers_AfterUpdate | |
ON dbo.Customers | |
AFTER UPDATE | |
AS | |
BEGIN | |
PRINT 'After Update' | |
END | |
GO | |
DISABLE TRIGGER dbo.Customers_AfterUpdate | |
ON dbo.Customers; |
This file contains hidden or 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
SELECT t.*, te.* | |
FROM sys.triggers t | |
INNER JOIN sys.trigger_events te | |
ON t.object_id = te.object_id |
This file contains hidden or 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 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 |
This file contains hidden or 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 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; |
This file contains hidden or 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 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 |
This file contains hidden or 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
WeatherClient client = new WeatherClient( | |
"[Partner Id here]" | |
, "[License Key here]"); | |
List<Location>= client.GetLocation("Warsaw,Poland"); |
OlderNewer