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 4 4182
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
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.goo glegroups.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
theoretically, you could create a statement level trigger that checks
for duplicates amongst all not null values in this column.
>> 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". This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 thro' the fields and :-
Response.Write(rs.fields(x).attributes and adFldIsNullable)
|
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 that is null.
|
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
create an ERD would more than likely kill the relatively complexed
app, the owner would want to drop out of window, so,
I don't intend to do that, you get the picture, sorry no DDLs this
time, and many tables have many nullable columns, joins slows...
|
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 that would work if necessary. Instead, I tried
the following (this is a related simplified example, not my
real one):
CREATE FUNCTION ApplyActionPK(
@IP int = NULL,
@DNS varchar(64) = NULL
|
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
corresponding field in the lookup table. In my data table we store the
ID in what I will call the 'key' field.
== Description of the desired operation:
| |
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 column
partition_id in these tables. Now, if I define this column as NOT NULL,
I notice that the loading this view is almost twice fast as if I had
defined it NULLABLE. Can anyone explain? What exactly is DB2 doing in
each of the case when...
|
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
crippled), I don't know. But it seems to me obvious that there should
be some way to specify that DB fields which can be null should be
mapped to appropriate Nullable(Of T) generic types. For fields there's
a dropdown in the dataset designer...
|
by: KillerJ |
last post by:
I found a post about this exact issue:
http://groups.google.com/group/microsoft.public.dotnet.xml/browse_thread/thread/1dfeb38170cb0b1/ea073666a4035bd5?lnk=st&q=decimal+parse+error+loading+dataset&rnum=6&hl=en#ea073666a4035bd5
but it only shows how to correct the issue manually, not whether it is
a known bug.
My situation is slightly different only in that the xml data and schema
I have are coming directly from the DataSet using:...
|
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 DataColumn( "StartDate",
typeof( DateTime? ) ) );
dtSearchFromData.Columns.Add( new DataColumn( "EndDate",
typeof( System.Nullable<DateTime>) ) );
Any ideas?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |