TAILIEUCHUNG - Hướng dẫn học Microsoft SQL Server 2008 part 71

Phát triển DDL Triggers Các mã kích hoạt được mã T-SQL bình thường. Trong một cách nào đó, một kích hoạt DDL là dễ viết hơn so với một kích hoạt DML vì DDL gây nên luôn luôn cháy trong một sự kiện đơn lẻ, trong khi DML gây nên phải xử lý các sự kiện với nhiều hàng bị ảnh hưởng liên quan đến việc bàn cơ sở, và chèn vào và xóa các bảng ảo. Sự phức tạp của các kết quả kích hoạt DDL từ thực tế là các dữ liệu về sự kiện này là trong XML | Part IV Developing with SQL Server Developing DDL Triggers The code in the trigger is normal T-SQL code. In some way a DDL trigger is easier to write than a DML trigger because DDL triggers always fire for a single event whereas DML triggers must handle events with multiple affected rows involving the base table and the inserted and deleted virtual tables. The complexity of the DDL trigger results from the fact that the data about the event is in XML. EventData DDL triggers can respond to so many different events that they need some method of capturing data about the event that caused them to fire. DML triggers have the inserted and deleted virtual tables DDL triggers have the EventData function. This function returns XML-formatted data about the event. The XML schema varies according to the type of event captured. Note that parts of the XML schema are case sensitive. Using the EventData function to populate an XML variable the trigger can use XQuery to investigate the values. Use the XQuery Value method to extract the data from the XML. The XML schema for event data is at C Program Files Microsoft SQL Server 100 Tools Binn schemas sqlserver 2006 11 events Alternatively the event schema is published at http sqlserver. The following code example creates a DDL trigger that reads EventData into an XML variable and then selects from the variable to display the data CREATE TRIGGER DDLTrigger ON DATABASE FOR CREATE_TABLE AS Set NoCount ON DECLARE @EventData XML EventDataC SELECT @ data EVENT_INSTANCE SchemaName 1 VARCHAR 50 as Schema @ data EVENT_INSTANCE ObjectName 1 VARCHAR 50 as Object @ data EVENT_INSTANCE EventType 1 VARCHAR 50 as EventType With the DDL triggers in place the next comamnd creates a table which fires the trigger which examines EventData s XML and returns the values to the client CREATE TABLE Test Col1 INT 662 DDL Triggers 27 Result Schema Object .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.