Solved

Foreign key problem in DB2 database

Posted on 2011-03-20
3
1,518 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:Dave Ford
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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

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 (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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