-
Notifications
You must be signed in to change notification settings - Fork 0
/
script(novo).sql
194 lines (169 loc) · 6.47 KB
/
script(novo).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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
-- MySQL Script generated by MySQL Workbench
-- Fri May 19 11:50:17 2023
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `mydb` ;
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`lista_pacientes`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`lista_pacientes` ;
CREATE TABLE IF NOT EXISTS `mydb`.`lista_pacientes` (
`cpf` VARCHAR(11) NOT NULL,
`nome` VARCHAR(45) NOT NULL,
PRIMARY KEY (`cpf`))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`medico`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`medico` ;
CREATE TABLE IF NOT EXISTS `mydb`.`medico` (
`cpf` VARCHAR(11) NOT NULL,
`nome` VARCHAR(45) NOT NULL,
`telefone` VARCHAR(11) NOT NULL,
`dt_nasc` VARCHAR(11) NOT NULL,
`email` VARCHAR(45) NOT NULL,
`especialidade` VARCHAR(30) NOT NULL,
`hr_atendimento` VARCHAR(10) NOT NULL,
`crm` INT NOT NULL,
`qtd_vagas` INT NOT NULL,
`lista_pacientes_cpf` VARCHAR(11) NOT NULL,
PRIMARY KEY (`cpf`),
INDEX `fk_medico_lista_pacientes1_idx` (`lista_pacientes_cpf` ASC),
CONSTRAINT `fk_medico_lista_pacientes1`
FOREIGN KEY (`lista_pacientes_cpf`)
REFERENCES `mydb`.`lista_pacientes` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`guiche`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`guiche` ;
CREATE TABLE IF NOT EXISTS `mydb`.`guiche` (
`id_guiche` INT NOT NULL,
`status` VARCHAR(30) NOT NULL,
`paciente` VARCHAR(45) NOT NULL,
`senha` INT NOT NULL,
`paciente_cpf` VARCHAR(11) NOT NULL,
PRIMARY KEY (`id_guiche`),
INDEX `fk_guiche_paciente1_idx` (`paciente_cpf` ASC),
CONSTRAINT `fk_guiche_paciente1`
FOREIGN KEY (`paciente_cpf`)
REFERENCES `mydb`.`paciente` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`recepcionista`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`recepcionista` ;
CREATE TABLE IF NOT EXISTS `mydb`.`recepcionista` (
`cpf` VARCHAR(11) NOT NULL,
`nome` VARCHAR(45) NOT NULL,
`telefone` VARCHAR(11) NOT NULL,
`dt_nasc` VARCHAR(11) NOT NULL,
`email` VARCHAR(45) NOT NULL,
`guiche_id_guiche` INT NOT NULL,
PRIMARY KEY (`cpf`),
INDEX `fk_recepcionista_guiche1_idx` (`guiche_id_guiche` ASC),
CONSTRAINT `fk_recepcionista_guiche1`
FOREIGN KEY (`guiche_id_guiche`)
REFERENCES `mydb`.`guiche` (`id_guiche`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`consulta`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`consulta` ;
CREATE TABLE IF NOT EXISTS `mydb`.`consulta` (
`cpf_paciente` VARCHAR(11) NOT NULL,
`nome_paciente` VARCHAR(45) NOT NULL,
`dt_nasc` VARCHAR(11) NOT NULL,
`medico` VARCHAR(45) NOT NULL,
`crm` INT NOT NULL,
`tipo_consulta` VARCHAR(20) NOT NULL,
`hr_consulta` VARCHAR(10) NOT NULL,
`medico_cpf` VARCHAR(11) NOT NULL,
`recepcionista_cpf` VARCHAR(11) NOT NULL,
`lista_pacientes_cpf` VARCHAR(11) NOT NULL,
PRIMARY KEY (`cpf_paciente`),
INDEX `fk_consulta_medico1_idx` (`medico_cpf` ASC) ,
INDEX `fk_consulta_recepcionista1_idx` (`recepcionista_cpf` ASC) ,
INDEX `fk_consulta_lista_pacientes1_idx` (`lista_pacientes_cpf` ASC) ,
CONSTRAINT `fk_consulta_medico1`
FOREIGN KEY (`medico_cpf`)
REFERENCES `mydb`.`medico` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_consulta_recepcionista1`
FOREIGN KEY (`recepcionista_cpf`)
REFERENCES `mydb`.`recepcionista` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_consulta_lista_pacientes1`
FOREIGN KEY (`lista_pacientes_cpf`)
REFERENCES `mydb`.`lista_pacientes` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`paciente`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`paciente` ;
CREATE TABLE IF NOT EXISTS `mydb`.`paciente` (
`cpf` VARCHAR(11) NOT NULL,
`nome` VARCHAR(45) NOT NULL,
`telefone` VARCHAR(11) NOT NULL,
`dt_nasc` VARCHAR(11) NOT NULL,
`endereco` VARCHAR(45) NOT NULL,
`email` VARCHAR(45) NOT NULL,
`medico_cpf` VARCHAR(11) NOT NULL,
`consulta_cpf_paciente` VARCHAR(11) NOT NULL,
PRIMARY KEY (`cpf`),
INDEX `fk_paciente_medico_idx` (`medico_cpf` ASC),
INDEX `fk_paciente_consulta1_idx` (`consulta_cpf_paciente` ASC),
CONSTRAINT `fk_paciente_medico`
FOREIGN KEY (`medico_cpf`)
REFERENCES `mydb`.`medico` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_paciente_consulta1`
FOREIGN KEY (`consulta_cpf_paciente`)
REFERENCES `mydb`.`consulta` (`cpf_paciente`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`funcionarios`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`funcionarios` ;
CREATE TABLE IF NOT EXISTS `mydb`.`funcionarios` (
`cpf_funcionario` VARCHAR(11) NOT NULL,
`nome` VARCHAR(45) NOT NULL,
`telefone` VARCHAR(11) NOT NULL,
`dt_nasc` VARCHAR(11) NOT NULL,
`email` VARCHAR(45) NOT NULL,
`recepcionista_cpf` VARCHAR(11) NOT NULL,
PRIMARY KEY (`cpf_funcionario`),
INDEX `fk_funcionarios_recepcionista1_idx` (`recepcionista_cpf` ASC),
CONSTRAINT `fk_funcionarios_recepcionista1`
FOREIGN KEY (`recepcionista_cpf`)
REFERENCES `mydb`.`recepcionista` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;