Make SQL Server to talk you! Antonios Chatzipavlis Software Architect, Development Evangelist, IT Consultant MCT, MCITP, MCPD, MCSD, MCDBA, MCSA, MCTS, MCAD, MCP, OCA MVP on SQL SERVER
2 Objectives SQL Server Agent Alert System Event Notifications
3 What Is an Alert? Predefined response to an event Triggered by jobs, performance conditions, or application log events Can notify an operator or start a specified job
4 Create an Alert Specify Alert name Condition (Event, WMI trigger, performance condition) that triggers the alert Response – notify an operator, start a job Use SQL Server Management Studio or “sp_add_alert” EXEC = N'Test = = = N'Error has occurred. The database will be backed = N'Back up the AdventureWorks Database' ;
5 Responding to Alerts Launch a Job Use an existing job Create a new job Notify an Operator Schedule responders for different parts of the day or week , pager, or net send Either Or
6 DEMO Using Alerts
7 Overview of Event Notifications Messages containing event data DDL Events Trace Events DML Events Database and Server Events Sent to an event processing service by using Service Broker A message type and contract are predefined You must create a queue, a service, and a route
8 Creating Event Notifications 1.Define the Event Notification 2.Specify the Scope 3.Specify the Event 4.Specify the Service CREATE EVENT NOTIFICATION NotifyALTER_T1 ON DATABASE FOR ALTER_TABLE TO SERVICE '//Adventure-Works.com/ArchiveService', '8140a771-3c4b ac ab17984';
9 Processing Event Notifications 1.Receive the message 2.Extract event data by using XQuery XML ;RECEIVE = = message_body FROM dbo.NotifyQueue; IF = 0 RETURN nvarchar(1000) nvarchar(24) nvarchar(6) ('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]', 'nvarchar(100)') ('(/EVENT_INSTANCE/PostTime)[1]','nvarchar(24)') ('(/EVENT_INSTANCE/SPID)[1]','nvarchar(6)')
10 Managing Event Notifications 1.Viewing event notifications and queues 2.Deleting event notifications SELECT name FROM sys.event_notifications SELECT definition FROM sys.service_queues DROP EVENT NOTIFICATION UpdateStats ON SERVER
11 DEMO Implementing Event Notifications
12 Q & A
13 My Blogs
14 Thank you