473,504 Members | 13,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why unique takes only one null as we know all null are not equal?

5 New Member
If Null= Null or <some value>= Null are not valid or in other words null values can't be compared then why unique constraint takes only one null value.
Feb 11 '11 #1
9 2199
Rabbit
12,516 Recognized Expert Moderator MVP
Who said null values can't be compared? They can be compared.
Feb 11 '11 #2
Tanu Sharma
5 New Member
Agreed. As null can not be considered as a value rather a marker which indicates absence of value and a value if compared with null results in an unknown. My question is for unique constraint. In SQL server we are not allowed to enter more then one null if there is a unique constraint present for same column. Could you please help me with the answer?
Feb 11 '11 #3
ck9663
2,878 Recognized Expert Specialist
Here, read this...

Good Luck!!!

~~ CK
Feb 11 '11 #4
Tanu Sharma
5 New Member
Thanks Ck.
But this couldn't answer my question as this solution consider all nulls equal and that's why it's grouping them together. It would be a great help for me if you could explain concept of Null in databases.
Feb 11 '11 #5
Rabbit
12,516 Recognized Expert Moderator MVP
In SQL Server, nulls are considered equal and are indexed.
Feb 11 '11 #6
Tanu Sharma
5 New Member
I agree to your fact, Rabbit.
But interestingly this is contradictory to the fact that joins exclude null values. We can find nulls in a table if using outer joins only. Inner joins and cross joins, also available in standard SQL, do not generate Null placeholders for missing values in related tables.

If we see in MySQL or PostgreSQL, they allow more than one nulls in a unique column, considering two nulls as different.

According to one of the PostgreSQL documentation when an index is declared unique, multiple table rows with equal indexed values will not be allowed. Null values are not considered equal. A multicolumn unique index will only reject cases where all of the indexed columns are equal in two rows.

May be this has not followed by Microsoft SQL Server.
Feb 11 '11 #7
Rabbit
12,516 Recognized Expert Moderator MVP
Who said you can't inner join on a null? You can inner join on a null.
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM Table1
  3. INNER JOIN Table2
  4. ON Table1.ID = Table2.ID
  5.   OR (Table1.ID IS NULL AND Table2.ID IS NULL)
Some database management servers will extend unique constraints to nulls. SQL Server is one of them. PostgreSQL is not.
Feb 11 '11 #8
ck9663
2,878 Recognized Expert Specialist
I can only guess, but I think the reason why sql server did that is because you cannot compare NULL, as you said yourself. Since you cannot compare NULL, you would not know if one NULL is the same or different from the other. For the purpose of group aggregation (which uses the same logic as DISTINCT), it consider all NULLs as one and the same.

Hope that make sense...

Good Luck!!!

~~ CK
Feb 11 '11 #9
Tanu Sharma
5 New Member
Agree to you CK. :-)
Feb 14 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
29178
by: Porthos | last post by:
Are there 'Null' and 'not equal to' operator that I can use in xsl:if statements? I assume that there must be, but I can't figure out the syntax. For example: <xsl:if test="@title DOES NOT...
1
3155
by: putty | last post by:
I found a few posts of people asking about insertCell()/insertRow() not working in IE6 SP2, and a few others about getting "null is null or not an object" errors, but no one posted a solution...
5
21105
by: skyloon | last post by:
hi, my structure table in database: Amount float(53) not null default 0 when i try to run his script: alter table ABC alter column Amount float(53) null it can only set the Amount to allow...
1
10018
by: Tilmann | last post by:
I'm currently using UDB 7.2 on WIN 2000 and also DB2 Version 7 on z/OS. I have one table with a column defined as NOT NULL. I had to change this column from NOT NULL to NULL. Is there any better...
24
19970
by: RHNewBie | last post by:
Hello, What is the difference between null and NULL. Are x == null and x == NULL the same? The compiler is gcc 3.2. Thanks.
2
1957
by: getmadhu | last post by:
Hi All... Any one help me with the above weird error I have a code like below print <<"HTML"; Content-type: text/html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html...
1
1808
by: Cirene | last post by:
I created an AJAX ASP.NET website. When I run the site in IE, with debugging on, I get: A runtime error has occurred. Do you wish to Debug? Line: 43 Error: 'null' is null or not an object Yes ...
4
4711
by: waqasahmed996 | last post by:
hi to all i am getting an error in IE (not in FF) that page in which media player incude give error that "null is null or not an object" please give me some solution a file is included...
4
5587
by: qwedster | last post by:
Howdy folks! I am using stored procedure to see if a value exists in database table and return 0 if exists or else -1, in the following SQL queries. However how to check if a value (that is...
3
8108
karthickkuchanur
by: karthickkuchanur | last post by:
Dear Experts, Please let me know what is the difference between difference between object !=null and null !=object,I already google it but i can't able to find the right answer
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.