Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9041301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:12:33+00:00 2026-06-16T10:12:33+00:00

I have the following table in SQL Server Create Table Banners ( BannerID int

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T10:12:35+00:00Added an answer on June 16, 2026 at 10:12 am

    If I am understanding the requirements correctly, this should be achievable with filtered indexes:

    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)
        )
    
    CREATE UNIQUE NONCLUSTERED INDEX IX_Banners_IsDomesticTrue 
    ON Banners (BannerIsDomestic) WHERE Show_Status = 1 
    
    INSERT Banners (BannerIsDomestic, BannerName, Show_Status) 
    VALUES (1, 'DomesticBannerShow', 1), (1, 'DomesticBannerHide', 0), 
    (0, 'ItnlBannerShow', 1), (0, 'IntlBannerHide', 0) 
    
    -- This will fail
    INSERT Banners (BannerIsDomestic, BannerName, Show_Status) 
    VALUES (1, 'DomesticBanner2', 1)
    
    -- This will fail
    INSERT Banners (BannerIsDomestic, BannerName, Show_Status)  
    VALUES (0, 'IntlBanners2', 1) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table in SQL Server: CREATE TABLE [dbo].[Users]( [Id] [int] IDENTITY(1,1)
In SQL Server 2008, I have the following tables: CREATE TABLE samples (SampleID int,
I have the following table in SQL Server 2008: CREATE TABLE tbl (ID INT,
In MICROSOFT SQL SERVER have the following table: CREATE TABLE [T1] ( [ID] int
I have the following SQL Server stored procedure : BEGIN TRAN CREATE TABLE #TempTable
Say, I have the following SQL Server 2008 table with data: CREATE TABLE tbl
I have a following table in SQL Server 2008 database: CREATE TABLE [dbo].[Actions]( [ActionId]
I have the following SQL Server stored procedure: CREATE PROCEDURE ispsDcOhcAgg @TmpTableName NVARCHAR(50), @ListItem
I have the following very large table in SQL Server 2005: create table Blah
I have a SQL Server table with the following structure: CREATE TABLE [dbo].[Log]( [LogID]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.