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.
Thanks in advance
A trigger is a procedure that is invoked automatically when certain database events occur. A stored procedure is a procedure that is explicitly invoked by a client application, another stored procedure, or a trigger procedure.
Difference between Triggers and Procedures:A Trigger is implicitly invoked whenever any event such as INSERT, DELETE, or UPDATE occurs in a TABLE. 2. When an event occurs, a trigger helps to execute an action automatically. A procedure helps to perform a specified task when it is invoked.
Procedures doesn't return any values their just get parameters and do something with them, functions does the same by their also can return you a value based on their work. Triggers are kind of event handlers that react on any action you want and start procedure when this action happens.
What is the difference between Triggers and Stored Procedure? Stored Procedures are called by the programmer wherever it wants to fire but triggers fired automatically when insert,delete,update occured. And triggers can be implemented to tables & views only where as stored procedure used in the database independently.
A stored procedure is a user defined piece of code written in the local version of PL/SQL, which may return a value (making it a function) that is invoked by calling it explicitly.
A trigger is a stored procedure that runs automatically when various events happen (eg update, insert, delete).
IMHO stored procedures are to be avoided unless absolutely required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With