Solved

Foreign key problem in DB2 database

Posted on 2011-03-20
3
1,499 Views
Last Modified: 2012-05-11
hi
        i have a table called complaints

complaints(uid ,cid,subject description) where uid and cid are composite primary key

and another table called

complaints_access(uid,cid, creationtime)where again  uid and cid are composite primary key

where cid of complaints_access refers to cid of cid of complaints(foreign key).


now it shows the following error

SQL0573N  A column list specified in the references clause of constraint
"CID..." does not identify a unique constraint of the parent table


please help!
0
Comment
Question by:manikandan689
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
ssisworo earned 500 total points
ID: 35174795
You can not create foreign key only part of the primary key for the referenced table. It has become part of the rules of the relational database. there may be missing, it would be better reviewed its database design.

Here I attach a sample script and desinnya. I hope can help.

--------------------
alter table COMPLAINTS_ACCESS
   drop foreign key "fk_complaints_access";

alter table COMPLAINTS_ACCESS
   add foreign key "fk_complaints_access" (UID, CID)
      references COMPLAINTS (UID, CID)
      on delete restrict;
------------------

 design
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 35175065
foreign keys can only reference primary keys or unique indexes,
so if you want your foreign key to be on cid, you need to create a unique index on cid
0
 
LVL 18

Expert Comment

by:daveslash
ID: 35181810

Both of the above comments should help you solve your immediate problem.

But, from a design standpoint, you may want to investigate whether there two table should be rolled up into one table. Obviously, I don't know the full background of what you're trying to accomplish, but it appears that the creationTime attribute more likely belongs in the parent table (complaints).

HTH,
DaveSlash
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
db2 z/os V10 access path 7 352
RPG to c# 3 398
iSeries DB2 SQL - Query Missing Value 10 92
DB2 with VBA Pass Through Insert Into using a Form Command Button 5 29
November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question