initial commit
191
doc/Informe/e1/Informe1.tex
Normal file
@@ -0,0 +1,191 @@
|
||||
\documentclass[12pt]{article}
|
||||
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[spanish]{babel}
|
||||
\usepackage{array}
|
||||
\usepackage{adjustbox}
|
||||
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{verbatim}
|
||||
\usepackage{courier}
|
||||
|
||||
\usepackage{listings}
|
||||
\usepackage{xcolor}
|
||||
|
||||
\lstdefinestyle{freefempp}{
|
||||
language=SQL,
|
||||
basicstyle=\footnotesize\ttfamily,
|
||||
commentstyle=\itshape\color{gray},
|
||||
keywordstyle=\color{blue},
|
||||
numberstyle=\color{red},
|
||||
stringstyle=\color{red},
|
||||
identifierstyle=\color{violet},
|
||||
showstringspaces=false,
|
||||
%float,
|
||||
%frame=single,
|
||||
%numbers=left
|
||||
}
|
||||
|
||||
\lstset{
|
||||
basicstyle=\footnotesize\ttfamily,
|
||||
columns=flexible,
|
||||
breaklines=true,
|
||||
style=freefempp
|
||||
}
|
||||
|
||||
\usepackage{titling}
|
||||
\renewcommand\maketitlehooka{\null\mbox{}\vfill}
|
||||
\renewcommand\maketitlehookd{\vfill\null}
|
||||
|
||||
\usepackage{hyperref}
|
||||
\hypersetup{colorlinks=true,allcolors=black}
|
||||
\usepackage{hypcap}
|
||||
|
||||
\title{\textbf{Proyecto Semestral de Base de Datos\\Entrega 1}}
|
||||
\author{Christopher Cromer\\\\Profesoras Mónica Caniupán y Valeria Beratto\\Ingeniería Civil Informática}
|
||||
\date{\today}
|
||||
|
||||
\pretitle{%
|
||||
\begin{center}
|
||||
\LARGE
|
||||
\includegraphics[width=4cm]{ubblogo.png}\\[\bigskipamount]
|
||||
}
|
||||
|
||||
\posttitle{\end{center}}
|
||||
|
||||
\begin{document}
|
||||
\clearpage
|
||||
\hypersetup{pageanchor=false}
|
||||
\begin{titlingpage}
|
||||
\maketitle
|
||||
\end{titlingpage}
|
||||
\thispagestyle{empty}
|
||||
|
||||
\newpage
|
||||
|
||||
\clearpage
|
||||
\thispagestyle{empty}
|
||||
\tableofcontents
|
||||
|
||||
\newpage
|
||||
\hypersetup{pageanchor=true}
|
||||
\pagenumbering{arabic}
|
||||
\section{Introducción}
|
||||
El objetivo de este trabajo es modelar un sistema para los colegios municipales de la región del Bío-Bío con el propósito de almacenar y consultar en una base de datos de PostgreSQL con información el colegio.
|
||||
|
||||
\newpage
|
||||
\section{Modelo Entidad Relación}
|
||||
\begin{center}
|
||||
\includegraphics[angle=270,origin=c,width=0.90\textwidth,height=0.90\textheight,keepaspectratio]{MER.png}
|
||||
\end{center}
|
||||
|
||||
\newpage
|
||||
\section{Modelo Relacional}
|
||||
\begin{center}
|
||||
En negrita se presentan las claves foráneas y las primarias en subrayado.\smallskip
|
||||
\end{center}
|
||||
region(\underline{id\_region}, nombre)\bigskip
|
||||
|
||||
\noindent
|
||||
ciudad(\underline{id\_ciudad}, nombre, \textbf{id\_region})\bigskip
|
||||
|
||||
\noindent
|
||||
apoderado(\underline{rut\_apoderado}, nombres, apellidos, direccion, \textbf{id\_ciudad})\bigskip
|
||||
|
||||
\noindent
|
||||
alumno(\underline{rut\_alumno}, nombres, apellidos, direccion, \textbf{id\_ciudad}, anyo\_ingreso, fecha\_nacimiento, \textbf{rut\_apoderado})\bigskip
|
||||
|
||||
\noindent
|
||||
profesor(\underline{rut\_profesor}, nombres, apellidos, direccion, \textbf{id\_ciudad})\bigskip
|
||||
|
||||
\noindent
|
||||
actividad(\underline{id\_actividad}, nombre, cupos, lugar, \textbf{rut\_profesor})\bigskip
|
||||
|
||||
\noindent
|
||||
nivel(\underline{id\_nivel}, nombre)\bigskip
|
||||
|
||||
\noindent
|
||||
bloque(\underline{id\_bloque}, descripcion)\bigskip
|
||||
|
||||
\noindent
|
||||
curso(\underline{id\_curso}, \textbf{rut\_profesor})\bigskip
|
||||
|
||||
\noindent
|
||||
asignatura(\underline{id\_asignatura}, nombre, \textbf{rut\_profesor})\bigskip
|
||||
|
||||
\noindent
|
||||
participar(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_actividad}})\bigskip
|
||||
|
||||
\noindent
|
||||
actividad\_nivel(\textbf{\underline{id\_actividad}}, \textbf{\underline{id\_nivel}})\bigskip
|
||||
|
||||
\noindent
|
||||
actividad\_bloque(\textbf{\underline{id\_actividad}}, \textbf{\underline{id\_bloque}})\bigskip
|
||||
|
||||
\noindent
|
||||
horario(\textbf{\underline{id\_asignatura}}, \textbf{\underline{id\_bloque}}, sala)\bigskip
|
||||
|
||||
\noindent
|
||||
registro(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_asignatura}}, nota)\bigskip
|
||||
|
||||
\noindent
|
||||
cursar(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_curso}})\bigskip
|
||||
|
||||
\noindent
|
||||
asociado(\textbf{\underline{id\_curso}}, \textbf{\underline{id\_asignatura}})\bigskip
|
||||
|
||||
\noindent
|
||||
asistente(\textbf{\underline{rut\_profesor}}, \textbf{\underline{id\_curso}})\bigskip
|
||||
|
||||
\newpage
|
||||
\section{Justificación de Modelo Relacional}
|
||||
|
||||
\textbf{\textit{region}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{ciudad}} adquiere la clave foránea \textbf{\textit{id\_region}} debido a que la relación entre las entidades \textbf{\textit{ciudad}} y \textbf{\textit{region}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{apoderado}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{apoderado}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{alumno}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{alumno}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}. También recibe la clave foránea \textbf{rut\_apoderado} debido a la relación entre las entidades \textbf{alumno} y \textbf{apoderado} que es de \textbf{n a 1}.\bigskip
|
||||
|
||||
\textbf{\textit{profesor}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{profesor}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{actividad}} adquiere la clave foránea \textbf{\textit{rut\_profesor}} debido a que las relaciones entre las otras entidades \textbf{\textit{actividad}} y \textbf{\textit{profesor}} es de \textbf{\textit{1 a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{nivel}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{bloque}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{curso}} adquiere la clave foránea \textbf{\textit{rut}} debido a que las relaciones entre las entidades \textbf{\textit{curso}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{asignatura}} adquiere la clave foránea \textbf{\textit{rut\_profesor}} debido a que la relación entre las entidades \textbf{\textit{asignatura}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{participar}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_actividad}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{actividad}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{actividad\_nivel}} es creado con las claves foráneas \textbf{\textit{id\_actividad}} y \textbf{\textit{id\_nivel}} dado que la relación entre \textbf{\textit{actividad}} y \textbf{\textit{nivel}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{actividad\_bloque}} es creado con las claves foráneas \textbf{\textit{id\_actividad}} y \textbf{\textit{id\_bloque}} dado que la relación entre \textbf{\textit{actividad}} y \textbf{\textit{bloque}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{horario}} es creado con las claves foráneas \textbf{\textit{id\_asignatura}} y \textbf{\textit{id\_bloque}}, y queda con el atributo \textbf{\textit{sala}} dado que la relación entre \textbf{\textit{asignatura}} y \textbf{\textit{bloque}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{registro}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_asignatura}}, y queda con el atributo \textbf{\textit{nota}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{asignatura}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{cursar}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_curso}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{curso}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{asociado}} es creado con las claves foráneas \textbf{\textit{id\_curso}} y \textbf{\textit{id\_asignatura}} dado que la relación entre \textbf{\textit{curso}} y \textbf{\textit{asignatura}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{asistente}} es creado opcionalmente con las claves foráneas \textbf{\textit{rut\_profesor}} y \textbf{\textit{id\_curso}} dado que la relación entre \textbf{\textit{curso}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1 con mínimo de 0}}.\bigskip
|
||||
|
||||
\newpage
|
||||
\section{Script SQL}
|
||||
|
||||
\subsection{Crear tablas}
|
||||
|
||||
\lstinputlisting{crear_tablas.sql}
|
||||
|
||||
\newpage
|
||||
\subsection{Insertar duplas}
|
||||
|
||||
\lstinputlisting{insertar_duplas.sql}
|
||||
|
||||
\end{document}
|
BIN
doc/Informe/e1/MER.dia
Normal file
BIN
doc/Informe/e1/MER.png
Normal file
After Width: | Height: | Size: 54 KiB |
150
doc/Informe/e1/crear_tablas.sql
Normal file
@@ -0,0 +1,150 @@
|
||||
CREATE TABLE region(
|
||||
id_region SMALLSERIAL UNIQUE,
|
||||
nombre_region VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_region)
|
||||
);
|
||||
|
||||
CREATE TABLE ciudad(
|
||||
id_ciudad SMALLSERIAL UNIQUE,
|
||||
nombre_ciudad VARCHAR(20) NOT NULL,
|
||||
id_region SMALLINT,
|
||||
PRIMARY KEY (id_ciudad),
|
||||
FOREIGN KEY (id_region) REFERENCES region (id_region) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE apoderado(
|
||||
rut_apoderado VARCHAR(9) NOT NULL UNIQUE CHECK (rut_apoderado ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
PRIMARY KEY (rut_apoderado),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE alumno(
|
||||
rut_alumno VARCHAR(9) NOT NULL UNIQUE CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
anyo_ingreso SMALLINT CHECK (anyo_ingreso > 1980),
|
||||
fecha_nacimiento DATE NOT NULL CHECK (fecha_nacimiento > '1980-01-01'),
|
||||
rut_apoderado VARCHAR(9) NOT NULL CHECK (rut_apoderado ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (rut_alumno),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (rut_apoderado) REFERENCES apoderado (rut_apoderado) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE profesor(
|
||||
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
PRIMARY KEY (rut_profesor),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad(
|
||||
id_actividad SERIAL UNIQUE,
|
||||
nombre VARCHAR(50) NOT NULL,
|
||||
cupos SMALLINT CHECK (cupos > 0),
|
||||
lugar VARCHAR(20) NOT NULL,
|
||||
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_actividad),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE nivel(
|
||||
id_nivel SERIAL UNIQUE,
|
||||
nombre VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_nivel)
|
||||
);
|
||||
|
||||
CREATE TABLE bloque(
|
||||
id_bloque SERIAL UNIQUE,
|
||||
descripcion VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_bloque)
|
||||
);
|
||||
|
||||
CREATE TABLE curso(
|
||||
id_curso VARCHAR(10) NOT NULL UNIQUE,
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_curso),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asignatura(
|
||||
id_asignatura SERIAL UNIQUE,
|
||||
nombre VARCHAR(50) NOT NULL,
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_asignatura),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE participar(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_actividad INT,
|
||||
PRIMARY KEY (rut_alumno, id_actividad),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad_nivel(
|
||||
id_actividad INT,
|
||||
id_nivel INT,
|
||||
PRIMARY KEY (id_actividad, id_nivel),
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_nivel) REFERENCES nivel (id_nivel) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad_bloque(
|
||||
id_actividad INT,
|
||||
id_bloque INT,
|
||||
PRIMARY KEY (id_actividad, id_bloque),
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE horario(
|
||||
id_asignatura INT,
|
||||
id_bloque INT,
|
||||
sala VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_asignatura, id_bloque),
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE registro(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_asignatura INT,
|
||||
nota NUMERIC(2,1) CHECK (nota >= 1.0 AND nota <= 7.0),
|
||||
PRIMARY KEY (rut_alumno, id_asignatura),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE cursar(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
PRIMARY KEY (rut_alumno, id_curso),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asociado(
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
id_asignatura INT,
|
||||
PRIMARY KEY (id_curso, id_asignatura),
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asistente(
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
PRIMARY KEY (rut_profesor, id_curso),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
|
||||
);
|
71
doc/Informe/e1/insertar_duplas.sql
Normal file
@@ -0,0 +1,71 @@
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (1, 'Florida');
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (2, 'Alabama');
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (3, 'Virginia');
|
||||
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (1, 'Pensacola', 1);
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (2, 'Montgomery', 2);
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (3, 'Virginia Beach', 3);
|
||||
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('14592927k', 'Christopher Barry', 'Cromer', '214 Edison Dr.', 1);
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192186099', 'Elia Alejandra', 'Chacano Troncoso', 'Avenida San Sebastian 778', 2);
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192199859', 'Jack', 'Johnson', '320 Thomas Jefferson St.', 3);
|
||||
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('254049492', 'Izabella Lynn', 'Cromer Chacano', '214 Edison Dr.', 2019, '2019-10-04', '14592927k', 1);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('245191391', 'Tomas', 'Bunt', 'Avenida San Sebastian 778', 2018, '2010-02-05', '192186099', 2);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('18028642k', 'Tom', 'Riddle', '320 Thomas Jefferson St.', 2017, '2014-12-31', '192199859', 3);
|
||||
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226174788', 'Severus', 'Snape', '232 Jackson Ave.', 1);
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226779329', 'Minerva', 'McGonagall', '333 Nottingham Ln.', 2);
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('139414853', 'Albus', 'Dumbledore', '8450 Sparrow Rd.', 3);
|
||||
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (1, 'Quidditch', 14, 'Quidditch field', '226174788');
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (2, 'Ogre taming', 5, 'The forbidden forest', '226779329');
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (3, 'Advanced transfiguration', 2, 'Headmaster''s office', '139414853');
|
||||
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (1, 'First');
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (2, 'Second');
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (3, 'Third');
|
||||
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (1, '08:10 - 09:30');
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (2, '09:40 - 11:00');
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (3, '11:10 - 12:30');
|
||||
|
||||
INSERT INTO curso (id_curso, rut_profesor) VALUES ('1A-2017', '226174788');
|
||||
INSERT INTO curso (id_curso, rut_profesor) VALUES ('2B-2018', '226779329');
|
||||
INSERT INTO curso (id_curso, rut_profesor) VALUES ('3C-2019', '139414853');
|
||||
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (1, 'Transfiguration', '226779329');
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (2, 'Defense against the dark arts', '226174788');
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (3, 'Muggle studies', '139414853');
|
||||
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('254049492', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('245191391', 2);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('18028642k', 3);
|
||||
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (1, 1);
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (2, 2);
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (3, 3);
|
||||
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (1, 1);
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (2, 2);
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (3, 3);
|
||||
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (1, 1, '203AC');
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (2, 2, '301AB');
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (3, 3, '102AA');
|
||||
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('254049492', 1, 7.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('245191391', 2, 4.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('18028642k', 3, 1.0);
|
||||
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('254049492', '1A-2017');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('245191391', '2B-2018');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('18028642k', '3C-2019');
|
||||
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('1A-2017', 1);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('2B-2018', 2);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('3C-2019', 3);
|
||||
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('139414853', '1A-2017');
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226174788', '2B-2018');
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226779329', '3C-2019');
|
BIN
doc/Informe/e1/ubblogo.png
Normal file
After Width: | Height: | Size: 185 KiB |
194
doc/Informe/e1corregido/Informe1.tex
Normal file
@@ -0,0 +1,194 @@
|
||||
\documentclass[12pt]{article}
|
||||
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[spanish]{babel}
|
||||
\usepackage{array}
|
||||
\usepackage{adjustbox}
|
||||
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{verbatim}
|
||||
\usepackage{courier}
|
||||
|
||||
\usepackage{listings}
|
||||
\usepackage{xcolor}
|
||||
|
||||
\lstdefinestyle{freefempp}{
|
||||
language=SQL,
|
||||
basicstyle=\footnotesize\ttfamily,
|
||||
commentstyle=\itshape\color{gray},
|
||||
keywordstyle=\color{blue},
|
||||
numberstyle=\color{red},
|
||||
stringstyle=\color{red},
|
||||
identifierstyle=\color{violet},
|
||||
showstringspaces=false,
|
||||
%float,
|
||||
%frame=single,
|
||||
%numbers=left
|
||||
}
|
||||
|
||||
\lstset{
|
||||
basicstyle=\footnotesize\ttfamily,
|
||||
columns=flexible,
|
||||
breaklines=true,
|
||||
inputencoding=utf8,
|
||||
extendedchars=true,
|
||||
literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {ñ}{{\~n}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {Ñ}{{\~N}}1,
|
||||
style=freefempp
|
||||
}
|
||||
|
||||
\usepackage{titling}
|
||||
\renewcommand\maketitlehooka{\null\mbox{}\vfill}
|
||||
\renewcommand\maketitlehookd{\vfill\null}
|
||||
|
||||
\usepackage{hyperref}
|
||||
\hypersetup{colorlinks=true,allcolors=black}
|
||||
\usepackage{hypcap}
|
||||
|
||||
\title{\textbf{Proyecto Semestral de Base de Datos\\Entrega 1 Corregido}}
|
||||
\author{Christopher Cromer\\\\Profesoras Mónica Caniupán y Valeria Beratto\\Ingeniería Civil Informática}
|
||||
\date{\today}
|
||||
|
||||
\pretitle{%
|
||||
\begin{center}
|
||||
\LARGE
|
||||
\includegraphics[width=4cm]{ubblogo.png}\\[\bigskipamount]
|
||||
}
|
||||
|
||||
\posttitle{\end{center}}
|
||||
|
||||
\begin{document}
|
||||
\clearpage
|
||||
\hypersetup{pageanchor=false}
|
||||
\begin{titlingpage}
|
||||
\maketitle
|
||||
\end{titlingpage}
|
||||
\thispagestyle{empty}
|
||||
|
||||
\newpage
|
||||
|
||||
\clearpage
|
||||
\thispagestyle{empty}
|
||||
\tableofcontents
|
||||
|
||||
\newpage
|
||||
\hypersetup{pageanchor=true}
|
||||
\pagenumbering{arabic}
|
||||
\section{Introducción}
|
||||
El objetivo de este trabajo es modelar un sistema para los colegios municipales de la región del Bío-Bío con el propósito de almacenar y consultar en una base de datos de PostgreSQL con información el colegio.
|
||||
|
||||
\newpage
|
||||
\section{Modelo Entidad Relación}
|
||||
\begin{center}
|
||||
\includegraphics[angle=270,origin=c,width=0.90\textwidth,height=0.90\textheight,keepaspectratio]{MER.png}
|
||||
\end{center}
|
||||
|
||||
\newpage
|
||||
\section{Modelo Relacional}
|
||||
\begin{center}
|
||||
En negrita se presentan las claves foráneas y las primarias en subrayado.\smallskip
|
||||
\end{center}
|
||||
region(\underline{id\_region}, nombre)\bigskip
|
||||
|
||||
\noindent
|
||||
ciudad(\underline{id\_ciudad}, nombre, \textbf{id\_region})\bigskip
|
||||
|
||||
\noindent
|
||||
apoderado(\underline{rut\_apoderado}, nombres, apellidos, direccion, \textbf{id\_ciudad})\bigskip
|
||||
|
||||
\noindent
|
||||
alumno(\underline{rut\_alumno}, nombres, apellidos, direccion, \textbf{id\_ciudad}, anyo\_ingreso, fecha\_nacimiento, \textbf{rut\_apoderado})\bigskip
|
||||
|
||||
\noindent
|
||||
profesor(\underline{rut\_profesor}, nombres, apellidos, direccion, \textbf{id\_ciudad})\bigskip
|
||||
|
||||
\noindent
|
||||
actividad(\underline{id\_actividad}, nombre, cupos, lugar, \textbf{rut\_profesor})\bigskip
|
||||
|
||||
\noindent
|
||||
nivel(\underline{id\_nivel}, nombre)\bigskip
|
||||
|
||||
\noindent
|
||||
bloque(\underline{id\_bloque}, descripcion)\bigskip
|
||||
|
||||
\noindent
|
||||
curso(\underline{id\_curso}, nombre, anyo, \textbf{rut\_profesor})\bigskip
|
||||
|
||||
\noindent
|
||||
asignatura(\underline{id\_asignatura}, nombre, \textbf{rut\_profesor})\bigskip
|
||||
|
||||
\noindent
|
||||
participar(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_actividad}})\bigskip
|
||||
|
||||
\noindent
|
||||
actividad\_nivel(\textbf{\underline{id\_actividad}}, \textbf{\underline{id\_nivel}})\bigskip
|
||||
|
||||
\noindent
|
||||
actividad\_bloque(\textbf{\underline{id\_actividad}}, \textbf{\underline{id\_bloque}})\bigskip
|
||||
|
||||
\noindent
|
||||
horario(\textbf{\underline{id\_asignatura}}, \textbf{\underline{id\_bloque}}, sala)\bigskip
|
||||
|
||||
\noindent
|
||||
registro(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_asignatura}}, nota)\bigskip
|
||||
|
||||
\noindent
|
||||
cursar(\textbf{\underline{rut\_alumno}}, \textbf{\underline{id\_curso}})\bigskip
|
||||
|
||||
\noindent
|
||||
asociado(\textbf{\underline{id\_curso}}, \textbf{\underline{id\_asignatura}})\bigskip
|
||||
|
||||
\noindent
|
||||
asistente(\textbf{\underline{rut\_profesor}}, \textbf{\underline{id\_curso}})\bigskip
|
||||
|
||||
\newpage
|
||||
\section{Justificación de Modelo Relacional}
|
||||
|
||||
\textbf{\textit{region}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{ciudad}} adquiere la clave foránea \textbf{\textit{id\_region}} debido a que la relación entre las entidades \textbf{\textit{ciudad}} y \textbf{\textit{region}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{apoderado}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{apoderado}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{alumno}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{alumno}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}. También recibe la clave foránea \textbf{rut\_apoderado} debido a la relación entre las entidades \textbf{alumno} y \textbf{apoderado} que es de \textbf{n a 1}.\bigskip
|
||||
|
||||
\textbf{\textit{profesor}} adquiere la clave foránea \textbf{\textit{id\_ciudad}} debido a que la relación entre las entidades \textbf{\textit{profesor}} y \textbf{\textit{ciudad}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{actividad}} adquiere la clave foránea \textbf{\textit{rut\_profesor}} debido a que las relaciones entre las otras entidades \textbf{\textit{actividad}} y \textbf{\textit{profesor}} es de \textbf{\textit{1 a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{nivel}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{bloque}} no adquiere ninguna clave foránea debido a que las relaciones entre las otras entidades son de \textbf{\textit{1 a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{curso}} adquiere la clave foránea \textbf{\textit{rut}} debido a que las relaciones entre las entidades \textbf{\textit{curso}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{asignatura}} adquiere la clave foránea \textbf{\textit{rut\_profesor}} debido a que la relación entre las entidades \textbf{\textit{asignatura}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1}}.\bigskip
|
||||
|
||||
\textbf{\textit{participar}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_actividad}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{actividad}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{actividad\_nivel}} es creado con las claves foráneas \textbf{\textit{id\_actividad}} y \textbf{\textit{id\_nivel}} dado que la relación entre \textbf{\textit{actividad}} y \textbf{\textit{nivel}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{actividad\_bloque}} es creado con las claves foráneas \textbf{\textit{id\_actividad}} y \textbf{\textit{id\_bloque}} dado que la relación entre \textbf{\textit{actividad}} y \textbf{\textit{bloque}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{horario}} es creado con las claves foráneas \textbf{\textit{id\_asignatura}} y \textbf{\textit{id\_bloque}}, y queda con el atributo \textbf{\textit{sala}} dado que la relación entre \textbf{\textit{asignatura}} y \textbf{\textit{bloque}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{registro}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_asignatura}}, y queda con el atributo \textbf{\textit{nota}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{asignatura}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{cursar}} es creado con las claves foráneas \textbf{\textit{rut\_alumno}} y \textbf{\textit{id\_curso}} dado que la relación entre \textbf{\textit{alumno}} y \textbf{\textit{curso}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{asociado}} es creado con las claves foráneas \textbf{\textit{id\_curso}} y \textbf{\textit{id\_asignatura}} dado que la relación entre \textbf{\textit{curso}} y \textbf{\textit{asignatura}} es de \textbf{\textit{n a n}}.\bigskip
|
||||
|
||||
\textbf{\textit{asistente}} es creado opcionalmente con las claves foráneas \textbf{\textit{rut\_profesor}} y \textbf{\textit{id\_curso}} dado que la relación entre \textbf{\textit{curso}} y \textbf{\textit{profesor}} es de \textbf{\textit{n a 1 con mínimo de 0}}.\bigskip
|
||||
|
||||
\newpage
|
||||
\section{Script SQL}
|
||||
|
||||
\subsection{Crear tablas}
|
||||
|
||||
\lstinputlisting{crear_tablas.sql}
|
||||
|
||||
\newpage
|
||||
\subsection{Insertar duplas}
|
||||
|
||||
\lstinputlisting{insertar_duplas.sql}
|
||||
|
||||
\end{document}
|
BIN
doc/Informe/e1corregido/MER.dia
Normal file
BIN
doc/Informe/e1corregido/MER.png
Normal file
After Width: | Height: | Size: 56 KiB |
152
doc/Informe/e1corregido/crear_tablas.sql
Normal file
@@ -0,0 +1,152 @@
|
||||
CREATE TABLE region(
|
||||
id_region SMALLSERIAL UNIQUE,
|
||||
nombre_region VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_region)
|
||||
);
|
||||
|
||||
CREATE TABLE ciudad(
|
||||
id_ciudad SMALLSERIAL UNIQUE,
|
||||
nombre_ciudad VARCHAR(20) NOT NULL,
|
||||
id_region SMALLINT,
|
||||
PRIMARY KEY (id_ciudad),
|
||||
FOREIGN KEY (id_region) REFERENCES region (id_region) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE apoderado(
|
||||
rut_apoderado VARCHAR(9) NOT NULL UNIQUE CHECK (rut_apoderado ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
PRIMARY KEY (rut_apoderado),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE alumno(
|
||||
rut_alumno VARCHAR(9) NOT NULL UNIQUE CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
anyo_ingreso SMALLINT CHECK (anyo_ingreso > 1980),
|
||||
fecha_nacimiento DATE NOT NULL CHECK (fecha_nacimiento > '1980-01-01'),
|
||||
rut_apoderado VARCHAR(9) NOT NULL CHECK (rut_apoderado ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (rut_alumno),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (rut_apoderado) REFERENCES apoderado (rut_apoderado) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE profesor(
|
||||
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
PRIMARY KEY (rut_profesor),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad(
|
||||
id_actividad SERIAL UNIQUE,
|
||||
nombre VARCHAR(50) NOT NULL,
|
||||
cupos SMALLINT CHECK (cupos > 0),
|
||||
lugar VARCHAR(20) NOT NULL,
|
||||
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_actividad),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE nivel(
|
||||
id_nivel SERIAL UNIQUE,
|
||||
nombre VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_nivel)
|
||||
);
|
||||
|
||||
CREATE TABLE bloque(
|
||||
id_bloque SERIAL UNIQUE,
|
||||
descripcion VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_bloque)
|
||||
);
|
||||
|
||||
CREATE TABLE curso(
|
||||
id_curso VARCHAR(10) NOT NULL UNIQUE,
|
||||
nombre VARCHAR(6) NOT NULL,
|
||||
anyo SMALLINT CHECK (anyo > 1980),
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_curso),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asignatura(
|
||||
id_asignatura SERIAL UNIQUE,
|
||||
nombre VARCHAR(50) NOT NULL,
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_asignatura),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE participar(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_actividad INT,
|
||||
PRIMARY KEY (rut_alumno, id_actividad),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad_nivel(
|
||||
id_actividad INT,
|
||||
id_nivel INT,
|
||||
PRIMARY KEY (id_actividad, id_nivel),
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_nivel) REFERENCES nivel (id_nivel) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad_bloque(
|
||||
id_actividad INT,
|
||||
id_bloque INT,
|
||||
PRIMARY KEY (id_actividad, id_bloque),
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE horario(
|
||||
id_asignatura INT,
|
||||
id_bloque INT,
|
||||
sala VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_asignatura, id_bloque),
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE registro(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_asignatura INT,
|
||||
nota NUMERIC(2,1) CHECK (nota >= 1.0 AND nota <= 7.0),
|
||||
PRIMARY KEY (rut_alumno, id_asignatura),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE cursar(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
PRIMARY KEY (rut_alumno, id_curso),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asociado(
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
id_asignatura INT,
|
||||
PRIMARY KEY (id_curso, id_asignatura),
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asistente(
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
PRIMARY KEY (rut_profesor, id_curso),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
|
||||
);
|
71
doc/Informe/e1corregido/insertar_duplas.sql
Normal file
@@ -0,0 +1,71 @@
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (1, 'Florida');
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (2, 'Alabama');
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (3, 'Virginia');
|
||||
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (1, 'Pensacola', 1);
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (2, 'Montgomery', 2);
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (3, 'Virginia Beach', 3);
|
||||
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('14592927k', 'Christopher Barry', 'Cromer', '214 Edison Dr.', 1);
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192186099', 'Elia Alejandra', 'Chacano Troncoso', 'Avenida San Sebastian 778', 2);
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192199859', 'Jack', 'Johnson', '320 Thomas Jefferson St.', 3);
|
||||
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('254049492', 'Izabella Lynn', 'Cromer Chacano', '214 Edison Dr.', 2019, '2019-10-04', '14592927k', 1);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('245191391', 'Tomas', 'Bunt', 'Avenida San Sebastian 778', 2018, '2010-02-05', '192186099', 2);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('18028642k', 'Tom', 'Riddle', '320 Thomas Jefferson St.', 2017, '2014-12-31', '192199859', 3);
|
||||
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226174788', 'Severus', 'Snape', '232 Jackson Ave.', 1);
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226779329', 'Minerva', 'McGonagall', '333 Nottingham Ln.', 2);
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('139414853', 'Albus', 'Dumbledore', '8450 Sparrow Rd.', 3);
|
||||
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (1, 'Quidditch', 14, 'Quidditch field', '226174788');
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (2, 'Ogre taming', 5, 'The forbidden forest', '226779329');
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (3, 'Advanced transfiguration', 2, 'Headmaster''s office', '139414853');
|
||||
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (1, 'First');
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (2, 'Second');
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (3, 'Third');
|
||||
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (1, '08:10 - 09:30');
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (2, '09:40 - 11:00');
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (3, '11:10 - 12:30');
|
||||
|
||||
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('1A-2017', '1A', 2017, '226174788');
|
||||
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('2B-2018', '2B', 2018, '226779329');
|
||||
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('3C-2019', '3C', 2019, '139414853');
|
||||
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (1, 'Transfiguration', '226779329');
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (2, 'Defense against the dark arts', '226174788');
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (3, 'Muggle studies', '139414853');
|
||||
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('254049492', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('245191391', 2);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('18028642k', 3);
|
||||
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (1, 1);
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (2, 2);
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (3, 3);
|
||||
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (1, 1);
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (2, 2);
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (3, 3);
|
||||
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (1, 1, '203AC');
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (2, 2, '301AB');
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (3, 3, '102AA');
|
||||
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('254049492', 1, 7.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('245191391', 2, 4.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('18028642k', 3, 1.0);
|
||||
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('254049492', '1A-2017');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('245191391', '2B-2018');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('18028642k', '3C-2019');
|
||||
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('1A-2017', 1);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('2B-2018', 2);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('3C-2019', 3);
|
||||
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('139414853', '1A-2017');
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226174788', '2B-2018');
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226779329', '3C-2019');
|
BIN
doc/Informe/e1corregido/ubblogo.png
Normal file
After Width: | Height: | Size: 185 KiB |
153
doc/Informe/e2/Informe2.tex
Normal file
@@ -0,0 +1,153 @@
|
||||
\documentclass[12pt]{article}
|
||||
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[spanish]{babel}
|
||||
\usepackage{array}
|
||||
\usepackage{adjustbox}
|
||||
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{verbatim}
|
||||
\usepackage{courier}
|
||||
|
||||
\usepackage{listings}
|
||||
\usepackage{xcolor}
|
||||
|
||||
\lstdefinestyle{freefempp}{
|
||||
language=SQL,
|
||||
basicstyle=\footnotesize\ttfamily,
|
||||
commentstyle=\itshape\color{gray},
|
||||
keywordstyle=\color{blue},
|
||||
numberstyle=\color{red},
|
||||
stringstyle=\color{red},
|
||||
identifierstyle=\color{violet},
|
||||
showstringspaces=false,
|
||||
%float,
|
||||
%frame=single,
|
||||
%numbers=left
|
||||
}
|
||||
|
||||
\lstset{
|
||||
basicstyle=\footnotesize\ttfamily,
|
||||
columns=flexible,
|
||||
breaklines=true,
|
||||
inputencoding=utf8,
|
||||
extendedchars=true,
|
||||
literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {ñ}{{\~n}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {Ñ}{{\~N}}1,
|
||||
style=freefempp
|
||||
}
|
||||
|
||||
\usepackage{titling}
|
||||
\renewcommand\maketitlehooka{\null\mbox{}\vfill}
|
||||
\renewcommand\maketitlehookd{\vfill\null}
|
||||
|
||||
\usepackage{hyperref}
|
||||
\hypersetup{colorlinks=true,allcolors=black}
|
||||
\usepackage{hypcap}
|
||||
|
||||
\title{\textbf{Proyecto Semestral de Base de Datos\\Entrega 2}}
|
||||
\author{Christopher Cromer\\\\Profesoras Mónica Caniupán y Valeria Beratto\\Ingeniería Civil Informática}
|
||||
\date{\today}
|
||||
|
||||
\pretitle{%
|
||||
\begin{center}
|
||||
\LARGE
|
||||
\includegraphics[width=4cm]{ubblogo.png}\\[\bigskipamount]
|
||||
}
|
||||
|
||||
\posttitle{\end{center}}
|
||||
|
||||
\begin{document}
|
||||
\clearpage
|
||||
\hypersetup{pageanchor=false}
|
||||
\begin{titlingpage}
|
||||
\maketitle
|
||||
\end{titlingpage}
|
||||
\thispagestyle{empty}
|
||||
|
||||
\newpage
|
||||
|
||||
\clearpage
|
||||
\thispagestyle{empty}
|
||||
\tableofcontents
|
||||
|
||||
\newpage
|
||||
\hypersetup{pageanchor=true}
|
||||
\pagenumbering{arabic}
|
||||
\section{Introducción}
|
||||
El objetivo de este trabajo es modelar un sistema para los colegios municipales de la región del Bío-Bío con el propósito de almacenar y consultar en una base de datos de PostgreSQL con información el colegio.
|
||||
|
||||
\newpage
|
||||
\section{Consultas}
|
||||
|
||||
\subsection{Consulta \texorpdfstring{$Q_1$}{$Q_1$}}
|
||||
\lstinputlisting{q1.sql}
|
||||
|
||||
\subsubsection{Resultado de \texorpdfstring{$Q_1$}{$Q_1$}}
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[width=0.90\textwidth,height=0.90\textheight,keepaspectratio]{q1.png}
|
||||
\end{center}
|
||||
|
||||
\subsection{Consulta \texorpdfstring{$Q_2$}{$Q_2$}}
|
||||
\lstinputlisting{q2.sql}
|
||||
|
||||
\subsubsection{Resultado de \texorpdfstring{$Q_2$}{$Q_2$}}
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[keepaspectratio]{q2.png}
|
||||
\end{center}
|
||||
|
||||
\newpage
|
||||
|
||||
\subsection{Consulta \texorpdfstring{$Q_3$}{$Q_3$}}
|
||||
\lstinputlisting{q3.sql}
|
||||
|
||||
\subsubsection{Resultado de \texorpdfstring{$Q_3$}{$Q_3$}}
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[keepaspectratio]{q3.png}
|
||||
\end{center}
|
||||
|
||||
\subsection{Consulta \texorpdfstring{$Q_4$}{$Q_4$}}
|
||||
\lstinputlisting{q4.sql}
|
||||
|
||||
\subsubsection{Resultado de \texorpdfstring{$Q_4$}{$Q_4$}}
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[keepaspectratio]{q4.png}
|
||||
\end{center}
|
||||
|
||||
\newpage
|
||||
|
||||
\subsection{Consulta \texorpdfstring{$Q_5$}{$Q_5$}}
|
||||
\lstinputlisting{q5.sql}
|
||||
|
||||
\subsubsection{Resultado de \texorpdfstring{$Q_5$}{$Q_5$}}
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[keepaspectratio]{q5.png}
|
||||
\end{center}
|
||||
|
||||
\subsection{Consulta \texorpdfstring{$Q_6$}{$Q_6$}}
|
||||
\lstinputlisting{q6.sql}
|
||||
|
||||
\subsubsection{Resultado de \texorpdfstring{$Q_6$}{$Q_6$}}
|
||||
|
||||
\begin{center}
|
||||
\includegraphics[keepaspectratio]{q6.png}
|
||||
\end{center}
|
||||
|
||||
\newpage
|
||||
\section{Script SQL}
|
||||
|
||||
\subsection{Crear tablas}
|
||||
|
||||
\lstinputlisting{crear_tablas.sql}
|
||||
|
||||
\newpage
|
||||
\subsection{Insertar duplas}
|
||||
|
||||
\lstinputlisting{insertar_duplas.sql}
|
||||
|
||||
\end{document}
|
||||
|
152
doc/Informe/e2/crear_tablas.sql
Normal file
@@ -0,0 +1,152 @@
|
||||
CREATE TABLE region(
|
||||
id_region SMALLSERIAL UNIQUE,
|
||||
nombre_region VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_region)
|
||||
);
|
||||
|
||||
CREATE TABLE ciudad(
|
||||
id_ciudad SMALLSERIAL UNIQUE,
|
||||
nombre_ciudad VARCHAR(20) NOT NULL,
|
||||
id_region SMALLINT,
|
||||
PRIMARY KEY (id_ciudad),
|
||||
FOREIGN KEY (id_region) REFERENCES region (id_region) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE apoderado(
|
||||
rut_apoderado VARCHAR(9) NOT NULL UNIQUE CHECK (rut_apoderado ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
PRIMARY KEY (rut_apoderado),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE alumno(
|
||||
rut_alumno VARCHAR(9) NOT NULL UNIQUE CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
anyo_ingreso SMALLINT CHECK (anyo_ingreso > 1980),
|
||||
fecha_nacimiento DATE NOT NULL CHECK (fecha_nacimiento > '1980-01-01'),
|
||||
rut_apoderado VARCHAR(9) NOT NULL CHECK (rut_apoderado ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (rut_alumno),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (rut_apoderado) REFERENCES apoderado (rut_apoderado) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE profesor(
|
||||
rut_profesor VARCHAR(9) NOT NULL UNIQUE CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
nombres VARCHAR(50) NOT NULL,
|
||||
apellidos VARCHAR(50) NOT NULL,
|
||||
direccion VARCHAR(30) NOT NULL,
|
||||
id_ciudad SMALLINT,
|
||||
PRIMARY KEY (rut_profesor),
|
||||
FOREIGN KEY (id_ciudad) REFERENCES ciudad (id_ciudad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad(
|
||||
id_actividad SERIAL UNIQUE,
|
||||
nombre VARCHAR(50) NOT NULL,
|
||||
cupos SMALLINT CHECK (cupos > 0),
|
||||
lugar VARCHAR(20) NOT NULL,
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_actividad),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE nivel(
|
||||
id_nivel SERIAL UNIQUE,
|
||||
nombre VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_nivel)
|
||||
);
|
||||
|
||||
CREATE TABLE bloque(
|
||||
id_bloque SERIAL UNIQUE,
|
||||
descripcion VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_bloque)
|
||||
);
|
||||
|
||||
CREATE TABLE curso(
|
||||
id_curso VARCHAR(10) NOT NULL UNIQUE,
|
||||
nombre VARCHAR(6) NOT NULL,
|
||||
anyo SMALLINT CHECK (anyo > 1980),
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_curso),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asignatura(
|
||||
id_asignatura SERIAL UNIQUE,
|
||||
nombre VARCHAR(50) NOT NULL,
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
PRIMARY KEY (id_asignatura),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE participar(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_actividad INT,
|
||||
PRIMARY KEY (rut_alumno, id_actividad),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad_nivel(
|
||||
id_actividad INT,
|
||||
id_nivel INT,
|
||||
PRIMARY KEY (id_actividad, id_nivel),
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_nivel) REFERENCES nivel (id_nivel) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE actividad_bloque(
|
||||
id_actividad INT,
|
||||
id_bloque INT,
|
||||
PRIMARY KEY (id_actividad, id_bloque),
|
||||
FOREIGN KEY (id_actividad) REFERENCES actividad (id_actividad) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE horario(
|
||||
id_asignatura INT,
|
||||
id_bloque INT,
|
||||
sala VARCHAR(20) NOT NULL,
|
||||
PRIMARY KEY (id_asignatura, id_bloque),
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_bloque) REFERENCES bloque (id_bloque) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE registro(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_asignatura INT,
|
||||
nota NUMERIC(2,1) CHECK (nota >= 1.0 AND nota <= 7.0),
|
||||
PRIMARY KEY (rut_alumno, id_asignatura),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE cursar(
|
||||
rut_alumno VARCHAR(9) NOT NULL CHECK (rut_alumno ~ '^[0-9k]+$'),
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
PRIMARY KEY (rut_alumno, id_curso),
|
||||
FOREIGN KEY (rut_alumno) REFERENCES alumno (rut_alumno) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asociado(
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
id_asignatura INT,
|
||||
PRIMARY KEY (id_curso, id_asignatura),
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_asignatura) REFERENCES asignatura (id_asignatura) ON DELETE RESTRICT
|
||||
);
|
||||
|
||||
CREATE TABLE asistente(
|
||||
rut_profesor VARCHAR(9) NOT NULL CHECK (rut_profesor ~ '^[0-9k]+$'),
|
||||
id_curso VARCHAR(10) NOT NULL,
|
||||
PRIMARY KEY (rut_profesor, id_curso),
|
||||
FOREIGN KEY (rut_profesor) REFERENCES profesor (rut_profesor) ON DELETE RESTRICT,
|
||||
FOREIGN KEY (id_curso) REFERENCES curso (id_curso) ON DELETE RESTRICT
|
||||
);
|
101
doc/Informe/e2/insertar_duplas.sql
Normal file
@@ -0,0 +1,101 @@
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (1, 'Bío Bío');
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (2, 'Ñuble');
|
||||
INSERT INTO region (id_region, nombre_region) VALUES (3, 'Virginia');
|
||||
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (1, 'Pensacola', 1);
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (2, 'Montgomery', 2);
|
||||
INSERT INTO ciudad (id_ciudad, nombre_ciudad, id_region) VALUES (3, 'Virginia Beach', 3);
|
||||
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('14592927k', 'Christopher Barry', 'Cromer', '214 Edison Dr.', 1);
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192186099', 'Elia Alejandra', 'Chacano Troncoso', 'Avenida San Sebastian 778', 2);
|
||||
INSERT INTO apoderado (rut_apoderado, nombres, apellidos, direccion, id_ciudad) VALUES ('192199859', 'Jack', 'Johnson', '320 Thomas Jefferson St.', 3);
|
||||
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('254049492', 'Isabella Lynn', 'Cromer Chacano', '214 Edison Dr.', 2019, '2019-10-04', '14592927k', 1);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('245191391', 'Tomas', 'Bunt', 'Avenida San Sebastian 778', 2018, '2010-02-05', '192186099', 2);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('18028642k', 'Tom', 'Riddle', '320 Thomas Jefferson St.', 2017, '2014-12-31', '192199859', 3);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('22690395k', 'Draco', 'Malfoy', '743 Thames Ave.', 2017, '2006-10-04', '192199859', 1);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('215221350', 'Victor', 'Krum', '9282 Park Way', 2017, '2007-02-12', '192199859', 1);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('144715179', 'Pansy', 'Parkinson', '339 Mobile Hwy.', 2017, '2008-12-03', '192199859', 1);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('86210681', 'Oliver', 'Wood', '323 Crane Ave.', 2017, '2007-01-02', '192199859', 1);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('20084453k', 'Theodore', 'Nott', '848 Short Way', 2017, '2006-02-04', '192199859', 1);
|
||||
INSERT INTO alumno (rut_alumno, nombres, apellidos, direccion, anyo_ingreso, fecha_nacimiento, rut_apoderado, id_ciudad) VALUES ('133765859', 'Cormac', 'McLaggen', '484 9th Ave.', 2017, '2007-01-08', '192199859', 1);
|
||||
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226174788', 'Severus', 'Snape', '232 Jackson Ave.', 1);
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('226779329', 'Minerva', 'McGonagall', '333 Nottingham Ln.', 2);
|
||||
INSERT INTO profesor (rut_profesor, nombres, apellidos, direccion, id_ciudad) VALUES ('139414853', 'Albus', 'Dumbledore', '8450 Sparrow Rd.', 3);
|
||||
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (1, 'Quidditch', 14, 'Quidditch field', '226174788');
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (2, 'Ogre taming', 5, 'The forbidden forest', '226779329');
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (3, 'Advanced transfiguration', 2, 'Headmaster''s office', '139414853');
|
||||
INSERT INTO actividad (id_actividad, nombre, cupos, lugar, rut_profesor) VALUES (4, 'Rugby', 30, 'Rugby field', '226174788');
|
||||
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (1, 'Primero');
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (2, 'Segundo');
|
||||
INSERT INTO nivel (id_nivel, nombre) VALUES (3, 'Tercero');
|
||||
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (1, '08:10 - 09:30');
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (2, '09:40 - 11:00');
|
||||
INSERT INTO bloque (id_bloque, descripcion) VALUES (3, '11:10 - 12:30');
|
||||
|
||||
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('1A-2019', '1A', 2019, '226174788');
|
||||
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('2B-2019', '2B', 2019, '226779329');
|
||||
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('3C-2019', '3C', 2019, '139414853');
|
||||
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('6A-2018', '6A', 2018, '226174788');
|
||||
INSERT INTO curso (id_curso, nombre, anyo, rut_profesor) VALUES ('1A-2018', '1A', 2018, '226779329');
|
||||
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (1, 'Transfiguration', '226779329');
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (2, 'Defense against the dark arts', '226174788');
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (3, 'Muggle studies', '139414853');
|
||||
INSERT INTO asignatura (id_asignatura, nombre, rut_profesor) VALUES (4, 'Potions', '226174788');
|
||||
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('254049492', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('245191391', 2);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('18028642k', 3);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('22690395k', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('215221350', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('144715179', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('86210681', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('20084453k', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('133765859', 1);
|
||||
INSERT INTO participar (rut_alumno, id_actividad) VALUES ('22690395k', 4);
|
||||
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (1, 1);
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (2, 2);
|
||||
INSERT INTO actividad_nivel (id_actividad, id_nivel) VALUES (3, 3);
|
||||
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (1, 1);
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (2, 2);
|
||||
INSERT INTO actividad_bloque (id_actividad, id_bloque) VALUES (3, 3);
|
||||
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (1, 1, '203AC');
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (2, 2, '301AB');
|
||||
INSERT INTO horario (id_asignatura, id_bloque, sala) VALUES (3, 3, '102AA');
|
||||
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('254049492', 1, 7.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('245191391', 2, 4.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('18028642k', 3, 1.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('22690395k', 4, 5.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('86210681', 4, 3.0);
|
||||
INSERT INTO registro (rut_alumno, id_asignatura, nota) VALUES ('144715179', 4, 2.0);
|
||||
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('254049492', '1A-2019');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('245191391', '2B-2019');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('18028642k', '3C-2019');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('22690395k', '6A-2018');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('215221350', '6A-2018');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('144715179', '6A-2018');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('86210681', '2B-2019');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('20084453k', '2B-2019');
|
||||
INSERT INTO cursar (rut_alumno, id_curso) VALUES ('133765859', '3C-2019');
|
||||
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('1A-2019', 1);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('2B-2019', 2);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('3C-2019', 3);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('6A-2018', 1);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('6A-2018', 2);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('6A-2018', 3);
|
||||
INSERT INTO asociado (id_curso, id_asignatura) VALUES ('1A-2018', 4);
|
||||
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('139414853', '1A-2019');
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226174788', '2B-2019');
|
||||
INSERT INTO asistente (rut_profesor, id_curso) VALUES ('226779329', '3C-2019');
|
BIN
doc/Informe/e2/q1.png
Normal file
After Width: | Height: | Size: 26 KiB |
19
doc/Informe/e2/q1.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
SELECT CONCAT_WS(' ', AL.nombres, AL.apellidos) AS alumno,
|
||||
CONCAT_WS(' ', AP.nombres, AP.apellidos) AS apoderado,
|
||||
CO.nombre curso,
|
||||
CONCAT_WS(' ', PJ.nombres, PJ.apellidos) AS jefe,
|
||||
CONCAT_WS(' ', PA.nombres, PA.apellidos) AS asistente
|
||||
FROM alumno AL
|
||||
JOIN apoderado AP ON (AP.rut_apoderado = AL.rut_apoderado)
|
||||
JOIN cursar CU ON (CU.rut_alumno = AL.rut_alumno)
|
||||
JOIN curso CO ON (CO.id_curso = CU.id_curso)
|
||||
JOIN profesor PJ ON (PJ.rut_profesor = CO.rut_profesor)
|
||||
JOIN asistente ASI ON (ASI.id_curso = CO.id_curso)
|
||||
JOIN profesor PA ON (PA.rut_profesor = ASI.rut_profesor)
|
||||
JOIN ciudad C ON (C.id_ciudad = AL.id_ciudad)
|
||||
JOIN region R ON (R.id_region = C.id_region)
|
||||
WHERE (
|
||||
CO.anyo = 2019 AND (
|
||||
R.nombre_region = 'Bío Bío' OR R.nombre_region = 'Ñuble'
|
||||
)
|
||||
);
|
BIN
doc/Informe/e2/q2.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
9
doc/Informe/e2/q2.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
SELECT CONCAT_WS(' ', P.nombres, P.apellidos) AS profesor FROM profesor P
|
||||
JOIN curso C ON (C.rut_profesor = P.rut_profesor)
|
||||
WHERE P.rut_profesor NOT IN (
|
||||
SELECT P2.rut_profesor FROM profesor P2
|
||||
JOIN actividad A ON (A.rut_profesor = P2.rut_profesor)
|
||||
JOIN actividad_nivel A2 ON (A2.id_actividad = A.id_actividad)
|
||||
JOIN nivel N ON (N.id_nivel = A2.id_nivel)
|
||||
WHERE (N.nombre = 'Primero' OR N.nombre = 'Segundo')
|
||||
);
|
BIN
doc/Informe/e2/q3.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
7
doc/Informe/e2/q3.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
SELECT A.nombre, COUNT(*) FROM actividad A
|
||||
JOIN participar P ON (P.id_actividad = A.id_actividad)
|
||||
JOIN alumno A2 ON (A2.rut_alumno = P.rut_alumno)
|
||||
WHERE (A2.fecha_nacimiento >= '2006-01-01'
|
||||
AND A2.fecha_nacimiento <= '2008-12-31')
|
||||
GROUP BY (A.nombre)
|
||||
HAVING COUNT(*) > 5;
|
BIN
doc/Informe/e2/q4.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
13
doc/Informe/e2/q4.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
CREATE VIEW matriculados(curso, cantidad) AS (
|
||||
SELECT C1.nombre, COUNT(*) FROM curso C1
|
||||
JOIN cursar C2 ON (C2.id_curso = C1.id_curso)
|
||||
WHERE (C1.anyo = 2019)
|
||||
GROUP BY (C1.nombre)
|
||||
);
|
||||
|
||||
SELECT M.curso, M.cantidad FROM matriculados M
|
||||
WHERE (
|
||||
M.cantidad = (
|
||||
SELECT MIN(M2.cantidad) FROM matriculados M2
|
||||
)
|
||||
);
|
BIN
doc/Informe/e2/q5.png
Normal file
After Width: | Height: | Size: 6.0 KiB |
14
doc/Informe/e2/q5.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
SELECT A.nombre, AVG(r.nota) FROM asignatura A
|
||||
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
|
||||
JOIN asociado A2 ON (A2.id_asignatura = A.id_asignatura)
|
||||
JOIN alumno A3 ON (A3.rut_alumno = R.rut_alumno)
|
||||
WHERE (
|
||||
A2.id_curso = '6A-2018'
|
||||
AND R.rut_alumno NOT IN (
|
||||
SELECT A4.rut_alumno FROM alumno A4
|
||||
JOIN participar P ON (P.rut_alumno = A4.rut_alumno)
|
||||
JOIN actividad A5 ON (A5.id_actividad = P.id_actividad)
|
||||
WHERE (A5.nombre = 'Rugby' AND A4.rut_alumno = A3.rut_alumno)
|
||||
)
|
||||
)
|
||||
GROUP BY (A.nombre);
|
BIN
doc/Informe/e2/q6.png
Normal file
After Width: | Height: | Size: 3.1 KiB |
24
doc/Informe/e2/q6.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
CREATE VIEW total_alumnos(asignatura, cantidad) AS (
|
||||
SELECT A.id_asignatura, COUNT(*) FROM asignatura A
|
||||
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
|
||||
JOIN alumno A2 ON (A2.rut_alumno = R.rut_alumno)
|
||||
JOIN asociado A3 ON (A3.id_asignatura = A.id_asignatura)
|
||||
WHERE (A3.id_curso = '1A-2018')
|
||||
GROUP BY (A.id_asignatura)
|
||||
);
|
||||
|
||||
CREATE VIEW total_aprobados(asignatura, cantidad) AS (
|
||||
SELECT A.id_asignatura, COUNT(*) FROM asignatura A
|
||||
JOIN registro R ON (R.id_asignatura = A.id_asignatura)
|
||||
JOIN alumno A2 ON (A2.rut_alumno = R.rut_alumno)
|
||||
JOIN asociado A3 ON (A3.id_asignatura = A.id_asignatura)
|
||||
WHERE (A3.id_curso = '1A-2018' AND R.nota >= 4)
|
||||
GROUP BY (A.id_asignatura)
|
||||
);
|
||||
|
||||
SELECT A2.nombre, TRUNC(CAST(T1.cantidad AS DECIMAL(3,2)) * 100 / CAST(T2.cantidad AS DECIMAL(3,2)),2) AS porcentaje
|
||||
FROM total_aprobados T1
|
||||
JOIN total_alumnos T2 ON (T2.asignatura = T1.asignatura)
|
||||
JOIN asociado A ON (T1.asignatura = A.id_asignatura AND T2.asignatura = A.id_asignatura)
|
||||
JOIN asignatura A2 ON (A2.id_asignatura = A.id_asignatura)
|
||||
WHERE ((CAST(T1.cantidad AS DECIMAL(3,2)) * 100 / CAST(T2.cantidad AS DECIMAL(3,2))) < 50);
|
BIN
doc/Informe/e2/ubblogo.png
Normal file
After Width: | Height: | Size: 185 KiB |
32
doc/meson.build
Normal file
@@ -0,0 +1,32 @@
|
||||
docs_enabled = get_option('valadocs')
|
||||
valadoc = find_program('valadoc', required: docs_enabled)
|
||||
vala_doc_sources = vala_sources
|
||||
vala_doc_sources += config_data_file
|
||||
if docs_enabled
|
||||
valadocs_deps = get_option('valadocs_deps')
|
||||
docs_deps = ['--pkg=gtk+-3.0']
|
||||
docs_deps += ['--pkg=libpq']
|
||||
docs_deps += ['--pkg=posix']
|
||||
if valadocs_deps
|
||||
docs_deps += ['--deps']
|
||||
endif
|
||||
custom_target('valadoc',
|
||||
input: vala_doc_sources,
|
||||
output: 'valadoc',
|
||||
command: [ valadoc,
|
||||
docs_deps,
|
||||
'--doclet=html',
|
||||
'--internal',
|
||||
'--private',
|
||||
'--force',
|
||||
'--package-name=@0@'.format(meson.project_name()),
|
||||
'--package-version=@0@'.format(meson.project_version()),
|
||||
'--vapidir=@0@'.format(join_paths(meson.source_root(), 'vapi')),
|
||||
'--directory=@OUTDIR@/valadoc',
|
||||
vala_doc_sources,
|
||||
],
|
||||
build_by_default: true,
|
||||
install: true,
|
||||
install_dir: join_paths(get_option('datadir'), 'doc', meson.project_name())
|
||||
)
|
||||
endif
|