Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi table Triggers SQL Server noob

I have a load of tables all with the same 2 datetime columns (lastModDate, dateAdded). I am wondering if I can set up global Insert Update trigger for these tables to set the datetime values. Or if not, what approaches are there?

Any pointers much appreciated

like image 932
Chin Avatar asked Feb 27 '23 05:02

Chin


2 Answers

I agree there is no such Global Trigger, but we can certainly reduce our efforts by creating script which will generate triggers for the tables.

Something like: http://weblogs.sqlteam.com/brettk/archive/2006/11/29/35816.aspx

like image 78
Nitin Midha Avatar answered Apr 27 '23 05:04

Nitin Midha


No, there's no such thing as a "global" trigger or a multi-table triggers. Triggers are by design bound to a table, so if you need to have triggers on a load of tables, you need to create a load of triggers, one for each table, and deploy them. No way around that, I'm afraid.

like image 30
marc_s Avatar answered Apr 27 '23 05:04

marc_s