简体   繁体   中英

MySQL WorkBench Hospital database

I'm learning MySQL with MySQL workbench and I have tried to code a hospital database but my problem is how can I know if I have enough beds-rooms for my patients? I have 5 tables:

t_patients (with idpatient, name, surname, n_card), 
t_doctor (with iddoctor, name, surname), 
t_ward (with idward, name), 
t_bed (with idbed, nbed, idward), 
t_ricovery (with idrecovery, idpatient, iddoctor, idbed, datericovery, datedischarge).

Can you help me? Sorry for my bad english and thank you

If you need a SQL Solution , I think it is best to add a "bed_available" field to either your t_bed table or your t_patients which is Boolean , true/false or 1 / 0 . this way you could use the function " Count " to count the number of free beds.

some thing like this :

SELECT COUNT(*) FROM t_patients WHERE bed_available=true;

to read more about the COUNT function , try this link : W3Schools

There is another solution , you could add a field (int), write a trigger that adds or decreases 1 (a bed or bed-room) each time a field updates / deletes or is inserted ! like when someone gets a room the total number of the beds is decreased by one and when someone is released from hospital the number of the free beds gets a plus 1

hope it helps.

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