-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathnursery_create.sql
executable file
·67 lines (56 loc) · 1.98 KB
/
nursery_create.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
DROP DATABASE IF EXISTS Nursery;
CREATE DATABASE IF NOT EXISTS Nursery;
USE Nursery;
CREATE TABLE Nursery.baby (
id int AUTO_INCREMENT NOT NULL,
id_mother int NOT NULL,
id_doctor int NOT NULL,
name_baby varchar(60) NOT NULL,
date_baby date NOT NULL,
height_baby int NULL,
weight_baby int NULL,
CONSTRAINT baby_pk PRIMARY KEY (id)
);
CREATE TABLE Nursery.specializations (
id int AUTO_INCREMENT NOT NULL,
name_specialization varchar(60) NOT NULL,
CONSTRAINT specializations_pk PRIMARY KEY (id)
);
CREATE TABLE Nursery.mother (
id int AUTO_INCREMENT NOT NULL,
name_mother varchar(1500) NOT NULL,
street varchar(60) NULL,
streetnumber varchar(20) NULL,
zip char(8) NULL,
date_mother date NULL,
CONSTRAINT mother_pk PRIMARY KEY (id)
);
CREATE TABLE Nursery.doctor (
id int AUTO_INCREMENT NOT NULL,
register char(10) NOT NULL,
name varchar(60) NOT NULL,
id_specialization int NOT NULL,
CONSTRAINT doctor_pk PRIMARY KEY (id)
);
CREATE TABLE Nursery.phone_mother (
id int AUTO_INCREMENT NOT NULL,
id_mother int NOT NULL,
phone varchar(13) NOT NULL,
CONSTRAINT phone_mother_pk PRIMARY KEY (id)
);
CREATE TABLE Nursery.phone_doctor (
id int AUTO_INCREMENT NOT NULL,
id_doctor int NOT NULL,
phone varchar(13) NOT NULL,
CONSTRAINT phone_doctor_pk PRIMARY KEY (id)
);
ALTER TABLE baby ADD CONSTRAINT baby_mother FOREIGN KEY baby_mother (id_mother)
REFERENCES Nursery.mother (id);
ALTER TABLE baby ADD CONSTRAINT baby_doctor FOREIGN KEY baby_doctor (id_doctor)
REFERENCES Nursery.doctor (id);
ALTER TABLE doctor ADD CONSTRAINT doctor_specializations FOREIGN KEY doctor_specializations (id_specialization)
REFERENCES Nursery.specializations (id);
ALTER TABLE phone_mother ADD CONSTRAINT phone_mother FOREIGN KEY phone_mother (id_mother)
REFERENCES Nursery.mother (id);
ALTER TABLE phone_doctor ADD CONSTRAINT phone_doctor FOREIGN KEY phone_doctor (id_doctor)
REFERENCES Nursery.doctor (id);