Last active
August 30, 2023 15:17
-
-
Save sergiohdljr/46dc0480fddf11e8f11ed3fc875de74f to your computer and use it in GitHub Desktop.
Clinica banco de dados
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Criando Banco de Dados | |
mysql> CREATE DATABASE bd_clinica; | |
-- Usando Banco de Dados | |
mysql> USE bd_clinica; | |
-- Criando tabelas | |
mysql> CREATE TABLE tbl_Ambulatorios ( | |
-> nroa INT PRIMARY KEY, | |
-> andar NUMERIC(3) NOT NULL, | |
-> capacidade SMALLINT ); | |
mysql> CREATE TABLE tbl_Medicos ( | |
-> codm INT PRIMARY KEY, | |
-> nome VARCHAR(40) NOT NULL, | |
-> idade SMALLINT NOT NULL, | |
-> especialidade CHAR(20), | |
-> CPF NUMERIC(11) UNIQUE, | |
-> cidade VARCHAR(30), | |
-> nroa INT, | |
-> FOREIGN KEY (nroa) REFERENCES tbl_Ambulatorios(nroa)); | |
mysql> CREATE TABLE tbl_Pacientes ( | |
-> codp INT PRIMARY KEY, | |
-> nome VARCHAR(40) NOT NULL, | |
-> idade SMALLINT NOT NULL, | |
-> cidade CHAR(30), | |
-> CPF NUMERIC(11) UNIQUE, | |
-> doenca VARCHAR(40) NOT NULL | |
-> ); | |
mysql> CREATE TABLE tbl_Funcionarios ( | |
-> codf INT PRIMARY KEY, | |
-> nome VARCHAR(40) NOT NULL, | |
-> idade SMALLINT, | |
-> CPF NUMERIC(11) UNIQUE, | |
-> cidade VARCHAR(30), | |
-> salario NUMERIC(10), | |
-> cargo VARCHAR(20) | |
-> ); | |
mysql> CREATE TABLE tbl_Consultas ( | |
-> codm INT, | |
-> codp INT, | |
-> data DATE, | |
-> hora TIME, | |
-> PRIMARY KEY (codm, codp, data, hora), | |
-> FOREIGN KEY (codm) REFERENCES tbl_Medicos(codm), | |
-> FOREIGN KEY (codp) REFERENCES tbl_Pacientes(codp) | |
-> ); | |
--- Remover as colunas cargo e nroada tabela de Funcionarios | |
mysql> ALTER TABLE tbl_Funcionarios | |
-> ADD COLUMN nroa INT, | |
-> ADD CONSTRAINT fk_nroa FOREIGN KEY (nroa) REFERENCES tbl_Ambulatorios(nroa); | |
--- Crie os seguintes índices: - Medicos: CPF (único), Pacientes: doenca | |
mysql> CREATE UNIQUE INDEX idx_unique_CPF_Medicos ON tbl_Medicos (CPF); | |
mysql> CREATE INDEX idx_doenca_Pacientes ON tbl_Pacientes (doenca); | |
--- Remover o índice doencaemPacientes | |
mysql> DROP INDEX idx_doenca_Pacientes ON tbl_Pacientes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment