· 5 years ago · Mar 24, 2020, 11:08 AM
1CREATE TABLE IF NOT EXISTS `patient` (
2 `id` int not null auto_increment,
3 `name` varchar(255) not null,
4 `last name` varchar(255) not null,
5 `doctor_id` int not null,
6 PRIMARY KEY (`id`)
7);
8ALTER TABLE `patient` ADD CONSTRAINT `patient_doctor_id_foreign` FOREIGN KEY (`doctor_id`) REFERENCES `doctor` (`id`);
9CREATE TABLE IF NOT EXISTS `doctor` (
10 `id` int not null auto_increment,
11 `name` varchar(255) not null,
12 `last name` varchar(255) not null,
13 PRIMARY KEY (`id`)
14);
15CREATE TABLE IF NOT EXISTS `side effects` (
16 `id` int not null auto_increment,
17 `name` varchar(255) not null,
18 `seriousness` int not null,
19 `medicine_id` int not null,
20 PRIMARY KEY (`id`)
21);
22ALTER TABLE `side effects` ADD CONSTRAINT `side effects_medicine_id_foreign` FOREIGN KEY (`medicine_id`) REFERENCES `medicine` (`id`);
23CREATE TABLE IF NOT EXISTS `anamnesis` (
24 `id` int not null auto_increment,
25 `disease_id` int not null,
26 `patient_id` int not null,
27 PRIMARY KEY (`id`)
28);
29ALTER TABLE `anamnesis` ADD CONSTRAINT `anamnesis_disease_id_foreign` FOREIGN KEY (`disease_id`) REFERENCES `disease` (`id`);
30ALTER TABLE `anamnesis` ADD CONSTRAINT `anamnesis_patient_id_foreign` FOREIGN KEY (`patient_id`) REFERENCES `patient` (`id`);
31CREATE TABLE IF NOT EXISTS `disease` (
32 `id` int not null auto_increment,
33 `name` varchar(255) not null,
34 PRIMARY KEY (`id`)
35);
36CREATE TABLE IF NOT EXISTS `medicine` (
37 `id` int not null auto_increment,
38 `name` varchar(255) not null,
39 `active substance` varchar(255) not null,
40 PRIMARY KEY (`id`)
41);
42CREATE TABLE IF NOT EXISTS `side effects of medicine` (
43 `id` int not null auto_increment,
44 `friquently_scale` varchar(255) not null,
45 `side_effect_id` int not null,
46 `medicine_id` int not null,
47 PRIMARY KEY (`id`)
48);
49ALTER TABLE `side effects of medicine` ADD CONSTRAINT `side effects of medicine_side_effect_id_foreign` FOREIGN KEY (`side_effect_id`) REFERENCES `side effects` (`id`);
50ALTER TABLE `side effects of medicine` ADD CONSTRAINT `side effects of medicine_medicine_id_foreign` FOREIGN KEY (`medicine_id`) REFERENCES `medicine` (`id`);