SlideShare a Scribd company logo
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
Objectives
• SQL Server Agent Alert System
• Event Notifications

2
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

3
Create an Alert
Use SQL Server Management Studio or “sp_add_alert”

Specify


Alert name



Condition (Event, WMI trigger, performance condition) that
triggers the alert



Response – notify an operator, start a job

EXEC dbo.sp_add_alert
@name = N'Test Alert',
@message_id = 55001, @severity = 0, @notification_message =
N'Error 55001 has occurred. The database will be backed up...',
@job_name = N'Back up the AdventureWorks Database' ;
4
Responding to Alerts
Either
Launch a Job


Use an existing job



Create a new job

Or
Notify an Operator


Schedule responders for different parts of the day or week



E-mail, pager, or net send

5
Using Alerts

DEMO

6
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

7
Creating Event Notifications
1.
2.
3.
4.

Define the Event Notification
Specify the Scope
Specify the Event
Specify the Service

CREATE EVENT NOTIFICATION NotifyALTER_T1
ON DATABASE
FOR ALTER_TABLE
TO SERVICE '//Adventure-Works.com/ArchiveService' ,
'8140a771-3c4b-4479-8ac0-81008ab17984';

8
Processing Event Notifications
1. Receive the message
2. Extract event data by using XQuery
DECLARE @cmd nvarchar(1000) NVARCHAR(256),
DECLARE
@messageTypeName
DECLARE @posttime nvarchar(24)
@messageBody XML
DECLARE @spid nvarchar(6)
;RECEIVE TOP(1)
@messageTypeName = message_type_name,
SET @messageBody = message_body
@cmd = @messagebody.value
('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]',
FROM dbo.NotifyQueue;
'nvarchar(100)')
SET @@ROWCOUNT = 0
IF @messagebody.value
('(/EVENT_INSTANCE/PostTime)[1]','nvarchar(24)')
RETURN
SET @spid = @messagebody.value
('(/EVENT_INSTANCE/SPID)[1]','nvarchar(6)')

9
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

10
Implementing Event Notifications

DEMO

11
Q&A
12
My Blogs
http://www.autoexec.gr/blogs/antonch

http://www.dotnetzone.gr/cs/blogs/antonch

13
Thank you

14

More Related Content

PPTX
Securing and maintaining azure sql
PPTX
PPTX
working with sql server agent-2
PDF
MSSQL Server - Automation
PDF
DBOps
PDF
VIPIN_GUPTA_SECURITY_ANALYST
PPTX
Sql server lesson9
PDF
Novell Identity Manager Tips, Tricks and Best Practices
Securing and maintaining azure sql
working with sql server agent-2
MSSQL Server - Automation
DBOps
VIPIN_GUPTA_SECURITY_ANALYST
Sql server lesson9
Novell Identity Manager Tips, Tricks and Best Practices

Similar to Make sql server to talk you (20)

DOC
B Woodward Portfolio
PPTX
Presentation
PDF
Hot sos em12c_metric_extensions
PDF
Sherlock holmes for dba’s
PPT
Oracle Applications Alerts
PPT
Gerry Hughes Bi Portfolio
DOCX
Nadeem_CV
PDF
Regain Control Thanks To Prometheus
DOCX
Alerts in r12
PDF
Practical Approach towards SQLi ppt
PPTX
Sql Injection V.2
DOC
Sample dotnet project
PDF
PPTX
Code injection
PPTX
Strata+Hadoop 2015 NYC End User Panel on Real-Time Data Analytics
DOCX
Andrew Kaplan Resume - 13Jul2016
PPT
Less09 Data
PDF
Time-Based Blind SQL Injection Using Heavy Queries
PPTX
Struts 2 – Architecture
DOCX
Sql Resume
B Woodward Portfolio
Presentation
Hot sos em12c_metric_extensions
Sherlock holmes for dba’s
Oracle Applications Alerts
Gerry Hughes Bi Portfolio
Nadeem_CV
Regain Control Thanks To Prometheus
Alerts in r12
Practical Approach towards SQLi ppt
Sql Injection V.2
Sample dotnet project
Code injection
Strata+Hadoop 2015 NYC End User Panel on Real-Time Data Analytics
Andrew Kaplan Resume - 13Jul2016
Less09 Data
Time-Based Blind SQL Injection Using Heavy Queries
Struts 2 – Architecture
Sql Resume
Ad

More from Antonios Chatzipavlis (20)

