IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 - Unique Constraint


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
abiyn

New User


Joined: 25 Mar 2008
Posts: 12
Location: Chennai

PostPosted: Wed Mar 26, 2008 3:30 pm
Reply with quote

I want to create below two tables

EMP (Parent table)
----

Emp ID - Primary Key
Ename
Project ID

PRO (Child table)
----
Project ID
PName
Manager ID - Foregin Key


I have created the first table. But when I tried to create 2nd table with unique constraint on Project ID, its throwing the below error message


---------+---------+---------+---------+---------+---------+---------+---------+
DSNT408I SQLCODE = -542, ERROR: PID CANNOT BE A COLUMN OF A PRIMARY KEY, A
UNIQUE CONSTRAINT, OR A PARENT KEY BECAUSE IT CAN CONTAIN NULL VALUES
DSNT418I SQLSTATE = 42831 SQLSTATE RETURN CODE
DSNT415I SQLERRP = DSNXIAB5 SQL PROCEDURE DETECTING ERROR
DSNT416I SQLERRD = 10 0 0 -1 0 0 SQL DIAGNOSTIC INFORMATION
DSNT416I SQLERRD = X'0000000A' X'00000000' X'00000000' X'FFFFFFFF'
X'00000000' X'00000000' SQL DIAGNOSTIC INFORMATION

Could you please provide the solution to define Project ID as unique.


Thanks In Advance

Regards
Abi
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Mar 26, 2008 3:33 pm
Reply with quote

the explanation is right in front of You

Quote:
DSNT408I SQLCODE = -542, ERROR: PID CANNOT BE A COLUMN OF A PRIMARY KEY, A
UNIQUE CONSTRAINT, OR A PARENT KEY BECAUSE IT CAN CONTAIN NULL VALUES
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Wed Mar 26, 2008 3:34 pm
Reply with quote

Could you please show CREATE statments of PRO table?
Back to top
View user's profile Send private message
abiyn

New User


Joined: 25 Mar 2008
Posts: 12
Location: Chennai

PostPosted: Wed Mar 26, 2008 3:42 pm
Reply with quote

Gnanas,

Below this the code which i used to create 2 tables. I want PID in table PRO to be unique. How can i do that?

CREATE TABLE EMP(ID INT NOT NULL,NAME VARCHAR(10),PID INT,DES CHAR(5),
PRIMARY KEY(ID));

CREATE UNIQUE INDEX EMPINX ON EMP(ID);

CREATE TABLE PRO(PID INT NOT NULL,PNAME VARCHAR(10),
MID INT,
FOREIGN KEY(MID) REFERENCES EMP(ID))
;

ALTER TABLE PRO ADD CONSTRAINT PIDU UNIQUE(PID);
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Wed Mar 26, 2008 3:57 pm
Reply with quote

Please give this,
Code:
CREATE UNIQUE INDEX PROINX ON PRO(PID);

Instead of ALTER...
Back to top
View user's profile Send private message
abiyn

New User


Joined: 25 Mar 2008
Posts: 12
Location: Chennai

PostPosted: Wed Mar 26, 2008 4:05 pm
Reply with quote

Gnanas,

I got the result.. Thanks a lot
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Any JCL or VSAM Utility to get number... JCL & VSAM 1
No new posts Difference between VALIDPROC and CHEC... DB2 3
No new posts Can we Insert duplicates in Primary U... DB2 2
No new posts SEPARATE UNIQUE and NON-UNIQUE in SEP... SYNCSORT 6
No new posts Unique IMS DB identifier IMS DB/DC 1
Search our Forums:

Back to Top