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

Unable to create a foreign key


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

New User


Joined: 08 Dec 2005
Posts: 9

PostPosted: Tue Nov 06, 2012 6:24 pm
Reply with quote

Hello,

I have created a table which has a primary key comprising of 2 columns say col1 and col2.
I have created 2 unique index one on primary key(col1 and col 2) and another on col1.

Now I am creating another table where I have to use col1 of first table as a foreign key in new table but I am geting an error (sqlcode 538).

If I refer to the below link then I can see if I have unique index defined in the parent table on a particular column then I can use it as a foreign key in the other table. publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=%2Fcom.ibm.db2z9.doc.codes%2Fsrc%2Ftpc%2Fn538.htm

I have tried to drop the primary key to see if then I am able to create the table with foreign key as col1 but the problem persists.

Could you please help me on this.

Regards,
Gaurav
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Wed Nov 07, 2012 10:29 am
Reply with quote

Can you show the DDL's for both tables , Indexes and Alter statements to define PK and FK.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Nov 12, 2012 3:03 pm
Reply with quote

just curious : why would you have PK (col1,col2) when IX(col1) is unique ?
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 How to create a list of SAR jobs with... CA Products 3
No new posts create rexx edit Macro that edits the... CLIST & REXX 3
No new posts COBOL - create and write to output fi... COBOL Programming 0
No new posts Best way to create an automated line ... TSO/ISPF 3
No new posts Infosphere Optim - unable to save Col... IBM Tools 0
Search our Forums:

Back to Top