-
Notifications
You must be signed in to change notification settings - Fork 0
/
clin.sql
70 lines (58 loc) · 1.6 KB
/
clin.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
CREATE DATABASE clinica_medica;
USE clinica_medica;
CREATE TABLE consultorio (
idC INT PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(45),
sala INT NOT NULL,
endereco TEXT,
UF CHAR(2)
);
CREATE TABLE paciente (
cpfP INT PRIMARY KEY,
nome VARCHAR(45) NOT NULL,
data_nascimento DATE NOT NULL,
endereco TEXT,
idCP INT,
FOREIGN KEY (idCP) REFERENCES consultorio(idC)
);
CREATE TABLE doutor (
crm INT PRIMARY KEY,
cpfD CHAR(11) NOT NULL UNIQUE,
nome VARCHAR(45) NOT NULL,
data_nascimento DATE NOT NULL
);
CREATE TABLE receita_medica (
idRC INT PRIMARY KEY AUTO_INCREMENT,
idPRC INT,
idD INT,
data_emissao DATE NOT NULL,
medicamento VARCHAR(45),
CID VARCHAR(45),
FOREIGN KEY (idPRC) REFERENCES paciente(cpfP),
FOREIGN KEY (idD) REFERENCES doutor(crm)
);
CREATE TABLE especializacao (
idE INT PRIMARY KEY,
nome VARCHAR(45)
);
CREATE TABLE cons_dou (
idC INT,
idD INT,
PRIMARY KEY (idC,idD),
CONSTRAINT fk_cons_dou_consultorio FOREIGN KEY (idC) REFERENCES consultorio(idC),
CONSTRAINT fk_cons_dou_doutor FOREIGN KEY (idD) REFERENCES doutor(crm)
);
CREATE TABLE pasc_dou (
idP INT,
idD INT,
PRIMARY KEY(idP,idD),
CONSTRAINT fk_pasc_dou_paciente FOREIGN KEY (idP) REFERENCES paciente(cpfP),
CONSTRAINT fk_pasc_dou_doutor FOREIGN KEY (idD) REFERENCES doutor(crm)
);
CREATE TABLE doutor_especializacao (
idD INT,
idE INT,
PRIMARY KEY (idD,idE),
CONSTRAINT fk_dou_espe_doutor FOREIGN KEY (idD) REFERENCES doutor(crm),
CONSTRAINT fk_dou_espe_especializacao FOREIGN KEY (idE) REFERENCES especializacao(idE)
);