1. Procedures :
A procedure is a combination of SQL statements written to perform a specified tasks. It helps in code re-usability and saves time and lines of code.
2. Triggers :
A trigger is a special kind of procedure which executes only when some triggering event such as INSERT, UPDATE, DELETE operations occurs in a table.
Difference between Triggers and Procedures :
|A Trigger is implicitly invoked whenever any event such as INSERT, DELETE, UPDATE occurs in a TABLE.||A Procedure is explicitly called by user/application using statements or commands such as exec, EXECUTE, or simply procedure_name|
|Only nesting of triggers can be achieved in a table. We cannot define/call a trigger inside another trigger.||We can define/call procedures inside another procedure.|
|In a database, syntax to define a trigger: CREATE TRIGGER TRIGGER_NAME||In a database, syntax to define a procedure: CREATE PROCEDURE PROCEDURE_NAME|
|Transaction statements such as COMMIT, ROLLBACK, SAVEPOINT are not allowed in triggers.||All transaction statements such as COMMIT, ROLLBACK are allowed in procedures.|
|Triggers are used to maintain referencial integrity by keeping a record of activities performed on the table.||Procedures are used to perform tasks defined or specified by the users.|
|We cannot return values in a trigger. Also, as an input, we cannot pass values as a parameter.||We can return 0 to n values. However, we can pass values as parameters.|
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between Cursor and Trigger in DBMS
- Difference between Function and Procedure
- Difference between 1NF and 2NF in DBMS
- Difference between 2NF and 3NF in DBMS
- Difference between DDL and DML in DBMS
- Difference between BCNF and 4NF in DBMS
- Difference between Database and DBMS
- Difference between 3NF and BCNF in DBMS
- Difference between RDBMS and DBMS
- Difference between Selection and Projection in DBMS
- Difference between Classification and Clustering in DBMS
- Difference between Generalization and Specialization in DBMS
- Difference between Schema and Instance in DBMS
- Difference between File System and DBMS
- Difference between Assertions and Triggers in DBMS
- Difference between OLAP and OLTP in DBMS
- Difference between Client /Server and Distributed DBMS
- jQuery | trigger() Method
- SQL Trigger | Student Database
- Main difference between Timestamp protocol and Thomos write rule in DBMS
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.