0

in DB tables i've: Patient Table, PatientBasicInfomation Table, PatientImageFindings Table.. i've multiple Questions depend on this design..(note that i'm beginner in DB) 1) if i have for each Patient an ID.. so according to DB concepts both PatientBasicInfomation, PatientImageFindings should have this key (ID) as a foreign key?!

2) in the Patient Table i should reference to the PatientBasicInfomation, PatientImageFindings by using their private keys so they will be in Patient Table as a foreign keys?! am i thinking correct...

3) Now my big problem: i want to insert in PatientImageFindings Table a record but under condition ID + Date (where Date is an important Field in PatientImageFindings Table, i don't know if i should put it as a private key or not..), how could i do this insertion statement in my java class..(Insertion under conditions)

BDeveloper
  • 1,175
  • 6
  • 24
  • 44
  • by the way... i want a condition that checks on ID first to get the specified patient, then check in PatientImageFindigins Table on Date it this Data already exist don't do insertion just update data... else do insertion.. – BDeveloper Jul 14 '12 at 07:59

1 Answers1

0

What you want to do is add a UNIQUE constraint across multiple columns.

This question provides an answer to do just that:
How do I specify unique constraint for multiple columns in MySQL?

alter table votes add unique index(user, email, address);

Unless you have another reason, you should enforce this at the database level and treat exceptions as they arise after attempted INSERTs.

Community
  • 1
  • 1
Prody
  • 5,182
  • 6
  • 44
  • 62
  • i couldn't understand the answer.. why do i need a unique key?!... all i need is a check statement instead... and also is it right if the Patient Table holds only foreign keys (in my java code this is a class which has many objects like: obj of PatientImageFindings, obj of PatientBasicInformation...etc) – BDeveloper Jul 14 '12 at 09:02