I have MS SQL Server database and insert some values to one of the tables.
Let's say that the table contains columns ID
, int Status
and text Text
.
If possible, I would like to create a trigger which prevents from writing specific incorrect status (say 1
) to the table. Instead, 0
should be written. However, other columns should be preserved when inserting new values:
If the new row written is (1, 4, "some text"
), it is written as is.
If the new row written is (1, 1, "another text"
), it is written as (1, 0, "another text"
)
Is it possible to create such trigger? How?
EDIT: I need to allow writing such record even if status column is invalid, so foreign keys will not work for me.