Browse Source

initial commit

master
Chris Cromer 1 year ago
commit
23735a66de
Signed by: cromer <chris@cromer.cl> GPG Key ID: 39CC813FF3C8708A
55 changed files with 3311 additions and 0 deletions
  1. +10
    -0
      .gitignore
  2. +11
    -0
      LICENSE
  3. +28
    -0
      README.md
  4. +1
    -0
      data/meson.build
  5. +22
    -0
      data/ui/main.gresource.xml
  6. +55
    -0
      data/ui/main.splash.ui
  7. +165
    -0
      data/ui/main.window.ui
  8. +13
    -0
      data/ui/meson.build
  9. BIN
      data/ui/pixdata/icon-colegio.png
  10. BIN
      data/ui/pixdata/logo-colegio.png
  11. +20
    -0
      data/ui/query.gresource.xml
  12. +284
    -0
      data/ui/query.tree.ui
  13. +243
    -0
      data/ui/query.window.ui
  14. +191
    -0
      doc/Informe/e1/Informe1.tex
  15. BIN
      doc/Informe/e1/MER.dia
  16. BIN
      doc/Informe/e1/MER.png
  17. +150
    -0
      doc/Informe/e1/crear_tablas.sql
  18. +71
    -0
      doc/Informe/e1/insertar_duplas.sql
  19. BIN
      doc/Informe/e1/ubblogo.png
  20. +194
    -0
      doc/Informe/e1corregido/Informe1.tex
  21. BIN
      doc/Informe/e1corregido/MER.dia
  22. BIN
      doc/Informe/e1corregido/MER.png
  23. +152
    -0
      doc/Informe/e1corregido/crear_tablas.sql
  24. +71
    -0
      doc/Informe/e1corregido/insertar_duplas.sql
  25. BIN
      doc/Informe/e1corregido/ubblogo.png
  26. +153
    -0
      doc/Informe/e2/Informe2.tex
  27. +152
    -0
      doc/Informe/e2/crear_tablas.sql
  28. +101
    -0
      doc/Informe/e2/insertar_duplas.sql
  29. BIN
      doc/Informe/e2/q1.png
  30. +19
    -0
      doc/Informe/e2/q1.sql
  31. BIN
      doc/Informe/e2/q2.png
  32. +9
    -0
      doc/Informe/e2/q2.sql
  33. BIN
      doc/Informe/e2/q3.png
  34. +7
    -0
      doc/Informe/e2/q3.sql
  35. BIN
      doc/Informe/e2/q4.png
  36. +13
    -0
      doc/Informe/e2/q4.sql
  37. BIN
      doc/Informe/e2/q5.png
  38. +14
    -0
      doc/Informe/e2/q5.sql
  39. BIN
      doc/Informe/e2/q6.png
  40. +24
    -0
      doc/Informe/e2/q6.sql
  41. BIN
      doc/Informe/e2/ubblogo.png
  42. +32
    -0
      doc/meson.build
  43. +26
    -0
      meson.build
  44. +12
    -0
      meson_options.txt
  45. +45
    -0
      src/colegio.vala
  46. +26
    -0
      src/config.vala.in
  47. +54
    -0
      src/db.vala
  48. +19
    -0
      src/db/q1.vala
  49. +11
    -0
      src/db/q2.vala
  50. +72
    -0
      src/dbwrapper.vala
  51. +137
    -0
      src/main_window.vala
  52. +42
    -0
      src/meson.build
  53. +167
    -0
      src/misc.vala
  54. +146
    -0
      src/queries.vala
  55. +349
    -0
      src/query_window.vala

+ 10
- 0
.gitignore View File

@@ -0,0 +1,10 @@
build
*.tar.gz
*.autosave
*#*#
*.aux
*.log
*.toc
*.synctex.gz
*.out
*.pdf

+ 11
- 0
LICENSE View File

@@ -0,0 +1,11 @@
Copyright 2019 Chris Cromer

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 28
- 0
README.md View File

