Hello, SQL 2008 R2
Is it possible to have a constraint that allows NULL but not duplicate values? Sort of like a unique index but allowing multiple NULLs.
Thank you,
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
I encourage you to play around with this a bit before you implement in production!
With SQL2008R2, you can create a filtered unique constraint. All you need to do is filter out the nulls, like this...
Code:
CREATE UNIQUE NONCLUSTERED INDEX idx_YourIndexNameHere
ON YourTableNameHere(YourColumnNameHere)
WHERE YourColumnNameHere IS NOT NULL
-George
Microsoft SQL Server MVP My Blogs SQLCop twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.