Last active
August 29, 2015 14:10
-
-
Save edgarsandi/8444f3d81200a6818cbf to your computer and use it in GitHub Desktop.
INSERTS
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
-- Resposta do lab | |
-- tabela categorias | |
CREATE TABLE tb_categorias( | |
cd_categoria NUMBER(3) PRIMARY KEY, | |
nm_categoria VARCHAR2(50) NOT NULL | |
); | |
-- Tabela cursos | |
CREATE TABLE tb_cursos( | |
cd_curso NUMBER(5) PRIMARY KEY, | |
nm_curso VARCHAR2(50) NOT NULL, | |
vl_ch NUMBER(4), | |
cd_categoria NUMBER(3) REFERENCES tb_categorias(cd_categoria) | |
); | |
-- Tabela salas | |
CREATE TABLE tb_salas( | |
cd_sala CHAR(3) PRIMARY KEY, | |
nm_sala VARCHAR2(50) NOT NULL, | |
vl_capacidade NUMBER(3) NOT NULL | |
); | |
-- Tabela instrutores | |
CREATE TABLE tb_instrutores( | |
cd_instrutor NUMBER(3) PRIMARY KEY, | |
nm_instrutor VARCHAR2(50) NOT NULL | |
); | |
-- Tabela turmas | |
CREATE TABLE tb_turmas( | |
cd_turma NUMBER(6), | |
dt_inicio DATE NOT NULL, | |
dt_fim DATE NOT NULL, | |
tx_periodo CHAR(1) NOT NULL, | |
cd_instrutor NUMBER(3) REFERENCES tb_instrutores(cd_instrutor), | |
cd_curso NUMBER(3) REFERENCES tb_cursos(cd_curso), | |
cd_sala CHAR(3) REFERENCES tb_salas(cd_sala) | |
); | |
-- Adicionando PRIMARY KEY em uma tabela existente | |
ALTER TABLE tb_turmas | |
ADD CONSTRAINT pk_tb_turmas | |
PRIMARY KEY (cd_turma); | |
-- Tabela alunos | |
CREATE TABLE tb_alunos( | |
cd_aluno NUMBER(5) PRIMARY KEY, | |
nm_aluno VARCHAR2(50) NOT NULL, | |
tx_sexo CHAR(1) NOT NULL, | |
dt_nascimento DATE | |
); | |
-- Tabela inscrições | |
CREATE TABLE tb_incricoes( | |
cd_aluno NUMBER(5) REFERENCES tb_alunos(cd_aluno), | |
cd_turma NUMBER(5) REFERENCES tb_turmas(cd_turma), | |
dt_inscricao DATE NOT NULL, | |
vl_inscricao NUMBER(10, 2) NOT NULL, | |
PRIMARY KEY(cd_aluno, cd_turma) | |
); | |
INSERT ALL | |
INTO tb_categorias (cd_categoria, nm_categoria) VALUES (1,'Banco de dados') | |
INTO tb_categorias (cd_categoria, nm_categoria) VALUES (2,'Programação') | |
INTO tb_categorias (cd_categoria, nm_categoria) VALUES(3,'Design') | |
SELECT * FROM dual; | |
INSERT INTO tb_cursos VALUES(1,'Oracle Essencial',24,1); | |
INSERT INTO tb_cursos VALUES(2,'PHP',40,2); | |
INSERT INTO tb_cursos VALUES(3,'Oracle PL/SQL',24,3); | |
INSERT INTO tb_instrutores VALUES (1,'Ronaldo'); | |
INSERT INTO tb_instrutores VALUES (2,'João'); | |
INSERT INTO tb_instrutores VALUES (3,'Pedro'); | |
INSERT INTO tb_salas VALUES ('S01','Sala 01',8); | |
INSERT INTO tb_salas VALUES ('S02','Sala 02',12); | |
ALTER SESSION SET NLS_DATE_FORMAT='DD-MM-YYYY'; | |
SELECT CURRENT_DATE FROM dual; | |
INSERT INTO tb_alunos VALUES (1,'Marisa','F','27/03/1979'); | |
INSERT INTO tb_alunos VALUES (2,'Rosana','F','27/03/1979'); | |
INSERT INTO tb_alunos VALUES (3,'Carlos','M','15/06/1960'); | |
INSERT INTO tb_alunos VALUES (4,'Fabio','M','20/09/1985'); | |
INSERT INTO tb_alunos VALUES (5,'Fabiana','F','11/10/1986'); | |
INSERT INTO tb_alunos VALUES (6,'Ana','F','11/12/1975'); | |
INSERT INTO tb_alunos VALUES (7,'Clara','F','11/12/2000'); | |
INSERT INTO tb_alunos VALUES (8,'Henrique','M','10/07/1996'); | |
INSERT INTO tb_alunos VALUES (9,'Claudia','F','1/07/1993'); | |
INSERT INTO tb_alunos VALUES (10,'Marta','F','8/04/1997'); | |
INSERT INTO tb_turmas VALUES (1,'01/07/2008','10/10/2008','M',1,1,'S01'); | |
INSERT INTO tb_turmas VALUES (2,'01/05/2008','10/6/2008','T',2,1,'S02'); | |
INSERT INTO tb_turmas VALUES (3,'01/06/2008','10/8/2008','N',1,2,'S01'); | |
INSERT INTO tb_turmas VALUES (4,'05/10/2008','09/11/2008','N',2,3,'S01'); | |
INSERT INTO tb_turmas VALUES (5,'05/10/2008','09/11/2008','M',1,3,'S02'); | |
INSERT INTO tb_inscricoes VALUES (1,1,'10/05/2008',500); | |
INSERT INTO tb_inscricoes VALUES (2,3,'10/06/2008',800); | |
INSERT INTO tb_inscricoes VALUES (3,4,'10/07/2008',900); | |
INSERT INTO tb_inscricoes VALUES (4,2,'10/05/2008',500); | |
INSERT INTO tb_inscricoes VALUES (4,3,'10/06/2008',600); | |
INSERT INTO tb_inscricoes VALUES (5,5,'10/04/2008',700); | |
INSERT INTO tb_inscricoes VALUES (6,1,'10/03/2008',1000.50); | |
SELECT * FROM tb_categorias; | |
SELECT * FROM tb_cursos; | |
SELECT * FROM tb_turmas; | |
SELECT * FROM tb_instrutores; | |
SELECT * FROM tb_salas; | |
SELECT * FROM tb_inscricoes; | |
SELECT * FROM tb_alunos; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment