Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Differences between stored procedure and triggers

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

like image 749
Dynamiite Avatar asked May 18 '13 20:05

Dynamiite


People also ask

What is the difference between triggers and stored procedures?

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.

What is the difference between procedure and trigger in SQL?

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.

What is difference between procedure and function and trigger?

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 a trigger and stored procedure What are the system tables that can be accessed in a trigger?

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.


1 Answers

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.

like image 166
Bohemian Avatar answered Oct 04 '22 08:10

Bohemian