sql server - Using triggers to alter inserted/updated data to enforce a business rule -


I have just created a trigger that is created for a time field from the date field (insert, after updating ). I thought it would be easy to implement a trigger compared to fixing it in the application to insert / update the table. For the latter updates will include re-compiling out of the app, and kicking people

but I'm not sure if I'm being lazy or clever, honestly.

  create TRIGGER [dbo]. [StripCastDateTime] running [dbo]. [PileInventory] After INSERT, the update started as - Added to prevent additional result set on SET NOCOUNT - Interference with SELECT statement. Set nosenate on; Update PileInventory set CastDate = cast (convert (varchar (11), Inserted.CastDate, 101) as inserted date [insert] from within [dbo] from within [PI] on PI as [PileInventory]. [JobNumber] = INSERTED.JobNumber and [PI]. [MarkNumber] = INSERTED.MarkNumber is not Inserted.CastDate is zero end GO  

This works perfectly, but is it the proper use of triggers?

Thank you.

Marshall

"itemprop =" lesson ">

After updating your updated tables, it hurt Your db I will use the trigger "inside INSERT" to change the data and then put it. There is no point in doing this after it is in DB

Other then it is a valid use of the trigger.

Read more here: ..


Comments