DB2 FOREIGN KEY name DOES NOT CONFORM TO THE DESCRIPTION OF THE PRIMARY KEY OF TABLE table name

Hi ,
Need help on execution of FK Relation ship in Z/OS
I have Two table Table_A and Table_B
Create table TABLE_A(Primary_no bigint not null,Primary_Value varchar(25)) ;
Create table TABLE_B(Secondary_no bigint not null,Parent_Primary_No Bigint,Secondary_Value varchar(25));

ALTER TABLE TABLE_B ADD CONSTRAINT FKEY8 FOREIGN KEY (Parent_Primary_No)      REFERENCES TABLE_B (Primary_No) ON DELETE RESTRICT;
I am getting error
DB2 FOREIGN KEY name DOES NOT CONFORM TO THE DESCRIPTION OF THE PRIMARY KEY OF TABLE table name
So I checked the difference
in TABLE_B column  (Parent_Primary_No) is nullable
I have ran same in UDB it is working ....but i need this column nullable.
SAKETHREDDYAsked:
Who is Participating?
 
Computer101Connect With a Mentor Commented:
PAQed with points refunded (125)

Computer101
EE Admin
0
 
Dave FordSoftware Developer / Database AdministratorCommented:

I could be missing something here, but it doesn't look like you defined a primary key on TABLE_A.

Also, you foreign key constraint seems to be pointing to itself. I think you meant to point to TABLE_A.

HTH,
DaveSlash
0
 
momi_sabagCommented:
Dave is right
you should try
ALTER TABLE TABLE_B ADD CONSTRAINT FKEY8 FOREIGN KEY (Parent_Primary_No)      REFERENCES TABLE_A (Primary_No) ON DELETE RESTRICT;

there should be no problem in zos having the foreign key column contain nulls,
just make sure the column you reference (primary_no in table_a) has either a primary key or a unique key defined on it
0
 
SAKETHREDDYAuthor Commented:
thanks for your help.
i find the solution in my R&D
In Z/Os we need to create Index , before creating the Primary key, Then if we ran the FK relationships it will not give above error.
In UDB on Windows , when i am creating table and Primary key , it is creating Index on primary cols, so it is not giving error in local system

 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.