Hi,USE tempdbCREATE TABLE UniqueColumnTable(pk int IDENTITY,fk int,selected bit)INSERT UniqueColumnTable (fk, selected) VALUES (1, 0)INSERT UniqueColumnTable (fk, selected) VALUES (1, 1)INSERT UniqueColumnTable (fk, selected) VALUES (2, 0)INSERT UniqueColumnTable (fk, selected) VALUES (2, 1)INSERT UniqueColumnTable (fk, selected) VALUES (2, 0)UPDATE UniqueColumnTable SET selected = 1 WHERE pk = 5SELECT * FROM UniqueColumnTableDROP TABLE UniqueColumnTable
I want the 'update' in the above code to fail. Basically, it must be impossible for any group of rows with the same 'fk' value for more than one row within the group to have 'selected' equal to 1. A group of rows which share the same 'fk' value doesn't have to have a row with 'selected' equal to 1 - just that, if there is, it must be the only one.How can I have the database enforce this, in particular, during concurrent updates?Cheers,XFactor