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

Như 66 Chương,''quản trị giao dịch, khóa, và chặn,''thảo luận chi tiết hơn, mỗi lệnh DML ngầm xảy ra trong vòng một giao dịch, thậm chí nếu không có lệnh GIAO DỊCH BEGIN tồn tại. Việc kích hoạt sau khi diễn ra sau khi chỉnh sửa, nhưng trước khi cam kết ngầm, do đó, giao dịch vẫn mở khi kích hoạt sau khi được phát ra | Part II Manipulating Data with Select explicitly ROLLBACK the transaction the data-modification operation will go through as originally intended. Unlike INSTEAD OF triggers AFTER triggers normally report an error code if an operation is rolled back. As Chapter 66 Managing Transactions Locking and Blocking discusses in greater detail every DML command implicitly occurs within a transaction even if no BEGIN TRANSACTION command exists. The AFTER trigger takes place after the modification but before the implicit commit so the transaction is still open when the AFTER trigger is fired. Therefore a transaction ROLLBACK command in the trigger will roll back all pending transactions. This code sample creates the AfterDemo AFTER trigger on the Guide table which includes the RAISERROR and ROLLBACK TRANSACTION commands USE CHA2 CREATE TRIGGER AfterDemo ON Guide AFTER INSERT UPDATE AS Print After Trigger Demo -- logic in a real trigger would decide what to do here RAISERROR Sample Error 16 1 ROLLBACK TRAN With the AFTER trigger applied to the Guide table the following INSERT will result INSERT Guide lastName FirstName Qualifications DateOfBirth DateHire VALUES Harrison Nancy Pilot Sky Diver Hang Glider Emergency Paramedic 19690625 20000714 Result After Trigger Demo Server Msg 50000 Level 16 State 1 Procedure AfterDemo Line 7 Sample Error A SELECT searching for Nancy Harrison would find no such row because the AFTER trigger rolled back the transaction. Note that the sample code in the file for this chapter drops the AfterDemo trigger so that the code in the remainder of the chapter will function. Non-Updateable Views Non-updateable views may affect INSERT UPDATE and DELETE operations. Several factors will cause a view to become non-updateable. The most common causes of non-updateable views are aggregate functions including DISTINCT group bys and joins. If the view 392 Modification Obstacles 16 includes other nested views any nested view that is .