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.|
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Difference between Cursor and Trigger in DBMS
- Difference between Function and Procedure
- Difference between 2NF and 3NF in DBMS
- Difference between 1NF and 2NF in DBMS
- Difference between DDL and DML in DBMS
- Difference between RDBMS and DBMS
- Difference between 3NF and BCNF in DBMS
- Difference between Database and DBMS
- Difference between Generalization and Specialization in DBMS
- Difference between Classification and Clustering in DBMS
- Difference between Schema and Instance in DBMS
- Difference between File System and DBMS
- Difference between Selection and Projection in DBMS
- Difference between OLAP and OLTP in DBMS
- SQL Trigger | Student Database
- jQuery | trigger() Method
- SQL Trigger | Book Management Database
- Main difference between Timestamp protocol and Thomos write rule in DBMS
- Check if Table, View, Trigger, etc present in Oracle
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.