Documente Academic
Documente Profesional
Documente Cultură
=
ë . Create a queue to receive messages.
2. Create a service on the queue that references the
event notifications contract.
3. Create a route on the service to define the address to
which Service Broker sends messages for the service. If
the event notification targets a service in the same
database, the DBA must specify ADDRESS = 'LOCAL'.
ë CREATE QUEUE ExforsysQueue ;
GO
CREATE SERVICE ExforsysService
ON QUEUE ExforsysQueue
(
[http://schemas.microsoft.com/SQL/Notifications/Post
EventNotification]
);
GO
CREATE ROUTE ExforsysRoute
WITH SERVICE_NAME = 'ExforsysService',
ADDRESS = 'LOCAL';
GO
V To create an event notification that is scoped to the
database (ON DATABASE), requires CREATE
DATABASE DDL EVENT NOTI'ICATION permission
in the current database.
V To create an event notification on a DDL statement
that is scoped to the server (ON SERVER), requires
CREATE DDL EVENT NOTI'ICATION permission
in the server.
V To create an event notification on a trace event,
requires CREATE TRACE EVENT NOTI'ICATION
permission in the server.
V To create an event notification that is scoped to a
queue, requires ALTER
permission on the queue.
ë --Create a queue to receive messages.
ë CREATE QUEUE NotifyQueue ;
ë GO
ë --Create a service on the queue that references
ë --the event notifications contract.
ë CREATE SERVICE NotifyService
ë ON QUEUE NotifyQueue
ë ([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification]
);
ë GO
ë --Create a route on the service to define the address
ë --to which Service Broker sends messages for the service.
ë CREATE ROUTE NotifyRoute
ë WITH SERVICE_NAME = 'NotifyService',
ë ADDRESS = 'LOCAL';
ë GO
ë --Create the event notification.
CREATE EVENT NOTI'ICATION log_ddl
ON SERVER
'OR Object_Created
TO SERVICE 'NotifyService',
'8 0a77-3c b- 79-8ac0-8008ab798 ' ;
ë CREATE EVENT NOTI'ICATION
event_notification_name ON { SERVER |
DATABASE | [ ENABLED | DISABLED ] { 'OR {
event_type | DDL_DATABASE_LEVEL_EVENTS }
[ ,...n ] TO broker_service
ë event_notification_nameThis is the name of the
event notification.
ë SERVERThe scope of the event notification is
the current server.
ë DATABASEThe scope of the event notification
is the current database.
ë ENABLEDThis specifies that the event
notification is active when the CREATE statement
has executed.
ë DISABLEDThis specifies that the event notification
is inactive until the notification is activated by
executing an ALTER EVENT NOTI'ICATION
statement.
ë event_typeThis is the name of an event that, after
execution, causes the event notification to execute.
SQL Server Books Online has the full list of events
included in event_type.
ë DDL_DATABASE_LEVEL_EVENTSThe event
notification fires after any of the CREATE, ALTER, or
DROP statements that can be indicated in
event_type execute.
ë broker_serviceThis is the SSB service to which
SQL Server posts the data about an event.