PPTX
Data virtualization using polybase
PDF
SQL server Backup Restore Revealed
PDF
Migrate SQL Workloads to Azure
PDF
Machine Learning in SQL Server 2019
PDF
Workload Management in SQL Server 2019
PDF
Loading Data into Azure SQL DW (Synapse Analytics)
PDF
Introduction to DAX Language
PDF
Building diagnostic queries using DMVs and DMFs
PDF
Exploring T-SQL Anti-Patterns
PDF
Designing a modern data warehouse in azure
PDF
Modernizing your database with SQL Server 2019
PDF
Designing a modern data warehouse in azure
PDF
SQLServer Database Structures
PDF
Sqlschool 2017 recap - 2018 plans
PDF
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
PDF
Microsoft SQL Family and GDPR
PDF
Statistics and Indexes Internals
PDF
Introduction to Azure Data Lake
PDF
Azure SQL Data Warehouse
PDF
Introduction to azure document db
Data virtualization using polybase
SQL server Backup Restore Revealed
Migrate SQL Workloads to Azure
Machine Learning in SQL Server 2019
Workload Management in SQL Server 2019
Loading Data into Azure SQL DW (Synapse Analytics)
Introduction to DAX Language
Building diagnostic queries using DMVs and DMFs
Exploring T-SQL Anti-Patterns
Designing a modern data warehouse in azure
Modernizing your database with SQL Server 2019
Designing a modern data warehouse in azure
SQLServer Database Structures
Sqlschool 2017 recap - 2018 plans
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Microsoft SQL Family and GDPR
Statistics and Indexes Internals
Introduction to Azure Data Lake
Azure SQL Data Warehouse
Introduction to azure document db
Ad

Recently uploaded (20)

PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
STKI Israel Market Study 2025 version august
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPT
Module 1.ppt Iot fundamentals and Architecture
PPTX
Modernising the Digital Integration Hub
PPT
Geologic Time for studying geology for geologist
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
CloudStack 4.21: First Look Webinar slides
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Getting Started with Data Integration: FME Form 101
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Hybrid model detection and classification of lung cancer
DP Operators-handbook-extract for the Mautical Institute
STKI Israel Market Study 2025 version august
O2C Customer Invoices to Receipt V15A.pptx
WOOl fibre morphology and structure.pdf for textiles
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Tartificialntelligence_presentation.pptx
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
sustainability-14-14877-v2.pddhzftheheeeee
Final SEM Unit 1 for mit wpu at pune .pptx
Module 1.ppt Iot fundamentals and Architecture
Modernising the Digital Integration Hub
Geologic Time for studying geology for geologist
A review of recent deep learning applications in wood surface defect identifi...
CloudStack 4.21: First Look Webinar slides
Zenith AI: Advanced Artificial Intelligence
Univ-Connecticut-ChatGPT-Presentaion.pdf
Enhancing emotion recognition model for a student engagement use case through...
Getting Started with Data Integration: FME Form 101
observCloud-Native Containerability and monitoring.pptx
Hybrid model detection and classification of lung cancer

Make sql server to talk you

  • 1. 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 2
  • 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 3
  • 4. Create an Alert Use SQL Server Management Studio or “sp_add_alert” Specify  Alert name  Condition (Event, WMI trigger, performance condition) that triggers the alert  Response – notify an operator, start a job EXEC dbo.sp_add_alert @name = N'Test Alert', @message_id = 55001, @severity = 0, @notification_message = N'Error 55001 has occurred. The database will be backed up...', @job_name = N'Back up the AdventureWorks Database' ; 4
  • 5. Responding to Alerts Either Launch a Job  Use an existing job  Create a new job Or Notify an Operator  Schedule responders for different parts of the day or week  E-mail, pager, or net send 5
  • 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 7
  • 8. Creating Event Notifications 1. 2. 3. 4. Define the Event Notification Specify the Scope Specify the Event Specify the Service CREATE EVENT NOTIFICATION NotifyALTER_T1 ON DATABASE FOR ALTER_TABLE TO SERVICE '//Adventure-Works.com/ArchiveService' , '8140a771-3c4b-4479-8ac0-81008ab17984'; 8
  • 9. Processing Event Notifications 1. Receive the message 2. Extract event data by using XQuery DECLARE @cmd nvarchar(1000) NVARCHAR(256), DECLARE @messageTypeName DECLARE @posttime nvarchar(24) @messageBody XML DECLARE @spid nvarchar(6) ;RECEIVE TOP(1) @messageTypeName = message_type_name, SET @messageBody = message_body @cmd = @messagebody.value ('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]', FROM dbo.NotifyQueue; 'nvarchar(100)') SET @@ROWCOUNT = 0 IF @messagebody.value ('(/EVENT_INSTANCE/PostTime)[1]','nvarchar(24)') RETURN SET @spid = @messagebody.value ('(/EVENT_INSTANCE/SPID)[1]','nvarchar(6)') 9
  • 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 10