A trigger in SQL is a sequence of actions which results in a change in the table of a database. It is activated when the contents of the table of a database are modified.
CREATE TRIGGER NORDER
INSERT ON ORDERS
AFTER (EXECUTE PROCEDURE N_ORDER)
The above query creates a trigger name NORDER.
Advantages of trigger:
1) Triggers can be used as an alternative method for implementing referential integrity constraints.
2) By using triggers, business rules and transactions are easy to store in database and can be used consistently even if there are future updates to the database.
3) It controls on which updates are allowed in a database.
4) When a change happens in a database a trigger can adjust the change to the entire database.
5) Triggers are used for calling stored procedures.
Disadvantages of trigger:
1) Programmers don’t have full control: Since business rules are hidden, programmers don’t have full control over the database. BY this, a program can generate several actions.
2) Increase in complexity: Triggers increase the complexity of a database as they have hard coded rules already implemented.
3) Decrease in performance of the database: By the complex nature of the database programs take more time to execute and there can be hidden performance downtimes.