473,503 Members | 12,791 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Uniqueness in a Nullable Column

Just curious to know if there is a simple way to ensure uniqueness
among non-null values within a nullable column.

For instance if I have a column of Names that can contain null values,
I would like to ensure that all names that actually have a value are
unique.

Thanks!

Wendy

Nov 12 '05 #1
4 4175
from a theoretical point of view, you might have a design flaw. In some
cases it is better to have a separate table Names with a UNIQUE
constraint on it, and have your original table refer to it via an FK
constraint.

Having said that, you can add another column, let's say N, and set it
to -1 for all NOT NULL names, and populate it from a sequence starting
from 0 if the name is null. Create a UNIQUE index on (Name, N) and you
are all set

Nov 12 '05 #2
Actually, from a theoretical viewpoint "a null is value distinct from any
other value INCLUDING NULL" (see Codd, accent mine). Even DB2 will return
unknown, not true for NULL = NULL.

Unfortunately, DB2 UDB's unique index fails to implement the semantic,
leading to the need for workarounds such as yours.

<ak************@yahoo.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
from a theoretical point of view, you might have a design flaw. In some
cases it is better to have a separate table Names with a UNIQUE
constraint on it, and have your original table refer to it via an FK
constraint.

Having said that, you can add another column, let's say N, and set it
to -1 for all NOT NULL names, and populate it from a sequence starting
from 0 if the name is null. Create a UNIQUE index on (Name, N) and you
are all set

Nov 12 '05 #3
theoretically, you could create a statement level trigger that checks
for duplicates amongst all not null values in this column.

Nov 12 '05 #4
>> Actually, from a theoretical viewpoint "a null is value distinct
from any
other value INCLUDING NULL" (see Codd, accent mine). Even DB2 will
return unknown, not true for NULL = NULL
.... <<

note that DB2 (as well as Oracle) will also return unknown for NULL <>
NULL. In this particular contest "distinct from any other value " means
"not(equal to any other value), unknown accepted", and this is exactly
what's implemented by Oracle
Unfortunately, DB2 UDB's unique index fails to implement the

semantic,
leading to the need for workarounds such as yours.
.... <<

DB2 UDB implements a stronger requirement
"distinct from any other value " meaning "not equal to any other value,
unknown NOT accepted".

Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3369
by: Paul Eaton | last post by:
Hi I am using asp/vbscript/ado/mssql. I am able to get the nullable property OK when generating a recordset with a simple SQL statement such as "select Fld1,Fld2 from Table1" and then looping...
20
4860
by: Andy | last post by:
Hi All! General statement: FK should not be nullabe to avoid orphans in DB. Real life: Business rule says that not every record will have a parent. It is implemented as a child record has FK...
6
4161
by: Doug Baroter | last post by:
Hi, I've enherited a big mess, a SQL Server 2000 database with approximately 50 user tables and 65+ GB data, no explicit relationships among entities (RI constraints whatsover), attempt to...
7
3875
by: Clifford Heath | last post by:
I have a case where a table has two candidate primary keys, but either (but not both) may be NULL. I don't want to store a copy of the concatenated ISNULL'ed fields as an additional column, though...
30
4517
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
7
3932
by: Rajesh.............................. | last post by:
What is the impact of using a nullable column vs a not nullable column for partitioning a Union ALL View? I have a Union ALL View with ten underlying tables unioned based on different values for a...
0
1391
by: Larry Lard | last post by:
There seems to be something a bit lacking in the way the dataset designer thing deals (or rather doesn't) with nullable fields in VS2005. Maybe it's cos I'm using VB2005 Express (which is variously...
3
2609
by: KillerJ | last post by:
I found a post about this exact issue: ...
5
51547
by: GG | last post by:
I am trying to add a nullable datetime column to a datatable fails. I am getting exception DataSet does not support System.Nullable<>. None of these works dtSearchFromData.Columns.Add( new...
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
7364
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...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
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
5604
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,...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
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 ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
405
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.