-
Notifications
You must be signed in to change notification settings - Fork 0
/
clinica.sql
198 lines (157 loc) · 6.21 KB
/
clinica.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
195
196
197
198
-- MySQL Script generated by MySQL Workbench
-- Thu Jun 1 23:11:28 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 `clinica` ;
-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `clinica` DEFAULT CHARACTER SET utf8 ;
USE `clinica`;
-- -----------------------------------------------------
-- Table `mydb`.`lista_pacientes`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `clinica`.`lista_pacientes` ;
CREATE TABLE IF NOT EXISTS `clinica`.`lista_pacientes` (
`id_paciente` INT NOT NULL AUTO_INCREMENT,
`cpf` VARCHAR(11) NOT NULL,
`nome` VARCHAR(45) NOT NULL,
`medico_cpf` VARCHAR(11) NOT NULL,
PRIMARY KEY (`id_paciente`),
FOREIGN KEY (`medico_cpf`)
REFERENCES `clinica`.`medico` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
INSERT INTO lista_pacientes(cpf,nome,medico_cpf) VALUES('4','dudu','1');
SELECT * FROM lista_pacientes;
DELETE FROM lista_pacientes WHERE cpf = '6';
-- -----------------------------------------------------
-- Table `mydb`.`medico`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `clinica`.`medico` ;
CREATE TABLE IF NOT EXISTS `clinica`.`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,
`senha` VARCHAR(45) NOT NULL,
PRIMARY KEY (`cpf`))
ENGINE = InnoDB;
SELECT * FROM medico;
DELETE FROM medico WHERE cpf = '33';
UPDATE medico SET qtd_vagas = 12 WHERE cpf = '2';
-- -----------------------------------------------------
-- Table `mydb`.`guiche`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `clinica`.`guiche` ;
CREATE TABLE IF NOT EXISTS `clinica`.`guiche` (
`id_guiche` INT NOT NULL AUTO_INCREMENT,
`status` VARCHAR(30) NOT NULL,
`senha` INT NOT NULL,
`modo` VARCHAR(20) NOT NULL,
`recepcionista_cpf` VARCHAR(11) NOT NULL,
PRIMARY KEY (`id_guiche`),
FOREIGN KEY (`recepcionista_cpf`)
REFERENCES `clinica`.`recepcionista`(`cpf`))
ENGINE = InnoDB;
select * from guiche;
INSERT INTO guiche(status,senha,modo,recepcionista_cpf) VALUES('livre',0,'ativo','1');
UPDATE guiche SET status = 'livre' WHERE id_guiche = 1;
-- -----------------------------------------------------
-- Table `mydb`.`recepcionista`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `clinica`.`recepcionista` ;
CREATE TABLE IF NOT EXISTS `clinica`.`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,
`senha` VARCHAR(45) NOT NULL,
PRIMARY KEY (`cpf`))
ENGINE = InnoDB;
ALTER TABLE recepcionista DROP FOREIGN KEY fk_recepcionista_guiche1;
INSERT INTO recepcionista(cpf,nome,telefone,dt_nasc,email,senha) VALUES('3','3','3','3','3','3');
SELECT * FROM recepcionista;
DELETE FROM recepcionista WHERE cpf= '5';
-- -----------------------------------------------------
-- Table `mydb`.`consulta`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `clinica`.`consulta`;
CREATE TABLE IF NOT EXISTS `clinica`.`consulta` (
`id_consulta` INT NOT NULL AUTO_INCREMENT,
`cpf_paciente` VARCHAR(11) NOT NULL,
`nome_paciente` VARCHAR(45) NOT NULL,
`telefone` VARCHAR(20) NOT NULL,
`dt_nasc` VARCHAR(11) NOT NULL,
`medico` VARCHAR(45) NOT NULL,
`crm` INT NOT NULL,
`tipo_consulta` VARCHAR(20) NOT NULL,
`medico_cpf` VARCHAR(11) NOT NULL,
`recepcionista_cpf` VARCHAR(11) NOT NULL,
PRIMARY KEY (`id_consulta`),
INDEX `fk_consulta_medico1_idx` (`medico_cpf` ASC),
INDEX `fk_consulta_recepcionista1_idx` (`recepcionista_cpf` ASC) ,
CONSTRAINT `fk_consulta_medico1`
FOREIGN KEY (`medico_cpf`)
REFERENCES `clinica`.`medico` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_consulta_recepcionista1`
FOREIGN KEY (`recepcionista_cpf`)
REFERENCES `clinica`.`recepcionista` (`cpf`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
ALTER TABLE consulta DROP FOREIGN KEY fk_consulta_recepcionista1;
SELECT * FROM consulta;
delete FROM consulta WHERE id_consulta = 2;
-- -----------------------------------------------------
-- Table `mydb`.`paciente`
-- -----------------------------------------------------
-- DROP TABLE IF EXISTS `clinica`.`paciente` ;
-- CREATE TABLE IF NOT EXISTS `clinica`.`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 `clinica`.`medico` (`cpf`)
-- ON DELETE NO ACTION
-- ON UPDATE NO ACTION)
-- ENGINE = InnoDB;
--
-- -----------------------------------------------------
-- Table `mydb`.`admin`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `clinica`.`admin` ;
CREATE TABLE IF NOT EXISTS `clinica`.`admin` (
`cpf_admin` VARCHAR(11) NOT NULL,
`nome` VARCHAR(45) NOT NULL,
`senha` VARCHAR(11) NOT NULL,
PRIMARY KEY (`cpf_admin`))
ENGINE = InnoDB;
INSERT INTO admin(cpf_admin,nome,senha) VALUES('1','luis','1');
SELECT * FROM admin;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;