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
 Indexes - Unique if not null?

Author  Topic 

willworkforfoodjnr
Starting Member

2 Posts

Posted - 2007-07-19 : 03:04:30
Hi everyone

I have a varchar column which may, or may not, contain a userID value. I want some way of saying "If the column has a value, it must be unique" But I can't find any way of doing it without SQL complaining about duplicate null values. Is there a way of doing this?

Thanks!

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-19 : 05:31:14
http://weblogs.sqlteam.com/mladenp/archive/2007/05/17/60209.aspx

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-19 : 06:06:50
quote:
Originally posted by spirit1

http://weblogs.sqlteam.com/mladenp/archive/2007/05/17/60209.aspx

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp


The page is not displayed

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

willworkforfoodjnr
Starting Member

2 Posts

Posted - 2007-07-19 : 06:13:01
Fast reply, and it works great, thanks!
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-19 : 06:16:43
> The page is not displayed

works fine for me... can you se it if you refresh?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-19 : 07:05:55
quote:
Originally posted by spirit1

> The page is not displayed

works fine for me... can you se it if you refresh?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp


Yes it works. It seems internet problem

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-07-23 : 13:23:07
"Fast reply, and it works great, thanks!"

We used to use this solution but got fed up with the requirements for ANSI flag settings etc.

Now we use a Trigger to enforce uniqueness on non-NULL values in a column.

Kristen
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-07-23 : 14:23:14
Or

http://weblogs.sqlteam.com/brettk/archive/2005/04/20/4592.aspx



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-07-24 : 03:23:45
For completeness see also:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Can't+insert+NULL+into+table+with+unique+key
Go to Top of Page
   

- Advertisement -