@@ -0,0 +1,28 @@
# Colegio
Este proyecto es para conectar a un base de datos de Postgresql para el ramo de Base de Datos.

## Profesora
Monica Mónica Caniupán & Valeria Beratto

## Requisitos
- Vala
- Meson
- Ninja
- Gtk+-3
- Libpq
- Valadoc (opcional para compilar valadoc del proyecto)

## Compilar
meson --prefix=/usr build
cd build
ninja

## Opciones de compilación
-D valadocs=true
Esta opción va a compilar la documentación de codiǵo fuente usando valadoc

-D valadocs_dep=true
Si ambos valadocs y esta opción están en uso se va a compilar la documentación del proyecto y tambien la documentación de todos los dependencias. Esta opción es caro y hace mucho mas lento la compilación.

-D debugging=true
Compilar con flags de depuración. Eso implica errores fatales que generan core dumps para ayudar con la depuración.

+ 1
- 0
data/meson.build View File

@@ -0,0 +1 @@
subdir('ui')

+ 22
- 0
data/ui/main.gresource.xml View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 Chris Cromer
~
~ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
~
~ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
~
~ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
~
~ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
~
~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<gresources>
<gresource prefix="/cl/cromer/ubb/colegio">
<file preprocess="xml-stripblanks">main.window.ui</file>
<file preprocess="xml-stripblanks">main.splash.ui</file>
<file preprocess="to-pixdata">pixdata/icon-colegio.png</file>
<file preprocess="to-pixdata">pixdata/logo-colegio.png</file>
</gresource>
</gresources>

+ 55
- 0
data/ui/main.splash.ui View File

@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1

Copyright 2019 Chris Cromer

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-->
<interface domain="colegio">
<requires lib="gtk+" version="3.20"/>
<object class="GtkGrid" id="content_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="resource">/cl/cromer/ubb/colegio/pixdata/logo-colegio.png</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="label" translatable="yes">Christopher Cromer</property>
<property name="justify">center</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
</interface>

+ 165
- 0
data/ui/main.window.ui View File

@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1

Copyright 2019 Chris Cromer

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-->
<interface domain="colegio">
<requires lib="gtk+" version="3.20"/>
<template class="ColegioMainWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="title">Hogwarts School of Witchcraft and Wizardry</property>
<property name="window_position">center</property>
<signal name="destroy" handler="on_destroy" swapped="no"/>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox" id="mainbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="baseline_position">top</property>
<child>
<object class="GtkMenuBar" id="menubar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Menu</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="tours">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Tours</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="staff">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Staff</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="tourists">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Tourists</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="quit">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Quit</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Views</property>
<property name="use_underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="q1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q1) Alumnos de Bı́obio o Ñuble</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q2) Profesores sin actividad</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q3) Actividades</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q4) Cursos con menor matriculados</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q5) Notas de asignaturas</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="q6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">(Q6) Asignaturas con bajo aprobación</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_activate_menu" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</template>
</interface>

+ 13
- 0
data/ui/meson.build View File

@@ -0,0 +1,13 @@
gnome = import('gnome')
main_gresource = gnome.compile_resources('main_gresource',
'main.gresource.xml',
source_dir: '.',
c_name: meson.project_name() + '_resource_main',
export: true,
install_header: true)
query_gresource = gnome.compile_resources('query_gresource',
'query.gresource.xml',
source_dir: '.',
c_name: meson.project_name() + '_resource_query',
export: true,
install_header: true)

BIN
data/ui/pixdata/icon-colegio.png View File

Before After
Width: 48  |  Height: 48  |  Size: 5.4 KiB

BIN
data/ui/pixdata/logo-colegio.png View File

Before After
Width: 408  |  Height: 480  |  Size: 366 KiB

+ 20
- 0
data/ui/query.gresource.xml View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 Chris Cromer
~
~ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
~
~ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
~
~ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
~
~ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
~
~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<gresources>
<gresource prefix="/cl/cromer/ubb/colegio">
<file preprocess="xml-stripblanks">query.window.ui</file>
<file preprocess="xml-stripblanks">query.tree.ui</file>
</gresource>
</gresources>

+ 284
- 0
data/ui/query.tree.ui View File

@@ -0,0 +1,284 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1

Copyright 2019 Chris Cromer

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-->
<interface domain="colegio">
<requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="liststore1"/>
<object class="GtkTreeView" id="query_tree_q1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="alumno">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Alumno</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="apoderado">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Apoderado</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="curso_q1">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Curso</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="jefe">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Jefe</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="asistente">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Asistente</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">4</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="profesor">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Profesor</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q3">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="nombre_q3">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Nombre</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="cantidad_q3">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Cantidad</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q4">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="curso_q4">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Curso</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="cantidad_q4">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Cantidad</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q5">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection">
<property name="mode">none</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="nombre_q5">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Nombre</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="promedio">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Promedio</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
<object class="GtkTreeView" id="query_tree_q6">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="headers_clickable">False</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<property name="enable_grid_lines">both</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="nombre_q6">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Nombre</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Porcentaje</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="markup">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</interface>

+ 243
- 0
data/ui/query.window.ui View File

@@ -0,0 +1,243 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1

Copyright 2019 Chris Cromer

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-->
<interface domain="colegio">
<requires lib="gtk+" version="3.20"/>
<template class="ColegioQueryWindow" parent="GtkApplicationWindow">
<property name="can_focus">False</property>
<property name="type">popup</property>
<property name="modal">True</property>
<property name="window_position">center-on-parent</property>
<property name="default_width">800</property>
<property name="default_height">600</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="show_menubar">False</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<child>
<object class="GtkScrolledWindow" id="scroll_window">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="spacing">25</property>
<child>
<object class="GtkButton" id="close_query">
<property name="label" translatable="yes">Close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="run_query">
<property name="label" translatable="yes">Run</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<signal name="clicked" handler="on_clicked_button" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">Statement</property>
<attributes>
<attribute name="font-desc" value="Sans Bold 6"/>
</attributes>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="label" translatable="yes">View and Query</property>
<attributes>
<attribute name="font-desc" value="Sans Bold 6"/>
</attributes>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkLabel" id="statement">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<property name="wrap">True</property>
<attributes>
<attribute name="font-desc" value="Sans 6"/>
</attributes>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="label_xalign">0</property>
<property name="label_yalign">0</property>
<property name="shadow_type">out</property>
<child>
<object class="GtkLabel" id="sql">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="margin_left">5</property>
<property name="margin_right">5</property>
<property name="margin_top">5</property>
<property name="margin_bottom">5</property>
<attributes>
<attribute name="font-desc" value="Monospace 6"/>
</attributes>
</object>
</child>
<child type="label_item">
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object>
</child>
</template>
</interface>

+ 191
- 0
doc/Informe/e1/Informe1.tex View 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 View File


BIN
doc/Informe/e1/MER.png View File

Before After
Width: 989  |  Height: 636  |  Size: 54 KiB

+ 150
- 0
doc/Informe/e1/crear_tablas.sql View 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
- 0
doc/Informe/e1/insertar_duplas.sql View 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 View File

Before After
Width: 2232  |  Height: 1441  |  Size: 185 KiB

+ 194
- 0
doc/Informe/e1corregido/Informe1.tex View 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 View File


BIN
doc/Informe/e1corregido/MER.png View File

Before After
Width: 989  |  Height: 636  |  Size: 56 KiB

+ 152
- 0
doc/Informe/e1corregido/crear_tablas.sql View 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
- 0
doc/Informe/e1corregido/insertar_duplas.sql View 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 View File

Before After
Width: 2232  |  Height: 1441  |  Size: 185 KiB

+ 153
- 0
doc/Informe/e2/Informe2.tex View 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
- 0
doc/Informe/e2/crear_tablas.sql View 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
- 0
doc/Informe/e2/insertar_duplas.sql View File

@@ -0,0 +1,101 @@