Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

msSql Trigger question (insert and update together)

Status
Not open for further replies.

darwin101

Programmer
Mar 7, 2001
156
US
Hi all

Is it possiable to write one trigger that handles inserts and updates ?
my table has has 2 fields, Id and Description. When a new record is inserted my trigger does an insert of this record into table B. That works fine.

When a record in table A is updated I want the trigger to update the same record in table B.

I can write 2 triggers to do this but I was wondering if they could be combined and/or what is best practice?

I have not been able to find examples on this in my books or BOL. Did I miss something..

much thanks
 
> Is it possiable to write one trigger that handles inserts and updates ?

Yes. Simply create trigger FOR INSERT, UPDATE and then merge logic from two existing triggers into signle one. You can easily determine action (INSERT or UPDATE) by checking inserted/deleted tables.

Is it worth it? I'd say yes - triggers can be ugly, 2-3 small triggers are even uglier.

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top