Database notes (2)

Source: Internet
Author: User

The trigger cannot be called using the EXEC command, but is activated when the user executes the Transact-SQL statement. Data Operation Language (DML) trigger in

Run INSERT, UPDATE, and (or) DELETE statements. SQL Server can prevent data modifications that do not comply with strict requirements, because SQL Server

Treat the trigger as a transaction. As the trigger is treated as a transaction, you only need to add a ROLLBACK command to the corresponding position of the Code.

To prevent records from going through the trigger. The ROLLBACK Command forces the database server to stop processing modifications and disallow the current transaction.

Forget that this transaction has occurred. In this sense, the trigger can be understood as a database watchdog.

The INSERT trigger can be used to modify, reject or even accept the records being inserted, or even cascade the operation of modifying other tables in the database.

. When an INSERT statement is used to create a new record in a table, the INSERT trigger is triggered. Once you try to insert

For the new record, SQL Server copies the new record to a table (trigger table) in the database and a special table (insert

Table), the new record exists in both tables: trigger table and insert Table. The records in the inserted Table should be exactly the records in the trigger table.

Same. When you need to cascade the modification results to other tables in the entire database, inserting a table is a very important table.

The DELETE trigger is used to restrict data that can be deleted from the database. After the DELETE trigger is added, SQL Server will be deleted

Records are transferred to a logical table (delete table) in the memory. Therefore, records are not completely removed and can still be referenced in code. This type

It is similar to the recycle bin, but the table to be deleted is automatically cleared after the transaction ends. the recycle bin needs to be cleared manually.

The UPDATE trigger is used to constrain the UPDATE statement published by the user. This type of trigger is used to restrict existing data that can be modified by users.

The UPDATE trigger combines the INSERT and DELETE triggers. If update is used to check the occurrence of a Single Column

. If update can be used not only in the UPDATE trigger, but also in the INSERT trigger.

Use the if update statement, because the DELETE statement does not modify the specific column.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.