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

  • SEARCH
  • Home
  • 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 1099071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:40:38+00:00 2026-05-17T00:40:38+00:00

I have column in a table that allow null but i want to make

  • 0

I have column in a table that allow null but i want to make constraint that make him null or unique … How can i do that ?
Note : I validate it from the frontend but i want to have a physical in sql server that allow this even developer try to enter data

  • 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-05-17T00:40:38+00:00Added an answer on May 17, 2026 at 12:40 am

    An alternative to a filtered index that works on SQL Server 2000 and later is an indexed view.

    Something like:

    CREATE VIEW DRI_YourTable_NonNullUnique
    WITH SCHEMABINDING
    AS
        SELECT YourColumn FROM dbo.YourTable WHERE not YourColumn is NULL
    GO
    CREATE UNIQUE CLUSTERED INDEX IX_DRI_YourTable on DRI_YourTable_NonNullUnique (YourColumn)
    

    Note that you don’t have to do anything special once this view is created – you need never refer to it again. It will simply cause constraint violations to occur, if there is an attempt to insert non-unique values in the base table.

    @marc_s – I beg to differ. They’re certainly not considered automatically (in query compilation) in editions below Enterprise, but they’re definitely creatable, and work as DRI enforcers in all editions:

    select @@VERSION
    
    create table dbo.T1 (
        T1ID int IDENTITY(1,1) not null,
        Val1 varchar(10) null,
        constraint PK_T1 PRIMARY KEY (T1ID)
    )
    go
    create view dbo.DRI_T1_Val1Unique
    with schemabinding
    as
        select Val1 from dbo.T1 where Val1 is not null
    go
    create unique clustered index IX_DRI_T1_Val1Unique on dbo.DRI_T1_Val1Unique (Val1)
    go
    insert into dbo.T1 (Val1)
    select 'abc' union all
    select null union all
    select null
    go
    insert into dbo.T1 (Val1)
    select 'abc'
    go
    select * from dbo.T1
    

    Results:

    Microsoft SQL Server  2000 - 8.00.2039 (Intel X86)   May  3 2005 23:18:38   Copyright (c) 1988-2003 Microsoft Corporation  Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 2) 
    
    1   abc
    2   NULL
    3   NULL
    

    And:

    (1 row(s) affected)
    
    (3 row(s) affected)
    Msg 2601, Level 14, State 3, Line 1
    Cannot insert duplicate key row in object 'DRI_T1_Val1Unique' with unique index 'IX_DRI_T1_Val1Unique'.
    The statement has been terminated.
    
    (0 row(s) affected)
    
    (3 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with several columns that allow NULLs. How would I go
I have a table that contains a nvarchar column that allows nulls. I have
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID]
I have a view like this: CREATE VIEW MyView AS SELECT Column FROM Table
We have a table that needs to be locked down in a specific way
I have the following MySql syntax to create a table with constraint to check
I'm working on a webapp with a set of data that users can browse
I have stored procedure that returns results sorted dynamically. The parent folder (this is
I'm looking for a jQuery plugin that will allow me to drag items across

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.