I have the following table in SQL Server
Create Table Banners
(
BannerID int Identity(1,1),
BannerUrl nvarchar(500),
BannerIsDomestic bit,
BannerName nvarchar(50),
CreationDate datetime,
ModificationDate datetime,
Show_Status bit,
Remark nvarchar(500)
Constraint Banner_ID_PK Primary Key (BannerID)
)
In this I want to apply a customize constraint like, at one time only two rows can have Show_Status to be true. One with BannerIsDomestic = true and one with BannerIsDomestic = false.
For all the rows that have BannerIsDomestic = true only one can have Show_Status = True and all other must be false.
And for all the rows that have BannerIsDomestic = false only one can have Show_Status = True, all others must be false.
Can I do this in SQL Server?
If I am understanding the requirements correctly, this should be achievable with filtered indexes: