473,513 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DB2 UDB for Windows needs to emulate a DB2 UDB for z/OS function

In my environment we are using DB2 UDB for Windows for development and
DB2 UDB for z/OS for production. In DB2 UDB for z/OS uniqueness of
columns that permit nulls may be enforced with a unique index created
with the "WHERE NOT NULL" parameter; this has the effect of ensuring
that not null columns are unique while not considering null columns to
be duplicates. Does anyone know of a way to duplicate this behavior
with DB2 UDB for Windows?

Nov 15 '06 #1
8 1669

JimS wrote:
In my environment we are using DB2 UDB for Windows for development and
DB2 UDB for z/OS for production. In DB2 UDB for z/OS uniqueness of
columns that permit nulls may be enforced with a unique index created
with the "WHERE NOT NULL" parameter; this has the effect of ensuring
that not null columns are unique while not considering null columns to
be duplicates. Does anyone know of a way to duplicate this behavior
with DB2 UDB for Windows?
All I can think of is a trigger that check uniquenes when column is not
null. If the value is not unique, signal sql exception.
/Lennart

Nov 15 '06 #2

Lennart wrote:
JimS wrote:
In my environment we are using DB2 UDB for Windows for development and
DB2 UDB for z/OS for production. In DB2 UDB for z/OS uniqueness of
columns that permit nulls may be enforced with a unique index created
with the "WHERE NOT NULL" parameter; this has the effect of ensuring
that not null columns are unique while not considering null columns to
be duplicates. Does anyone know of a way to duplicate this behavior
with DB2 UDB for Windows?

All I can think of is a trigger that check uniquenes when column is not
null. If the value is not unique, signal sql exception.
/Lennart
Thanks for the reply. Using a trigger in this manner seems plausible.
Do you know if there is a user exit in DB2 UDB for Windows that can be
tweaked to emulate the "WHERE NOT NULL" parameter on a unique index in
DB2 UDB for z/OS? If not, do you know if DB2 UDB for Windows supports
Sparse Indexes?

Nov 16 '06 #3
JimS wrote:
Lennart wrote:
>JimS wrote:
>>In my environment we are using DB2 UDB for Windows for development and
DB2 UDB for z/OS for production. In DB2 UDB for z/OS uniqueness of
columns that permit nulls may be enforced with a unique index created
with the "WHERE NOT NULL" parameter; this has the effect of ensuring
that not null columns are unique while not considering null columns to
be duplicates. Does anyone know of a way to duplicate this behavior
with DB2 UDB for Windows?
All I can think of is a trigger that check uniquenes when column is not
null. If the value is not unique, signal sql exception.
/Lennart

Thanks for the reply. Using a trigger in this manner seems plausible.
Do you know if there is a user exit in DB2 UDB for Windows that can be
tweaked to emulate the "WHERE NOT NULL" parameter on a unique index in
DB2 UDB for z/OS? If not, do you know if DB2 UDB for Windows supports
Sparse Indexes?
There is no such exit.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Nov 16 '06 #4

JimS wrote:
In my environment we are using DB2 UDB for Windows for development and
DB2 UDB for z/OS for production. In DB2 UDB for z/OS uniqueness of
columns that permit nulls may be enforced with a unique index created
with the "WHERE NOT NULL" parameter; this has the effect of ensuring
that not null columns are unique while not considering null columns to
be duplicates. Does anyone know of a way to duplicate this behavior
with DB2 UDB for Windows?
How about this way?
1) Add a generated column(call it uniq_sfx) Like this
uniq_sfx data-type
GENERATED ALWAYS AS
(CASE
WHEN unique_col IS NULL THEN
<primary-keyor <unique-column>
ELSE NULL
END
)

2) CREATE UNIQUE INDEX ON <table(unique_col, uniq_sfx)

For example:
(mgrno is a unique column which is allowed multiple nulls)
------------------------------ Commands Entered
------------------------------
CREATE TABLE Dept_Uniq_NULLs
(deptno CHAR(3) NOT NULL PRIMARY KEY
,deptname VARCHAR(29) NOT NULL
,mgrno CHAR(6)
,admrdept CHAR(3) NOT NULL
,uniq_sfx CHAR(3)
GENERATED ALWAYS AS
(CASE
WHEN mgrno IS NULL THEN
deptno
ELSE NULL
END
)
);
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
CREATE UNIQUE INDEX Dept_UNs_mgrno ON Dept_Uniq_NULLs
(mgrno, uniq_sfx);
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, mgrno, admrdept)
SELECT deptno, deptname, mgrno, admrdept
FROM Department;
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
SELECT * FROM Dept_Uniq_NULLs;
------------------------------------------------------------------------------

DEPTNO DEPTNAME MGRNO ADMRDEPT UNIQ_SFX
------ ----------------------------- ------ -------- --------
A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00 -
B01 PLANNING 000020 A00 -
C01 INFORMATION CENTER 000030 A00 -
D01 DEVELOPMENT CENTER - A00 D01
D11 MANUFACTURING SYSTEMS 000060 D01 -
D21 ADMINISTRATION SYSTEMS 000070 D01 -
E01 SUPPORT SERVICES 000050 A00 -
E11 OPERATIONS 000090 E01 -
E21 SOFTWARE SUPPORT 000100 E01 -

9 record(s) selected.
------------------------------ Commands Entered
------------------------------
INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept)
VALUES ('D02', 'New DEVELOPMENT CENTER', 'A00');
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, mgrno, admrdept)
VALUES ('D03', '3rd DEVELOPMENT CENTER', '000030', 'A00');
------------------------------------------------------------------------------
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0803N One or more values in the INSERT statement, UPDATE statement,
or
foreign key update caused by a DELETE statement are not valid because
the
primary key, unique constraint or unique index identified by "2"
constrains
table "DB2ADMIN.DEPT_UNIQ_NULLS" from having duplicate rows for those
columns.
SQLSTATE=23505

------------------------------ Commands Entered
------------------------------
SELECT * FROM Dept_Uniq_NULLs;
------------------------------------------------------------------------------

DEPTNO DEPTNAME MGRNO ADMRDEPT UNIQ_SFX
------ ----------------------------- ------ -------- --------
A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00 -
B01 PLANNING 000020 A00 -
C01 INFORMATION CENTER 000030 A00 -
D01 DEVELOPMENT CENTER - A00 D01
D11 MANUFACTURING SYSTEMS 000060 D01 -
D21 ADMINISTRATION SYSTEMS 000070 D01 -
E01 SUPPORT SERVICES 000050 A00 -
E11 OPERATIONS 000090 E01 -
E21 SOFTWARE SUPPORT 000100 E01 -
D02 New DEVELOPMENT CENTER - A00 D02

10 record(s) selected.

Nov 17 '06 #5
If you want hide uniq_sfx column, you can CREATE View.

For example:
------------------------------ Commands Entered
------------------------------
CREATE VIEW Dept_Uniq_NULLsV AS
SELECT deptno, deptname, mgrno, admrdept
FROM Dept_Uniq_NULLs;
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
INSERT INTO Dept_Uniq_NULLsV
VALUES ('D04', '4th DEVELOPMENT CENTER', NULL, 'A00');
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.
------------------------------ Commands Entered
------------------------------
SELECT * FROM Dept_Uniq_NULLsV;
------------------------------------------------------------------------------

DEPTNO DEPTNAME MGRNO ADMRDEPT
------ ----------------------------- ------ --------
A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00
B01 PLANNING 000020 A00
C01 INFORMATION CENTER 000030 A00
D01 DEVELOPMENT CENTER - A00
D11 MANUFACTURING SYSTEMS 000060 D01
D21 ADMINISTRATION SYSTEMS 000070 D01
E01 SUPPORT SERVICES 000050 A00
E11 OPERATIONS 000090 E01
E21 SOFTWARE SUPPORT 000100 E01
D02 New DEVELOPMENT CENTER - A00
D04 4th DEVELOPMENT CENTER - A00

11 record(s) selected.

------------------------------ Commands Entered
------------------------------
INSERT INTO Dept_Uniq_NULLsV
VALUES ('D05', '5th DEVELOPMENT CENTER', '000050', 'A00');
------------------------------------------------------------------------------
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0803N One or more values in the INSERT statement, UPDATE statement,
or
foreign key update caused by a DELETE statement are not valid because
the
primary key, unique constraint or unique index identified by "2"
constrains
table "DB2ADMIN.DEPT_UNIQ_NULLS" from having duplicate rows for those
columns.
SQLSTATE=23505

Nov 17 '06 #6

Tonkuma wrote:
JimS wrote:
In my environment we are using DB2 UDB for Windows for development and
DB2 UDB for z/OS for production. In DB2 UDB for z/OS uniqueness of
columns that permit nulls may be enforced with a unique index created
with the "WHERE NOT NULL" parameter; this has the effect of ensuring
that not null columns are unique while not considering null columns to
be duplicates. Does anyone know of a way to duplicate this behavior
with DB2 UDB for Windows?
How about this way?
1) Add a generated column(call it uniq_sfx) Like this
uniq_sfx data-type
GENERATED ALWAYS AS
(CASE
WHEN unique_col IS NULL THEN
<primary-keyor <unique-column>
ELSE NULL
END
)

