tailieunhanh - Types of Triggers

Sau khi kích hoạt được thực hiện sau khi các hành động của INSERT, UPDATE, hoặc DELETE tuyên bố được thực hiện. Quy định cụ thể sau khi là tương tự như quy định cụ thể CHO, đó là lựa chọn duy nhất có sẵn trong các phiên bản trước đó của SQL Server. Sau khi kích hoạt có thể chỉ được xác định trên bàn. | Types of Triggers AFTER Triggers After triggers are executed after the action of the INSERT UPDATE or DELETE statement is performed. Specifying AFTER is the same as specifying FOR which is the only option available in earlier versions of SQL Server. AFTER triggers can be specified only on tables. INSTEAD OF Triggers INSTEAD OF triggers are executed in place of the usual triggering action. INSTEAD OF triggers can also be defined on views with one or more base tables where they can extend the types of updates a view can support. INSTEAD OF triggers give you the ability to evaluate the changes that would have taken place if the data modification statement had actually executed. Like AFTER triggers each INSTEAD OF trigger gives you access to two virtual tables called Inserted and Deleted. For a DELETE trigger the virtual table Deleted holds all the deleted rows and for an INSERT trigger the virtual table Inserted holds all the new rows. For INSTEAD OF triggers the Deleted table holds the rows that would have been deleted and the Inserted table holds the rows that would have been inserted had the modification taken place. An UPDATE trigger populates both the Inserted and Deleted tables the Deleted table stores the old version of the rows and the Inserted table stores the new version. With all triggers the Inserted and Deleted tables change their structure to reflect the columns and data types of the table the trigger is attached to. For example if you have a trigger on the Titles table in the Pubs database the Inserted and Deleted tables will have the same columns as the Titles table with the same names and data types. Table compares an INSTEAD OF trigger with an AFTER trigger. Following is a simple example. Suppose you want to make sure that when someone updates any prices in the Titles table in the Pubs database the change is no more than 10 percent of the original price. You need to look at both the old price value and the new value to see whether the change is

TỪ KHÓA LIÊN QUAN