473,394 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

UNIQUE WHERE NOT NULL

UNIQUE WHERE NOT NULL is supported in DB2 for z/OS, which allows for
duplicate null values to exist on a unique constraint.

Anyone know if or when this is coming to DB2 for LUW?
Nov 12 '05 #1
7 13803
Mark A wrote:
UNIQUE WHERE NOT NULL is supported in DB2 for z/OS, which allows for
duplicate null values to exist on a unique constraint.

Anyone know if or when this is coming to DB2 for LUW?

Not being IBM I can't answer the original question, but I can suggest a
reasonably easy to do the same thing. Suppose a table t, with at least
primarykey, and notnullunique columns. The following (barring any typing
or memory lapses on my part) should do what what you want.

alter table t
add column pseudokey generated always as
colaesce(notnullunique, primarykey);

alter table t
add constraint uniqpseudo unique (pseudokey);

These can be combined into one statement, but the intent is clearer as two.
Nov 12 '05 #2
"Bob Stearns" <rs**********@charter.net> wrote in message
news:Jl*****************@fe03.lga...
Not being IBM I can't answer the original question, but I can suggest a
reasonably easy to do the same thing. Suppose a table t, with at least
primarykey, and notnullunique columns. The following (barring any typing
or memory lapses on my part) should do what what you want.

alter table t
add column pseudokey generated always as
colaesce(notnullunique, primarykey);

alter table t
add constraint uniqpseudo unique (pseudokey);

These can be combined into one statement, but the intent is clearer as

two.

2 Big assumptions need to be made for this to work:

1) There are no data type or length issues between the two columns
2) There is no way that the primary key could be a valid value on the other
column that you are testing for uniqueness.
Nov 12 '05 #3
it's a brilliant idea, it only needs a little modification:

alter table t
add column pseudokey generated always as
(case when notnullunique is null then primarykey end);
create unique index u_ind on the_table(pseudokey, notnullunique);

Nov 12 '05 #4
I suggest you open a "requirement" through your local IBM support. That way,
you at least get noticed. And the more they receive such requirements, the
better the chances that IBM will start to address these sorts of unnecessary
and frustrating incompatibilities.

And yes, it's a very big nuisance. Some things take years to move from
mainframe DB2 to UDB (e.g. versioned packages), others, like results sets in
embedded CALLs, UNIQUE WHERE NOT NULL, or an intelligent REBIND command,
still haven't been done.

"Mark A" <no****@nowhere.com> wrote in message
news:Xu********************@comcast.com...
UNIQUE WHERE NOT NULL is supported in DB2 for z/OS, which allows for
duplicate null values to exist on a unique constraint.

Anyone know if or when this is coming to DB2 for LUW?

Nov 12 '05 #5
ak************@yahoo.com wrote:
it's a brilliant idea, it only needs a little modification:

alter table t
add column pseudokey generated always as
(case when notnullunique is null then primarykey end);
create unique index u_ind on the_table(pseudokey, notnullunique);


Why do you need the modifications? The COALESCE is exactly the same
(semantically) as the CASE expression you used. And the UNIQUE constraint
creates a unique index under the covers too.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #6
Knut,

just imagine:

insert into t(primarykey, notnullu*nique)values(1,null);

in Bob's index there is (1);
in mine there is (1,null);

insert into t(primarykey, notnullu*nique)values(2,1);
---- should be OK, correct?

that would add another (1) to Bob's index - FAIL, IT'S A UNIQUE INDEX
in mine there are (1,null) and (null,1) - still OK

When I was typing
case when notnullunique is null then primarykey end
I meant

case when notnullunique is null then primarykey ELSE NULL end

which is not equivalent to COALESCE, which is

case when notnullunique is null then primarykey ELSE NOTNULLUNIQUE end

What do you think?
Alexander

Nov 12 '05 #7
ak************@yahoo.com wrote:
Knut,

just imagine:

insert into t(primarykey, notnullu*nique)values(1,null);

in Bob's index there is (1);
in mine there is (1,null);


You are correct. I missed the part where the index is created on two
columns. Now it makes sense to me.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #8

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

Similar topics

5
by: Westcoast Sheri | last post by:
Which will be a faster lookup of an item by, "color" in the following mySQL tables: "unique key," "primary key," or just plain "key"?? CREATE TABLE myTable ( number int(11) NOT NULL default '0',...
26
by: Agoston Bejo | last post by:
I want to enforce such a constraint on a column that would ensure that the values be all unique, but this wouldn't apply to NULL values. (I.e. there may be more than one NULL value in the column.)...
10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
4
by: Dave | last post by:
Can you create a unique constraint on multiple columns, or does it have to be implemented as a unique index? If possible can someone please post some sample code? Thanks,
3
by: Prince Kumar | last post by:
Is there any way I can define an Unique constraint or unique index which allows more than one null values for the same column combination in DB2? ie, If my index is defined on (col3, col4) where...
10
by: BuddhaBuddy | last post by:
Platform is DB2/NT 7.2.9 The table was created like this: CREATE TABLE MYTEST ( MYTESTOID bigint not null primary key, FK_OTHEROID bigint not null references other, FK_ANOTHEROID bigint not...
4
by: Rich | last post by:
Hi, I keep getting an error when I try to insert a new record into a table (SQL 2000) that has a column that I've configured as 'Unique Null Allowed'. I used Visual Studio (2003) IDE SQL Data...
2
by: rootman | last post by:
Hi @all i try to create a ssh public key database on a mysql-5.0.16 DB the problem is the size of the varchar, i want a size 1024... mysql> create table sshkeys ( absid integer unsigned...
1
by: ken_knee | last post by:
I have a PARENT/CHILD I'm attempting to attach another CHILD to. When I try to add a FOREIGN KEY to the 3rd table referring to CHILD1 (AGTERNS), I get error SQL0573N A column list specified in the...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.