SQL Differences between stored procedure and triggers

前端 未结 13 1344
北荒
北荒 2021-01-30 20:38

I\'m having trouble understanding the difference between a stored procedure and a trigger in sql. If someone could be kind enough to explain it to me that would be great.

<
13条回答
  •  悲&欢浪女
    2021-01-30 21:19

    Some differences between triggers and procedures:

    1. We can execute a stored procedure whenever we want with the help of the exec command, but a trigger can only be executed whenever an event (insert, delete, and update) is fired on the table on which the trigger is defined.
    2. Stored procedure can take input parameters, but we can't pass parameters as input to a trigger.
    3. Stored procedures can return values but a trigger cannot return a value.
    4. We can use transaction statements like begin transaction, commit transaction, and rollback inside a stored procedure but we can't use transaction statements inside a trigger
    5. We can call a stored procedure from the front end (.asp files, .aspx files, .ascx files, etc.) but we can't call a trigger from these files.

提交回复
热议问题