TAILIEUCHUNG - Introducing Triggers

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 shows the script that creates the ProductAudit table. 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 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.