sql server的一道简单问题但是菜鸟怎么也不会改
题目:
Create an event notification that records every attempt to create or drop a table in the Sales schema in the AdventureWorks database. Store the information in a log table by a stored procedure invoked by a Service Broker service.
我的代码:
USE AdventureWorks
ALTER DATABASE AdventureWorks SET ENABLE_BROKER
GO
CREATE TABLE Sales.LogTable
(EventName varchar(10),TableName varchar(10))
GO
CREATE PROC Sales.LogProc
AS
DECLARE @message_body XML,@message_type_name NVARCHAR(256),@dialog UNIQUEIDENTIFIER;
BEGIN
WAITFOR (
RECEIVE TOP(1)
@dialog=conversation_handle,
@message_type_name=message_type_name,
@message_body=message_body
FROM Sales.NotifyQueue
),TIMEOUT 100;
INSERT INTO Sales.LogTable(EventName,TableName)
VALUES(
CAST(@message_body.query('/EVENT_INSTANCE/EventName/text()')AS varchar(10)),
CAST(@message_body.query('/EVENT_INSTANCE/TableName/text()')AS varchar(10)))
END
GO
CREATE QUEUE Sales.NotifyQueue
WITH ACTIVATION(
STATUS=ON,
PROCEDURE_NAME=Sales.LogProc,
MAX_QUEUE_READERS=10,
EXECUTE AS SELF)
GO
CREATE SERVICE NotifyService
ON QUEUE Sales.NotifyQueue
([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification])
GO
CREATE ROUTE NotifyRoute
WITH SERVICE_NAME='NotifyService',
ADDRESS='LOCAL'
GO
CREATE EVENT NOTIFICATION NotifyCREATE_TABLE
ON DATABASE
FOR CREATE_TABLE
TO SERVICE 'NotifyService', 'current database'
GO
CREATE EVENT NOTIFICATION NotifyDROP_TABLE
ON DATABASE
FOR DROP_TABLE
TO SERVICE 'NotifyService', 'current database'
GO
CREATE TABLE Sales.Test(col1 int)
GO
SELECT * FROM Sales.LogTable
出来的结果没有报错,但是什么都没留在LOGTABLE里,请问怎么修改,谢谢
------解决方案--------------------
create database AdventureWorks
use AdventureWorks
alter database AdventureWorks set enable_broker
alter database AdventureWorks set trustworthy on
create schema Sales
create table Sales.LogTable
(EventName varchar(10),
TableName varchar(10)
)