TAILIEUCHUNG - Microsoft SQL Server 2008 R2 Unleashed- P105

Microsoft SQL Server 2008 R2 Unleashed- P105:SQL Server 2005 provided a number of significant new features and enhancements over what was available in SQL Server 2000. This is not too surprising considering there was a five-year gap between these major SQL Server 2008 is not as much of a quantum leap forward from SQL Server 2005 | 984 CHAPTER 30 Creating and Managing Triggers This type of trigger is useful for controlling development and production database environments. It goes beyond the normal security measures and helps manage unwanted change. For development environments this type of trigger enables the database administrator to lock down an environment and focus all changes through that person. The previous examples include events scoped at the database level. Let s look at an example that applies to server-level events. The script in Listing creates a trigger scoped at the server level. It prevents changes to the server logins. When this trigger is installed it displays a message and rolls back any login changes that are attempted. LISTING A Server-Scoped DDL Trigger for Logins CREATE TRIGGER tr_LoginAudit ON ALL SERVER FOR CREATE_LOGIN ALTER_LOGIN DROP_LOGIN AS PRINT You must disable the tr_LoginAudit trigger before making login changes ROLLBACK The DDL trigger examples we have looked at thus far have targeted specific events listed in Table . These individual events can also be referenced via an event group. Event groups are hierarchical in nature and can be referenced in DDL triggers instead of the individual events. For example the table-level trigger from Listing can be changed as shown in Listing to accomplish the same result. In Listing the DDL_TABLE_EVENTS group reference replaces the individual event references to CREATE_TABLE ALTER_TABLE and DROP_TABLE. LISTING An Example of a DDL Trigger Referencing an Event Group USE BigPubs2008 IF EXISTS SELECT FROM WHERE name N tr_TableAudit AND parent_class 0 DROP TRIGGER tr_TableAudit ON DATABASE go CREATE TRIGGER tr_TableAudit ON DATABASE FOR DDL_TABLE_EVENTS AS PRINT You must disable the TableAudit trigger in order to change any table in this database ROLLBACK GO Download from Using DDL Triggers 985 SQL Server Books Online has an excellent diagram listing all the .

TỪ KHÓA LIÊN QUAN
Đã 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.