tailieunhanh - Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .Net - P4

Tham khảo tài liệu 'programming microsoft sql server 2000 with microsoft visual basic .net - p4', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | a disabled trigger all you have to do is enable it. Recall that you can disable and enable a trigger with an ALTER TABLE statement for the table with the trigger that you want to disable temporarily. The following script demonstrates the syntax for creating a trigger for the MyTable table created earlier in this chapter. See the Creating a Scalar UDF Without Parameters section. The trigger protects the table from inserts updates and deletes by rolling back the transaction associated with the trigger. The script starts by removing any previous version of the trgKeepMyTableUntouched trigger and then begins a CREATE TRIGGER statement. Like most other CREATE statements the CREATE TRIGGER statement must occu r at the top of a batch. Therefore the code to drop the old version ends with the GO keyword. The ON clause of the CREATE TRIGGER statement designates the MyTable table as the one to which the trigger will belong. The FOR clause indicates that the trigger will fire for insert update and delete events. The first statement after the AS keyword is a RAISERROR statement that sends a custom message back to the Messages pane of Query Analyzer. An informational message issued from a trigger is useful for letting a user know that a trigger fired. The RAISERROR statement can serve other functions as well but it is a robust alternative to the PRINT statement for sending messages to the Messages pane. The string for a custom message can be up to 400 characters. The trailing values 16 and 1 indicate the severity and state for the error. For simple informational messages you can consistently apply these values. The second T-SQL statement in the script rolls back the transaction to modify the table. The ROLLBACK TRAN statement is an abbreviated version of the ROLLBACK TRANSACTION statement. In either form this statement removes any inserted rows restores any column values to their nonupdated state and adds back any deleted rows. You will generally want to use the ROLLBACK TRAN .

TỪ KHÓA LIÊN QUAN