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.