· 6 years ago · Nov 26, 2019, 11:32 PM
1set foreign_key_checks=0;
2
3create database if not exists dz08;
4
5use dz08;
6
7drop table if exists pacijent;
8create table if not exists pacijent (
9 pacijent_id int(11) not null auto_increment,
10 ime varchar(64) not null,
11 prezime varchar(64) not null,
12 jmbg varchar(13) not null unique,
13 adresa varchar(64) not null,
14 telefon varchar (32) not null,
15 constraint pacijent_pk primary key (pacijent_id),
16 doktor_id int(11)
17);
18describe pacijent;
19
20
21alter table pacijent add constraint foreign key (doktor_id) references doktor (doktor_id);
22
23
24drop table if exists doktor;
25create table if not exists doktor (
26 doktor_id int(11) not null auto_increment,
27 ime varchar(64) not null,
28 prezime varchar(64) not null,
29 jmbg varchar(13) not null unique,
30 spec varchar(32) not null,
31 constraint doktor_pk primary key (doktor_id)
32);
33describe doktor;
34
35
36drop table if exists medikament;
37create table if not exists medikament (
38 medikament_id int(11) auto_increment,
39 naziv varchar(64) not null,
40 proizvodjac varchar(64) not null,
41 sifra varchar(13) not null,
42 constraint medikament_pk primary key (medikament_id),
43 proizvodjac_id int(11)
44);
45describe medikament;
46
47
48alter table medikament add constraint foreign key (proizvodjac_id) references proizvodjac (proizvodjac_id);
49
50
51drop table if exists bolest;
52create table if not exists bolest (
53 bolest_id int(11) not null auto_increment,
54 naziv varchar(64) not null,
55 opis varchar(1024) not null,
56 slika blob not null,
57 constraint bolest_pk primary key (bolest_id)
58);
59
60drop table if exists proizvodjac;
61create table if not exists proizvodjac (
62 proizvodjac_id int(11) not null auto_increment,
63 naziv varchar(64) not null,
64 adresa varchar(64) not null,
65 telefon varchar(32) not null,
66 constraint proizvodjac_pk primary key (proizvodjac_id)
67);
68describe proizvodjac;
69
70
71drop table if exists boluje_od;
72create table if not exists boluje_od (
73 boluje_od_id int(11) not null auto_increment,
74 datum_dijagnoze varchar(32) not null,
75 constraint boluje_od_pk primary key (boluje_od_id),
76 pacijent_id int(11),
77 bolest_id int(11)
78);
79describe boluje_od;
80
81alter table boluje_od add constraint foreign key (pacijent_id) references pacijent (pacijent_id);
82alter table boluje_od add constraint foreign key (bolest_id) references bolest (bolest_id);
83
84alter table bolest drop slika;
85describe bolest;
86
87alter table doktor add legitimacija varchar(16) unique after jmbg;
88describe doktor;
89
90drop table if exists izabrani_doktor;
91create table if not exists izabrani_doktor (
92 izabrani_doktor_id integer(11) auto_increment,
93 constraint izabrani_doktor_pk primary key (izabrani_doktor_id),
94 doktor_id integer(11),
95 pacijent_id integer(11),
96 constraint foreign key (doktor_id) references doktor(doktor_id),
97 constraint foreign key (pacijent_id) references pacijent(pacijent_id)
98);
99
100drop table if exists pregled;
101create table if not exists pregled (
102 pregled_id integer(11) auto_increment,
103 constraint pregled_pk primary key (pregled_id),
104 datum datetime,
105 doktor_id integer(11),
106 pacijent_id integer(11),
107 constraint foreign key (doktor_id) references doktor(doktor_id),
108 constraint foreign key (pacijent_id) references pacijent(pacijent_id)
109);
110
111drop table if exists terapija;
112create table if not exists terapija (
113 terapija_id integer(11) auto_increment,
114 constraint terapija_pk primary key (terapija_id),
115 opis varchar(4096),
116 datum datetime,
117 trajanje integer(3),
118 doktor_id integer(11),
119 pacijent_id integer(11),
120 constraint foreign key (doktor_id) references doktor(doktor_id),
121 constraint foreign key (pacijent_id) references pacijent(pacijent_id)
122);
123
124set foreign_key_checks=1;