0

!Entity Relationship Diagram

I'm trying to figure out how to update a table with values from a different table when the second table is updated. Basically I want to be able to insert a new row into the donate_blood table, then auto create a new blood entry with the values patients.blood_type and patients.id. The blood.blood_id is set to auto increment.

Is this possible? I'm not too familiar with triggers and it isn't making much sense to me. Could someone point me in the right direction?

I can try to explain further if it doesn't exactly make sense.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • You shouldn't be duplicating data in multiple tables, but I guess blood type can change. – danblack Nov 08 '19 at 03:22
  • Its a little unclear why `donate_blood` exists. How is this different from `blood`? Try to make your ER diagram embedded in the question rather than a link. Welcome to SO. – danblack Nov 08 '19 at 03:27
  • Unable to embed images as I just created my account. donate_blood is the table that was created when I created the relationship between blood and donors. – user3131489 Nov 08 '19 at 03:29
  • I updated the post to display the full ERD as well – user3131489 Nov 08 '19 at 03:33
  • donate_blood looks like a 1:1 relationship between donor and blood (being a dontated unit). No reason a donor_id and donation timestamp couldn't be in blood. Same with bank_id. Rather than using triggers, use [insert -select](https://dev.mysql.com/doc/refman/5.7/en/insert-select.html) to copy the bloodtype over from the donor. – danblack Nov 08 '19 at 03:48
  • My advise is `use_blood`, `blood`, `stored_blood` and `donate_blood` should all be the one table. Show some SQL for creating a donation, or creating a patient and we can try to see the correctness of that. – danblack Nov 11 '19 at 03:44

0 Answers0