If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > About Unique Constraint - Urgent Plz !

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-04, 00:05
SamCute SamCute is offline
Registered User
 
Join Date: Mar 2004
Posts: 205
About Unique Constraint - Urgent Plz !

Hi ,

Is it necessary that a unique constraint column should have the constraint NOT NULL.

Bcoz, I got this errro when executing the following :

CREATE TABLE T_Person (
USERID VARCHAR2(64), EMPLOYEENUMBER VARCHAR2(256),
CONSTRAINT PERSON_A3 UNIQUE (USERID)
);

"USERID" cannot be a column of a primary key or unique key because
it can contain null values. SQLSTATE=42831

Please explain how can I modify the above DDl.
Reply With Quote
  #2 (permalink)  
Old 04-16-04, 01:16
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
I think the message is pretty clear. Check the SQL Reference for details. When a unique constraint is created, DB2 will create a unique index on that column(s) if one does not already exist.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 04-16-04, 01:56
sgulec sgulec is offline
Registered User
 
Join Date: Apr 2004
Location: Turkey
Posts: 1
You can create a UNIQUE WHERE NOT NULL index on that column. In this case NULL values are accepted.
Reply With Quote
  #4 (permalink)  
Old 04-16-04, 07:03
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
UNIQUE WHERE NOT NULL indexes are allowed in DB2 for OS/390 and z/OS, but I don't believe they are allowed in DB2 for UNIX, Linux, and Windows.

In DB2 for UNIX, Linux, and Windows if can create a unique index on a column(s) which are nullable, nulls are treated like any other value and only one null value may exist in the table for the index key.

When creating an unique constraint, the columns must be defined as NOT NULL. This applies to DB2 for OS/390 and z/OS and DB2 for UNIX, Linux, and Windows.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On