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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger for delete record and copy to table

Status
Not open for further replies.

firsttube

Technical User
Apr 21, 2004
165
CA
I need to write a trigger that will do the following:

Delete a record and copy it into another table (exact same structure), when the "Status" field of that record is updated to "A".

I'm new to triggers and would be grateful for an example, if this is even possible.

thanks
ft


Information is not Knowledge, Knowledge is not Wisdom, Wisdom is not Truth, Truth is not Beauty, Beauty is not Love, Love is not Music, Music is the best.
 
Not 100% sure about this but you may have trouble doing what you want due to "mutating tables".

Whilst the trigger is firing you want it to insert into another table and delete the record that has just been updated.

If this is the case a trigger (I think may hold a lock on the row that is being updated causing the delete of that row to hang.

Depending on why you need to do what you want and probably lods of application needs will deterime how else to handle this.

If allowable I would write the new record to a new table with a trigger and have a trigger on the other table to delete the row from the first table.

Just my observations.

[bandito] [blue]DBomrrsm[/blue] [bandito]

[blue]Software code, like laws and sausages, should never be examined in production[/blue][black] - [/black][purple]Edward Tenner[/purple]
 
Since the record is already marked with 'A', why would you need to move it to another table?

Select * From YourTable Where Status <> 'A'

will return only the valid records. Changing the operator to '=' will return the archived records...

Plus, having them in the same table will ease time-specific statistics.

Just a thought.


[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top