Given a column with bit type in SQL Server 2008, how can I write a trigger to allow updates from 0 to 1, but disallow updating from 1 to 0?
In other words, once the bit is set to 1, it should always be 1.
The trigger must work for multiple updates, e.g. :
UPDATE Table SET BitField = 0
Should fail for any row where BitField = 1.
EDIT: To give some background, the bit/flag in question marks whether or not a monetary transaction needs to be processed. If the bit =1, the transaction has already been processed. If the bit is reset to 0, the transaction may be duplicated, so I need to enforce at the database level that the bit can not be reset to 0.
I need to protect against direct queries run against the database as well as application level bugs. I can’t be sure that a stored procedure will always be used to update the table, so I believe a trigger is the only way to enforce this logic.
Looks like you are in need of a simple after trigger