May 23, 2011 at 11:43 pm
Hi
Please tell me how can i create Unique Constraint on one column that allow multiple null values,
Thanks
Vineet
Thanks And Regards
Vineet Bhargava
vineetbhargav@gmail.com
May 24, 2011 at 1:44 am
Unique keys do not allow NULL values.As 'NULL' values cant be compared to check for uniqueness,the values of the unique column are considered to be equal.This means that a column defined as a unique key column can have only one NULL value.
---
Thinking is the hardest work there is, which is the probable reason so few engage in it.
Sunitha
😎
May 24, 2011 at 3:26 am
Thanks Sunitha
i know , But there must be some way to deal with it.
Regards
Vineet Bhargava
Thanks And Regards
Vineet Bhargava
vineetbhargav@gmail.com
May 24, 2011 at 3:34 am
you could wirte a trigger to do this, but i am not sure why you would want to,
also it is considered bad form to post the same question twice.
May 24, 2011 at 3:38 am
Use a filtered unique index.
Edit - quote captured wrong post.
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
May 24, 2011 at 3:49 am
Few possibilities
1) Use a unique constraint on a schemabound view
CREATE VIEW dbo.myView
WITH SCHEMABINDING AS
SELECT col
FROM myTable
WHERE col IS NOT NULL
GO
CREATE UNIQUE CLUSTERED INDEX IX ON dbo.myView (col);
2) Have a look at the 'nullbuster' method
3) Use a filtered index (SQL Server 2008 only)
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537May 24, 2011 at 3:49 am
But a filtered index is possible only in SQL 2008.
---
Thinking is the hardest work there is, which is the probable reason so few engage in it.
Sunitha
😎
May 24, 2011 at 4:05 am
A couple of possibilities here[/url].
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply