Stored Procedure & trigger

Source: Internet
Author: User

A trigger is executed when an event is triggered, and a stored procedure can be directly called by the stored procedure name. When performing operations such as update, insert, and delete on a table,
The SQL statements defined by the trigger are automatically executed to ensure that the data processing must comply with the rules defined by these SQL statements.

The trigger is mainly used to achieve complex integrity and data consistency that cannot be guaranteed by the primary key and foreign key. In addition, the trigger has many other functions:

(1) Enforce Restriction)

Triggers implement more complex constraints than check statements.

(2) Auditing changes)

Trigger can detect operations in the database, so that you cannot specify updates or changes in the database without permission.

(3) cascaded operation ).

 

Stored Procedure

1. The stored procedure is compiled only when it is created. You do not need to re-compile the stored procedure every time you execute it. Generally, the SQL statement is compiled every time it is executed. Therefore, the stored procedure is used.

It can speed up database execution.

2. When complex operations are performed on the database (for example, update, insert, query, and delete multiple tables), the complex operations can be encapsulated with the database using the stored procedure.

The provided transaction processing is used together.

3. stored procedures can be reused to reduce the workload of database developers.

4. High security. You can set that only a user has the right to use a specified stored procedure.

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.