Add special constraint to avoid duplicate rows with this condition?
You can create a filtered unique index with a WHERE clause.
CREATE UNIQUE NONCLUSTERED INDEX IX_[index name]_FloorNum_BedNum ON [myTable] (
FloorNum ASC,
BedNum ASC)
WHERE (IsActive = 1)
This will only take into account records where the IsActive
column is set to 1
.
Based on your description I think that ClientId
is not necessary in this example but if I am wrong you can add it to the index as well.