简体   繁体   中英

insert with condition in mysql

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)

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 INSERT s.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM