Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Unique Constraint with exceptions

Author  Topic 

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2010-05-06 : 13:41:58
Is it possible to create a table constraint that would allow

Unique or null or 'none'

on a column

The Nulls and the 'none' would need to allow multiples.



Jim
Users <> Logic

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-06 : 13:48:50
1. you need to create check constraint for that

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dportas
Yak Posting Veteran

53 Posts

Posted - 2010-05-06 : 14:35:03
Normalize it. Move the column into a new table and put the unique constraint on that. For the null or "none" rows you just don't have a row in that new table. That's assuming "none" means the same as null - if it means something else then create a new column for it.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-06 : 14:40:38
I agree with dportas. That's how we handle the situation where I work.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -