Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have two different insert triggers on the same table?

They seem to be allowed as I can see both my insert triggers listed under the table with different names. Is it common or a bad practice? I am using SQL Server 2005

like image 250
Hammad Khan Avatar asked Oct 19 '11 20:10

Hammad Khan


People also ask

Can we have multiple triggers in the same table?

You can create multiple triggers for the same subject table, event, and activation time. The order in which those triggers are activated is the order in which the triggers were created. Db2 records the timestamp when each CREATE TRIGGER statement executes.

Can we have multiple triggers in the same table in Oracle?

Oracle allows more than one trigger to be created for the same timing point, but it has never guaranteed the execution order of those triggers.

How many triggers can be created on a table?

There is no limit. You can have as many triggers for the same event on a table.

How many triggers are allowed in MySQL table?

There are 6 different types of triggers in MySQL: 1. Before Update Trigger: As the name implies, it is a trigger which enacts before an update is invoked.


1 Answers

Yes, you can definitely have more than one trigger for each operation, e.g. AFTER INSERT or AFTER UPDATE etc. It does make sense to split up separate concerns into separate, small, manageable chunks of code.

The one thing you cannot rely on is that they'll be executed in a certain order - the order in which the triggers are indeed executed also doesn't have to be stable, i.e. the same every time around.

like image 133
marc_s Avatar answered Oct 06 '22 22:10

marc_s