Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Article Discussions
»
Article Discussions by Author
»
Discuss content posted by Gopi Sri
»
UNIQUE constraint
65 posts, Page 2 of 7
««
1
2
3
4
5
»
»»
UNIQUE constraint
Rate Topic
Display Mode
Topic Options
Author
Message
dawryn
dawryn
Posted Thursday, December 20, 2012 12:33 AM
SSCommitted
Group: General Forum Members
Last Login: Yesterday @ 4:12 AM
Points: 1,963,
Visits: 585
Got it wrong for the same reason. I thought about unique filtered indexes but that is not the same as unique constraints which allow one null only.
Post #1398826
SQLRNNR
SQLRNNR
Posted Thursday, December 20, 2012 12:35 AM
SSCoach
Group: General Forum Members
Last Login: Today @ 5:03 PM
Points: 18,853,
Visits: 12,438
Stewart "Arturius" Campbell (12/20/2012)
IMHO, I think the correct answer here will be "It depends".
It depends on whether filtered indexes are utilised or not, etc.
However, it could be that the PO intended that the use of filtered index(es) is implied (or should be assumed)...
I disagree that "It depends" with this question. It was asked if it was simply possible. No need to consider filtered indexes, you just need to know if there is any possible way to insert multiple nulls into a unique constraint - imho.
Jason
AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1398827
Koen Verbeeck
Koen Verbeeck
Posted Thursday, December 20, 2012 12:38 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 6:30 AM
Points: 9,410,
Visits: 6,495
SQLRNNR (12/20/2012)
Stewart "Arturius" Campbell (12/20/2012)
IMHO, I think the correct answer here will be "It depends".
It depends on whether filtered indexes are utilised or not, etc.
However, it could be that the PO intended that the use of filtered index(es) is implied (or should be assumed)...
I disagree that "It depends" with this question. It was asked if it was simply possible. No need to consider filtered indexes, you just need to know if there is any possible way to insert multiple nulls into a unique constraint - imho.
A unique constraint is not the same as a unique index.
Anyway, your explanation of a constraint over multiple columns demonstrates that the question has the correct answer (albeit a little tricky
), but just an incorrect explanation.
How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
Member of
LinkedIn
. My blog at
LessThanDot
.
MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1398828
Gopi S
Gopi S
Posted Thursday, December 20, 2012 12:41 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Sunday, June 02, 2013 3:31 AM
Points: 151,
Visits: 278
Hello,
"
Data Integrity
" can be enforced in sql server through
PRIMARY KEY Constraint
FOREIGN KEY Constraint
UNIQUE Constraint
CHECK Constraint
Default Definition
so on..
My point here is all about enforcing "Unique Constraint".
This can be done in several ways.
Query 1. Add Unique Constraint
ALTER TABLE dbo.<tablename> ADD CONSTRAINT
<constraint_name> UNIQUE NONCLUSTERED
(
<columnname>
) ON [PRIMARY]
Query 2. Add Unique Index
CREATE UNIQUE NONCLUSTERED INDEX
<index_name> ON dbo.<tablename>
(
<columnname>
) ON [PRIMARY]
Technically there is no difference between Unique Index and Unique Constraint. Even though syntax are different the effect is the same.
Unique Constraint creates Unique Index to maintain the constraint to prevent duplicate keys. Unique Index also creates index that are physical structure that maintain uniqueness. It is a convenient way to enforce a Unique Constraint for SQL Server.
In above case "Unique Constraint" allows one "NULL".
But my question was how the above Unique Constraint can be created but allowing multiple NULL values and not the RULES of Unique constraint.
I just want to bring that
it is possible to enforce Uniqueness
in a column but allowing multiple "NULL" values and one of the way to implement this is using filtered index.
Ref: http://blog.sqlauthority.com/2007/04/26/sql-server-difference-between-unique-index-vs-unique-constraint/
http://social.msdn.microsoft.com/Forums/en/transactsql/thread/a298b63b-e1eb-4b31-a2d7-64e1fe493b0a
Thanks
Gopi
Post #1398830
Lokesh Vij
Lokesh Vij
Posted Thursday, December 20, 2012 12:41 AM
Ten Centuries
Group: General Forum Members
Last Login: Today @ 2:21 AM
Points: 1,228,
Visits: 1,358
SQLRNNR (12/20/2012)
Stewart "Arturius" Campbell (12/20/2012)
IMHO, I think the correct answer here will be "It depends".
It depends on whether filtered indexes are utilised or not, etc.
However, it could be that the PO intended that the use of filtered index(es) is implied (or should be assumed)...
I disagree that "It depends" with this question. It was asked if it was simply possible. No need to consider filtered indexes, you just need to know if there is any possible way to insert multiple nulls into a unique constraint - imho.
Let us all "Agree" to "Disagree" and come to a point that today's Question has a take-away on Filter Index
~ Lokesh Vij
Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions
Link to my Blog Post -->
www.SQLPathy.com
Follow me
@Twitter
Post #1398831
dawryn
dawryn
Posted Thursday, December 20, 2012 12:41 AM
SSCommitted
Group: General Forum Members
Last Login: Yesterday @ 4:12 AM
Points: 1,963,
Visits: 585
SQLRNNR (12/20/2012)
I don't disagree with the correct answer. I disagree with the explanation. I also do disagree with many of the complaints thus far about the question. You can most certainly have multiple null values in a unique constraint. Don't constrain yourselves to a narrow scope of a constraint on a single column - where you can have only one null value.
ALTER TABLE sometest
ADD CONSTRAINT someconstraint UNIQUE (testid,col1,col2);
Disagree!
This constraint can not represent value of Null even if all columns are populated with Nulls.
Besides, only one occurrence of Nulls in all columns is allowed.
Post #1398832
SQLRNNR
SQLRNNR
Posted Thursday, December 20, 2012 12:47 AM
SSCoach
Group: General Forum Members
Last Login: Today @ 5:03 PM
Points: 18,853,
Visits: 12,438
dawryn (12/20/2012)
SQLRNNR (12/20/2012)
I don't disagree with the correct answer. I disagree with the explanation. I also do disagree with many of the complaints thus far about the question. You can most certainly have multiple null values in a unique constraint. Don't constrain yourselves to a narrow scope of a constraint on a single column - where you can have only one null value.
...
Besides, only one occurrence of Nulls in all fields is allowed.
True only one occurence of null in all fields is allowed. But that is not the question. The question was simply if multiple nulls could be inserted.
Jason
AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #1398833
Gopi S
Gopi S
Posted Thursday, December 20, 2012 12:50 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Sunday, June 02, 2013 3:31 AM
Points: 151,
Visits: 278
So far Jason is following me
Post #1398835
Koen Verbeeck
Koen Verbeeck
Posted Thursday, December 20, 2012 12:51 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 6:30 AM
Points: 9,410,
Visits: 6,495
Gopi S (12/20/2012)
Technically there is no difference between Unique Index and Unique Constraint. Even though syntax are different the effect is the same.
Unique Constraint creates Unique Index to maintain the constraint to prevent duplicate keys. Unique Index also creates index that are physical structure that maintain uniqueness. It is a convenient way to enforce a Unique Constraint for SQL Server.
In above case "Unique Constraint" allows one "NULL".
Technically, there's a difference. Logically yes, they achieve the same, but technically they are different. An index is not a constraint and vice versa.
I know the first hit on Google is the blog post of Pinal Dave who says they are the same, but if you look a bit further on the search results, you'll also find posts that contradict this. By the way, to avoid copyright infringement or plagiarism, you should include a reference to the blog of Pinal Dave, not just copy paste its contents and pretend it's yours.
Difference Between Unique Index vs Unique Constraint
How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
Member of
LinkedIn
. My blog at
LessThanDot
.
MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1398836
Koen Verbeeck
Koen Verbeeck
Posted Thursday, December 20, 2012 12:51 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 6:30 AM
Points: 9,410,
Visits: 6,495
Gopi S (12/20/2012)
So far Jason is following me
Yes, by saying your explanation is insufficient...
edit: I forgot to mention: thanks for the effort to create and submit a question. Hopefully you keep this up and hopefully there won't be any confusion on your next question
How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
Member of
LinkedIn
. My blog at
LessThanDot
.
MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1398837
« Prev Topic
|
Next Topic »
65 posts, Page 2 of 7
««
1
2
3
4
5
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.