Trigger to keep a single record form a table to a certain status
715410Aug 3 2009 — edited Aug 4 2009Hi all.
I have a table which has a "Status" field. I'm trying to accomplish, with a trigger, that the table can only have one record with an "Active" status, so whenever and Insert or Update occurs, if the new value for the "Status" field is "Active", I should update all other records in the table to "Inactive". I've tried several approaches, and managed to make it work on Inserts, but any Updates wll give an error that says that the table is mutating. I've tried to do it on before and after trigger types, without success.
Is there a way to do what I want with a trigger, or do necessarily I have to create an SP that needs to be called before the Insert or Update operation?