Đang chuẩn bị liên kết để tải về tài liệu:
Introducing Triggers

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Introducing Triggers A database trigger is a special kind of stored procedure that is run automatically by the database-or in trigger terms, fired-after a specified INSERT | Introducing Triggers A database trigger is a special kind of stored procedure that is run automatically by the database-or in trigger terms fired-after a specified INSERT UPDATE or DELETE statement is run against a specified database table. Triggers are very useful for doing things such as auditing changes made to column values in a table. A trigger can also fire instead of an INSERT UPDATE or DELETE. For example instead of performing an INSERT to add a row to the Products table a trigger could raise an error if a product with the same ProductID already existed in the table. As mentioned triggers are very useful for auditing changes made to column values. In this section you ll see an example of a trigger that will audit changes made to the Products table. Also when an UPDATE statement modifies the UnitPrice column of a row in the Products table a row will be added to the ProductAudit table. Finally when a DELETE statement removes a row from the Products table a row will be added to the ProductAudit table. Before you see the triggers you ll need to create the ProductAudit table. Listing 4.6 shows the ProductAudit.sql script that creates the ProductAudit table. Listing_4.6 PRODUCTAUDIT.SQL__ ProductAudit.sql creates a table that is used to store the results of triggers that audit modifications to the Products table USE Northwind CREATE TABLE ProductAudit ID int IDENTITY 1 1 PRIMARY KEY Action nvarchar 100 NOT NULL PerformedBy nvarchar 15 NOT NULL DEFAULT User TookPlace datetime NOT NULL DEFAULT GetDate The IDENTITY clause creates an identity for the ID primary key column of the ProductAudit table. An identity automatically generates values for a column. The identity for the ID column starts with the value 1 which is incremented by 1 after each INSERT. The Action column stores a string that records the action performed for example Product .

TÀI LIỆU 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.