Skip to content
Advertisement

Check constraint to prevent 2 or more rows from having numeric value of 1

I have a SQL table with a column called [applied], only one row from all rows can be applied ( have the value of 1) all other rows should have the value 0

Is there a check constraint that i can write to force such a case?

Advertisement

Answer

Most databases support filtered indexes:

create unique index unq_t_applied on t(applied) where applied = 1;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement