USE MASTER GO CREATE DATABASE DBAEventManagement ; GO USE DBAEventManagement ; GO -- For new database service broker is enabled by default watch out for upgraded database though! SELECT name, is_broker_enabled FROM sys.databases WHERE database_id = DB_ID() ; GO -- Create a service broker queue to hold the events CREATE QUEUE syseventqueue ; GO CREATE SERVICE syseventservice ON QUEUE syseventqueue ( [http://schemas.microsoft.com/SQL/Notifications/PostEventNotification] ) ; GO SELECT * FROM sys.event_notification_event_types ORDER BY Type_Name ; GO CREATE EVENT NOTIFICATION notify_locks ON SERVER WITH fan_in FOR DEADLOCK_GRAPH TO SERVICE 'syseventservice', 'current database' ; GO SELECT cast( message_body as xml ), * FROM syseventqueue ; GO SELECT cast( message_body as xml ).query('EVENT_INSTANCE/TextData/deadlock-list') FROM syseventqueue ; GO