SQL Differences between stored procedure and triggers

前端 未结 13 1328
北荒
北荒 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条回答
  •  -上瘾入骨i
    2021-01-30 21:33

    Both are database objects containing blocks lof code that can be used for implementing business logic

    The differences are:

    1) Triggers fire automatically but they need events for that. (Example: create,alter,drop,insert,delete,update) .

    2) Procedures have to be explicitly called and then executed. They do not need create,alter,drop,insert,delete,update. we can also execute procedures automatically using the sp_procoption.

    3) we cannot pass parameters inside the triggers,

    but we can pass parameters inside stored procedures

    example: if we want to display a message "error"

    using a trigger: we need some DDL/DML Statement using a procedure: NO DDL/DML is needed

提交回复
热议问题