SQL Differences between stored procedure and triggers

Dynamiite picture Dynamiite · May 18, 2013 · Viewed 88.2k times · Source

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

Answer

Bohemian picture Bohemian · May 18, 2013

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.