2) CREATE UNIQUE INDEX ON <table(unique_col, uniq_sfx)

For example:
(mgrno is a unique column which is allowed multiple nulls)
------------------------------ Commands Entered
------------------------------
CREATE TABLE Dept_Uniq_NULLs
(deptno CHAR(3) NOT NULL PRIMARY KEY
,deptname VARCHAR(29) NOT NULL
,mgrno CHAR(6)
,admrdept CHAR(3) NOT NULL
,uniq_sfx CHAR(3)
GENERATED ALWAYS AS
(CASE
WHEN mgrno IS NULL THEN
deptno
ELSE NULL
END
)
);
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
CREATE UNIQUE INDEX Dept_UNs_mgrno ON Dept_Uniq_NULLs
(mgrno, uniq_sfx);
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, mgrno, admrdept)
SELECT deptno, deptname, mgrno, admrdept
FROM Department;
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
SELECT * FROM Dept_Uniq_NULLs;
------------------------------------------------------------------------------

DEPTNO DEPTNAME MGRNO ADMRDEPT UNIQ_SFX
------ ----------------------------- ------ -------- --------
A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00 -
B01 PLANNING 000020 A00 -
C01 INFORMATION CENTER 000030 A00 -
D01 DEVELOPMENT CENTER - A00 D01
D11 MANUFACTURING SYSTEMS 000060 D01 -
D21 ADMINISTRATION SYSTEMS 000070 D01 -
E01 SUPPORT SERVICES 000050 A00 -
E11 OPERATIONS 000090 E01 -
E21 SOFTWARE SUPPORT 000100 E01 -

9 record(s) selected.
------------------------------ Commands Entered
------------------------------
INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept)
VALUES ('D02', 'New DEVELOPMENT CENTER', 'A00');
------------------------------------------------------------------------------
DB20000I The SQL command completed successfully.

------------------------------ Commands Entered
------------------------------
INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, mgrno, admrdept)
VALUES ('D03', '3rd DEVELOPMENT CENTER', '000030', 'A00');
------------------------------------------------------------------------------
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0803N One or more values in the INSERT statement, UPDATE statement,
or
foreign key update caused by a DELETE statement are not valid because
the
primary key, unique constraint or unique index identified by "2"
constrains
table "DB2ADMIN.DEPT_UNIQ_NULLS" from having duplicate rows for those
columns.
SQLSTATE=23505

------------------------------ Commands Entered
------------------------------
SELECT * FROM Dept_Uniq_NULLs;
------------------------------------------------------------------------------

DEPTNO DEPTNAME MGRNO ADMRDEPT UNIQ_SFX
------ ----------------------------- ------ -------- --------
A00 SPIFFY COMPUTER SERVICE DIV. 000010 A00 -
B01 PLANNING 000020 A00 -
C01 INFORMATION CENTER 000030 A00 -
D01 DEVELOPMENT CENTER - A00 D01
D11 MANUFACTURING SYSTEMS 000060 D01 -
D21 ADMINISTRATION SYSTEMS 000070 D01 -
E01 SUPPORT SERVICES 000050 A00 -
E11 OPERATIONS 000090 E01 -
E21 SOFTWARE SUPPORT 000100 E01 -
D02 New DEVELOPMENT CENTER - A00 D02

10 record(s) selected.
Ah, thats clever. Heres a slightly different version (which I think
will work as well):

DROP TABLE Dept_Uniq_NULLs;
CREATE TABLE Dept_Uniq_NULLs
(deptno CHAR(3) NOT NULL PRIMARY KEY
,deptname VARCHAR(29) NOT NULL
,mgrno CHAR(6)
,admrdept CHAR(3) NOT NULL
,uniq_sfx CHAR(3)
GENERATED ALWAYS AS
(COALESCE(mgrno,deptno))
);

CREATE UNIQUE INDEX Dept_UNs_mgrno ON Dept_Uniq_NULLs
(uniq_sfx);

INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept)
VALUES ('D02', 'New DEVELOPMENT CENTER', 'A00');

INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept)
VALUES ('D03', 'New DEVELOPMENT CENTER', 'A00');

INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept, mgrno)
VALUES ('D04', 'New DEVELOPMENT CENTER', 'A00', 'AAA');

INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept, mgrno)
VALUES ('D05', 'New DEVELOPMENT CENTER', 'A00', 'BBB');

[ltjn@lelles ~]$ db2 "select * from Dept_Uniq_NULLs"

