Jose Saiz

Jose Saiz

  • 1.4k
  • 243
  • 98.7k

Trigger for DELETE

Oct 10 2017 9:05 PM
Hi Guys
I am looking for sample Trigger when deleting a row 
 
For Instance (MS-SQL 2008/2012)
I have a shopping cart that has a customer table with Indentity Column on CustomerId datatype integer, Order table etc.
I would like that if any tech support people or my self that query the table customer via the Query Analyzer and by mistake use the statement DELETE or TRUNCATE
that the trigger either Rolls back the transaction or do not accept the deletion.
 
The reason for the trigger is because I've noticed that I have lots old orders that became orpham because the customer was deleted, and it is too late to implement the foreign key which helps in this case because it does not allow you to delete the customer that is tied to another table with rows.
 
Thanks

Answers (2)