-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdb_script.sql
More file actions
64 lines (55 loc) · 1.99 KB
/
Copy pathdb_script.sql
File metadata and controls
64 lines (55 loc) · 1.99 KB
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
create database unc_hospital;
use unc_hospital;
create table pessoa (
id int not null primary key AUTO_INCREMENT,
nome varchar(50),
rg int not null,
cpf varchar(14) not null,
sexo char(1) not null,
dtNascimento date not null,
telefone varchar(20)
);
create table paciente (
id int not null primary key AUTO_INCREMENT,
idPessoa int not null,
gravidade smallint
);
create table medico (
id int not null primary key AUTO_INCREMENT,
idPessoa int not null,
especialidade varchar(25)
);
create table enfermeiro (
id int not null primary key AUTO_INCREMENT,
idPessoa int not null,
dataAdmissao date not null
);
create table agenda (
id int not null primary key AUTO_INCREMENT,
dtAgenda date not null,
horario time not null,
idPaciente int not null
);
create table internacao (
id int not null primary key AUTO_INCREMENT,
idPaciente int not null,
horario time not null,
quarto varchar(10),
idPessoaAcompanhante int
);
create table servico (
id int not null primary key AUTO_INCREMENT,
descricao varchar(100),
idMedico int not null,
idPaciente int not null,
idEnfermeiro int not null
);
alter table paciente add constraint fk_pessoa_paciente foreign key (idPessoa) references pessoa(id);
alter table medico add constraint fk_pessoa_medico foreign key (idPessoa) references pessoa(id);
alter table enfermeiro add constraint fk_pessoa_enfermeiro foreign key (idPessoa) references pessoa(id);
alter table agenda add constraint fk_paciente_agenda foreign key (idPaciente) references paciente(id);
alter table internacao add constraint fk_paciente_internacao foreign key (idPaciente) references paciente(id);
alter table internacao add constraint fk_pessoa_internacao foreign key (idPessoaAcompanhante) references pessoa(id);
alter table servico add constraint fk_medico_servico foreign key (idMedico) references medico(id);
alter table servico add constraint fk_paciente_servico foreign key (idPaciente) references paciente(id);
alter table servico add constraint fk_enfermeiro_servico foreign key (idEnfermeiro) references enfermeiro(id);