DEPTNO DEPTNAME MGRNO ADMRDEPT UNIQ_SFX
------ ----------------------------- ------ -------- --------
D02 New DEVELOPMENT CENTER - A00 D02
D03 New DEVELOPMENT CENTER - A00 D03
D04 New DEVELOPMENT CENTER AAA A00 AAA
D05 New DEVELOPMENT CENTER BBB A00 BBB

4 record(s) selected.

Nov 17 '06 #7
Lennart wrote:
Ah, thats clever. Heres a slightly different version (which I think
will work as well):

DROP TABLE Dept_Uniq_NULLs;
CREATE TABLE Dept_Uniq_NULLs
(deptno CHAR(3) NOT NULL PRIMARY KEY
,deptname VARCHAR(29) NOT NULL
,mgrno CHAR(6)
,admrdept CHAR(3) NOT NULL
,uniq_sfx CHAR(3)
GENERATED ALWAYS AS
(COALESCE(mgrno,deptno))
);

CREATE UNIQUE INDEX Dept_UNs_mgrno ON Dept_Uniq_NULLs
(uniq_sfx);

INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept)
VALUES ('D02', 'New DEVELOPMENT CENTER', 'A00');

INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept)
VALUES ('D03', 'New DEVELOPMENT CENTER', 'A00');

INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept, mgrno)
VALUES ('D04', 'New DEVELOPMENT CENTER', 'A00', 'AAA');

INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept, mgrno)
VALUES ('D05', 'New DEVELOPMENT CENTER', 'A00', 'BBB');

[ltjn@lelles ~]$ db2 "select * from Dept_Uniq_NULLs"

DEPTNO DEPTNAME MGRNO ADMRDEPT UNIQ_SFX
------ ----------------------------- ------ -------- --------
D02 New DEVELOPMENT CENTER - A00 D02
D03 New DEVELOPMENT CENTER - A00 D03
D04 New DEVELOPMENT CENTER AAA A00 AAA
D05 New DEVELOPMENT CENTER BBB A00 BBB

4 record(s) selected.
You can't INSERT a row with MGRNO = 'D02'.
Following INSERT will fail.
INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept, mgrno)
VALUES ('D06', 'New DEVELOPMENT CENTER', 'A00', 'D02');

Nov 18 '06 #8

Tonkuma wrote:
[...]
You can't INSERT a row with MGRNO = 'D02'.
Following INSERT will fail.
INSERT INTO Dept_Uniq_NULLs
(deptno, deptname, admrdept, mgrno)
VALUES ('D06', 'New DEVELOPMENT CENTER', 'A00', 'D02');
I stand corrected :-)

/Lennart

Nov 19 '06 #9

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

Similar topics

16
34536
by: Robert Mark Bram | last post by:
Hi All! Is there a way to reference a window by name without doing something like this: open (, 'windowName'); The open method will open a blank window if there is no window with such a name. I am trying to organise a navigation structure between two windows with content from the same host.. I have been trying the following:
37
4946
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined signature. When developing this lib, I figured that the pointer-to-member-function, although seemingly an attractive solution, does not work well...
4
1037
by: Siegfried Heintze | last post by:
I believe it is necessary to grant my FTP account access to Access to the path "C:/WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/root/" if I want to access DLLs or MSAccess databases in my ASP.NET application. Is this documented in a KB article somewhere? Since third party hosting services are reluctant to grant me such...
9
4967
by: bob | last post by:
Hi, I know there exists a good reason why the designers of c++ decided that function hiding should exist. But I don't know why. Can anybody provide a good reason/example of a case where function hiding saves the day. I know there exists one, I'd just like to hear about it. thanks and have a nice day.
11
1968
by: The Frog | last post by:
Hi all, Maybe I am just missing something simple here, but I seem to have an issue with a callback function in A97 that is used to fill a Listbox with values. The first time the callback function is used (when the form opens) all runs well and everyone is happy. Then comes the problem - values are added to the recordset (ADO) that the...
2
4465
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as seperate process. If my windows application starts running,only if it completes fully, then my windows services should continue its execution. My...
1
4829
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as seperate process. If my windows application starts running,only if it completes fully, then my windows services should continue its execution. My...
11
4259
by: John Nagle | last post by:
I passed a dict for the "env" variable to Popen with Unicode strings for the dictionary values. Got: File "D:\Python24\lib\subprocess.py", line 706, in _execute_child TypeError: environment can only contain strings It turns out that the strings in the "env" parameter have to be ASCII, not Unicode, even though Windows fully supports...
0
7178
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...
0
7397
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, 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. ...
0
7565
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7128
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...
0
7543
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5704
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3255
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...
0
3242
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.