Sistemas Gestores de Bases de Datos

206
Profesor: Rafael Lozano Luján

Transcript of Sistemas Gestores de Bases de Datos

Page 1: Sistemas Gestores de Bases de Datos

� � � �� �� � � �� � �� �� �� � � � ��� �� � � ��� � � �

� �� � � � �� � �� � �� �� � � �� �� �� � �

Profesor: Rafael Lozano Luján

Page 2: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

�� �� � � � � ����� ���� ��

INTRODUCCIÓN A LOS SISTEMAS DE INFORMACIÓN Y A LAS BASES DE DATOS . 7 Concepto de Información ................................................................................................. 7 Sistema de Información.................................................................................................... 7

���� ������ ��� ���� ������������������������������������������������������������������������������������������������������������������������������������ ����� �� ��� ��� �����������������������������������������������������������������������������������������������������������������������������������������

Aplicación de las TIC a los SI......................................................................................... 10 De los sistemas tradicionales de ficheros a las bases de datos .................................... 11 Introducción a las Bases de Datos................................................................................. 11 Ventajas e inconvenientes de las Bases de Datos frete a los ficheros clásicos............ 12 Características de las Bases de Datos .......................................................................... 13 Visiones de los datos en las bases de datos ................................................................. 15 Bases de datos y Sistemas de Gestión de bases de datos ........................................... 17 Principales funciones de un SGBD ................................................................................ 18

�� �! �� �� �"�! ���� ���# ! � ��������������������������������������������������������������������������������������������������������� $ �� �! �� ��� ��# � ��! � ������������������������������������������������������������������������������������������������������������������������� $ �� �! �� ��% ������ ����������������������������������������������������������������������������������������������������������������������������������� $

Componentes de un SGBD............................................................................................ 19

REPRESENTACIÓN DE PROBLEMAS DEL MUNDO REAL. LOS MODELOS DE DATOS ........................................................................................................................ 22

Los problemas del mundo real ....................................................................................... 22 & ���' ����! � ������������������������������������������������������������������������������������������������������������������������������������������ �( ��# �������! �� ������# ��' ��� ��� ���� � � ������ ����������������������������������������������������������������������������������� �( ) �� ���� ������# ��' ��� ��������������������������������������������������������������������������������������������������������������������������� �*

Los Modelos de Datos.................................................................................................... 26 �� ' � � ����� ��� ��+ � ����������������������������������������������������������������������������������������������������������������������������� � & ������������� ������� � � ��������+ � ����������������������������������������������������������������������������������������������� � & ���� � ����� �� ����������� ��, �� ��' ����� �� ���� ��������������������������������������������������������������������������� �-

EL MODELO ENTIDAD - INTERRELACIÓN ....................................................... 30 Introducción .................................................................................................................... 30 Estática del Modelo Entidad – Interrelación ................................................................... 30

��� � ����������������������������������������������������������������������������������������������������������������������������������������������������� ($ ���������! ����������������������������������������������������������������������������������������������������������������������������������������������� ($ ����������������������������������������������������������������������������������������������������������������������������������������������������� (*

Semántica de las interrelaciones.................................................................................... 34 % �� ��� � ��� ��� ���# �� ����� � ������������������������������������������������������������������������������������������������������� (* � �# �� ��������. ������/ ���� ���"�! ������������������������������������������������������������������������������������������ (0

Generalización y Herencia ............................................................................................. 36 & ����� ��� � ���������1����2 � �� ����������������������������������������������������������������������������������������������������������� (

Interrelaciones Exclusivas .............................................................................................. 39 Representación de las Restricciones en el ME-R.......................................................... 40 Dinámica del Modelo Entidad – Interrelación................................................................. 40

EL MODELO RELACIONAL .............................................................................. 41 Estructura del Modelo Relacional................................................................................... 42

� �� ���/ �) ��' � �� ������������������������������������������������������������������������������������������������������������������������������������ *( � �"�! ��"��� ��� ������! � �������������������������������������������������������������������������������������������������������������������� ** % ������ ������! ������������������������������������������������������������������������������������������������������������������������������������� *0 % ��3 �� ������������������������������������������������������������������������������������������������������������������������������������������������������ *0

Restricciones .................................................................................................................. 46 �����������4 ������� �������������������������������������������������������������������������������������������������������������������������� *� ������������� � ����������������������������������������������������������������������������������������������������������������������������� *�

Los valores nulos en el modelo relacional ..................................................................... 48 % ���# ��� ��3 ������� �� ���������������������������������������������������������������������������������������������������������������������������� *

Normalización de Relaciones......................................................................................... 49 � �# �� �����"� ������� ����������������������������������������������������������������������������������������������������������������������� 0$ ��� ���� ������ ��5 �! � �������������������������������������������������������������������������������������������������������������������������� 0(

Las 12 reglas de Codd para los sistemas relacionales.................................................. 58

Page 3: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

�� �� � � � � ���(� ���� ��

TRADUCCIÓN DEL MODELO ENTIDAD - INTERRELACIÓN AL MODELO RELACIONAL .............................................................................................................. 60

Preparación de los esquemas conceptuales.................................................................. 60 ��� ��! �� �����' � ����� 6 ��# ��� ������������������������������������������������������������������������������������������������������������ �� ��� ��! �� �����' � ������ # � ������������������������������������������������������������������������������������������������������������ �$

Transformación de los esquemas conceptuales ............................................................ 62 7����"��� �! �� �������# ��� ����� � ��������������������������������������������������������������������������������������������������� �� 7����"��� �! �� ���# ��� ����������! ��� ������ �� �������������������������������������������������������������������������������� �( 7����"��� �! �� �������# ��� ����������! ��� ������ � 4 ��� ������������������������������������������������������������������� �� 7����"��� �! �� ���# ��� ����������! ��� � 4 ������ � 4 �� ������������������������������������������������������������������� �8 7����"��� ������ ���# ��� ����������������9���������������������������������������������������������������������������������� � 7����"��� �! �� ���# ��� ����������! ����"��. 3 �� ��������������������������������������������������������������������������������� �-

Eliminación de las relaciones jerárquicas ...................................................................... 70 Álgebra Relacional ......................................................................................................... 78

: # ��� �����# �� �3 �� ������������������������������������������������������������������������������������������������������������������������������ � : # ��� ������ ��3 � �� ����������������������������������������������������������������������������������������������������������������������������� * : # ��� ������ ��3 � �� ����������������������������������������������������������������������������������������������������������������������������� 0 : # ��� �������������������3 ��������� ��� ��������������������������������������������������������������������������������������������� �

SQL ................................................................................................................ 88 Lenguaje estructurado de consultas SQL ...................................................................... 88

; ����� ����������������������������������������������������������������������������������������������������������������������������������������������������� �< & ��� ������ � �1������� �� �� ��������������������������������������������������������������������������������������������������������������

Tipos de datos (ORACLE).............................................................................................. 89 Tipos de datos (MySQL)................................................................................................. 91 Operadores SQL ............................................................................................................ 92

: # ��� ��������� = ��� ���������������������������������������������������������������������������������������������������������������������������� -� : # ��� ������! � �� ���������������������������������������������������������������������������������������������������������������������������������� -� : # ��� ��� ���������! � ��������������������������������������������������������������������������������������������������������������������� -( & ���� ����� ��3 ����>�? @ & & ��������������������������������������������������������������������������������������������������������������������� -(

Consultas simples .......................................................................................................... 94 & ������������& �% 7������������������������������������������������������������������������������������������������������������������������������ -* % ���� ����������������������������������������������������������������������������������������������������������������������������������������������� -0 % ��� � ������� �� �� ������������������������������������������������������������������������������������������������������������������������������� -0 ����! �� ���� ���������� � ����A������B C ��������������������������������������������������������������������������������������������� -� ����� � # �� ������������������������������������������������������������������������������������������������������������������������������������������ -� ����! �� ��"����% �� � �� ���D ; ������������������������������������������������������������������������������������������������������������ -8 7���� ���� # ���! ��AE F�G H F�G F�G E F�H F�H E C ����������������������������������������������������������������������������������������������� -8 7���� ������ �>�� �7D ��? ����������������������������������������������������������������������������������������������������������������������� - 7���� ��# �������������1� ����A�? C ��������������������������������������������������������������������������������������������������������� - 7���� �������# �� �������# ���! ���& �I � ���������������������������������������������������������������������������������������������� -- 7���� ��3 ������� ���A���? @ & & C �������������������������������������������������������������������������������������������������������������������� -- : � ���! �� ���������� ��� ��� ��� ������� �����% �� � �� ���: �� ���� J �������������������������������������������������� $ � �

Consultas sumarias ...................................................................................................... 100 % � �� ��� ��������� ��� ������ � ���A�@ + C ������������������������������������������������������������������������������������������������ $ � $ % � �� ��� ���# ��� � �� ��� ������ � ���A) K � C ���������������������������������������������������������������������������������������� $ � $ � ����� ��! �� ��3 ��������. ���� ��������������������������������������������������������������������������������������������������������� $ � $ % � ����� ��3 ������� �� �����A% : @ ? 7C ��������������������������������������������������������������������������������������������������� $ � � K �������? @ & & �/ �"� ������ ����� � �� �������������������������������������������������������������������������������������������������� $ � � ��� ��! �� ��"���� � # �� ���A� ��7�? % 7C ������������������������������������������������������������������������������������������ $ � (

Consultas agrupadas.................................................................................................... 103 % �� ����� ��' 6 �2 � � �� ��� �� # ����% �� � �� ���; ) K �? � ���������������������������������������������������������������������� $ � 0

Subconsultas ................................................................................................................ 106 7���� ���� # ���! �� ���� ' ���� ����AE F�G H F�G F�G E F�H F�H E C �������������������������������������������������������������������� $ � - 7���� ��# �������������1� ����A�? C ������������������������������������������������������������������������������������������������������� $ � - 7���� ���. ������A�L ��7�C ������������������������������������������������������������������������������������������������������������������ $ $ � 7����� ���"� ���A) ? J �/ �) & & C ������������������������������������������������������������������������������������������������������������� $ $ � �� ' ���� ������� � �� �������������������������������������������������������������������������������������������������������������������������� $ $ $ �� ' ���� ������������� � �� ���; ) K �? � ���������������������������������������������������������������������������������������������������� $ $ �

Page 4: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

�� �� � � � � ���*� ���� ��

Consultas multitabla ..................................................................................................... 113 % ���� ������ � ����' ������������� ������! �� ��"�� ��������������������������������������������������������������������������� $ $ * + 6 ��# ������� � ���� ���� # ���1�� ���� ������������������������������������������������������������������������������������������������� $ $ * % ���� ����� ���������� � ����' ��� �������������������������������������������������������������������������������������������������������������� $ $ 0 M ����. ������������������������������������������������������������������������������������������������������������������������������������������������� $ $ 0

Actualizaciones de Datos ............................................................................................. 118 ) , � ��"��������������? ���7 ������������������������������������������������������������������������������������������������������������� $ $ �� # ���! �� �� ��������������� �& �7� ����������������������������������������������������������������������������������������������� $ �� + � "�! �� �� ��������������@ � � ) 7�������������������������������������������������������������������������������������������� $ ��

Lenguaje de definición de datos: DDL ......................................................................... 125 % ���! �� ����' �������������% ������7�' �������������������������������������������������������������������������������������������� $ �0 % ���! �� ���� ������������% �������� �. ���������������������������������������������������������������������������������������� $ �� % ���! �� ��3 ��������������% ������K �N ������������������������������������������������������������������������������������������� $ �8 � ���� �� ����' ���F��� ���/ �3 ������������������������������������������������������������������������������������������������������������� $ �- + � "�! �� ��� ��� �"�! �� ����' ������������) & 7���7) � & � ������������������������������������������������������ $ (�

Seguridad SQL ............................................................................................................. 131 ) �� ����# �3 ��� ������������� �) ? 7��������������������������������������������������������������������������������������������������� $ ($ ��3 ��! �� ��# �3 ��� ��������������K : I �������������������������������������������������������������������������������������� $ (�

Funciones SQL en Oracle ............................................................................................ 133 �� ������ �������� ������� � = �� ������������������������������������������������������������������������������������������������������� $ (( �� ������ �������� �������"��� � = �� ������������������������������������������������������������������������������������������������� $ (( �� ������ �������� ����� ��"�4 �� ������������������������������������������������������������������������������������������������������ $ (( ���� �����# �����: @ ? � �/ �7�@ ? % �# ����"�4 ��>������������������������������������������������������������������������������������� $ (( �� ������ ����3 ���! � ����������������������������������������������������������������������������������������������������������������������� $ (* : �����"� ����� �������������������������������������������������������������������������������������������������������������������������������������� $ (*

Funciones SQL en MySQL........................................................................................... 134 �� ������ ��� �������������������������������������������������������������������������������������������������������������������������������� $ (* �� �������� � = ��� ����������������������������������������������������������������������������������������������������������������������������� $ (� �� ������ ��"�4 ��/ �4 ��� ��������������������������������������������������������������������������������������������������������������������� $ (� �� ������ ���� # ���! � �������������������������������������������������������������������������������������������������������������������� $ (8 + ���� ���� ��"� ����������������������������������������������������������������������������������������������������������������������������� $ (

MYSQL ........................................................................................................ 139 Introducción .................................................................................................................. 139 Instalación de MySQL en Windows.............................................................................. 139

% �� # ��' �! �� �����������! � ������������������������������������������������������������������������������������������������������������� $ *� �����"�5 ���������� ���� �� ����������������������������������������������������������������������������������������������������������������� $ *$

Instalación de MySQL en Linux.................................................................................... 142 �������! �� ��� ��� ���' � ! ��' ���� ��������������������������������������������������������������������������������������������������� $ *� % �� # ��' �! �� �����������! �����@ ? �L O& �� . ������������������������������������������������������������������������������������� $ *(

Creación y uso de BD en MySQL................................................................................. 144 Creación de tablas........................................................................................................ 144

7# ��� ����' �������+ / �< & ��������������������������������������������������������������������������������������������������������������������� $ *8 ) , � ����� ����������< & � ����� ������������������� ��+ / �< & ��������������������������������������������������������� $ 0� ����# ����� ������. �����������' ����+ / �< & ����& : ) � �� ) 7) ���������������������������������������������������������������� $ 0*

Optimize table, replace, set, lock tables y unlock tables.............................................. 155 Visualización de las tablas de una base de datos: show, describe y explain .............. 157

SQL PARA MYSQL. LENGUAJE DE MANIPULACIÓN DE DATOS. .................... 158 Introducción .................................................................................................................. 158 La sentencia SELECT .................................................................................................. 158

% �� � �� �����& �% 7 ���������������������������������������������������������������������������������������������������������������������������������� $ 0- % �� � �� ����? 7: ���������������������������������������������������������������������������������������������������������������������������������������� $ �� % �� � �� �����: + �������������������������������������������������������������������������������������������������������������������������������������� $ �$ % �� � �� ���D ; �������������������������������������������������������������������������������������������������������������������������������������� $ �� % �� � �� ���� �: @ � �� J ����������������������������������������������������������������������������������������������������������������������������� $ �( % �� � �� ���; ) K �? � ����������������������������������������������������������������������������������������������������������������������������������� $ �( % �� � �� ���: �� ���� J ������������������������������������������������������������������������������������������������������������������������������ $ �* % �� � �� ���& �+ �7 ��������������������������������������������������������������������������������������������������������������������������������������� $ �0 ����� ' ������� � �����% �� � �� ���) � ������������������������������������������������������������������������������������������������������� $ ��

Page 5: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

�� �� � � � � ���0� ���� ��

Consultas con condiciones de búsqueda..................................................................... 166 7���� ���� # ���! ������������������������������������������������������������������������������������������������������������������������������� $ �8 7���� ������ �>�% �� � �� ���� �7D ��? �P �) ? � ����������������������������������������������������������������������������������������� $ �8 7���� ��# �������������1� ���>�% �� � �� ����? ����������������������������������������������������������������������������������������� $ � 7���� �������# �� �������# ����>�% �� � �� ���& �I � ������������������������������������������������������������������������������� $ � 7���� ��3 ������� ��>�% �� � �� ������? @ & & ���������������������������������������������������������������������������������������������������� $ �- % �� ������� # � �������: # ��� �����) ? � F�: ��/ �? : 7����������������������������������������������������������������������� $ �-

Consultas Agrupadas ................................................................................................... 169 �� ������ ���� ��� � ������������� ������! � ������������������������������������������������������������������������������������ $ 8� �� �! ��% : @ ? 7������������������������������������������������������������������������������������������������������������������������������������� $ 8$ K �������? @ & & ��������"� ������ ���� ��� � ������������������������������������������������������������������������������������������ $ 8� 7����� ����� ��"���� � # �� ������� ��7�? % 7 ������������������������������������������������������������������������������������� $ 8� ) � �� # ���"�������� �: @ � �� J ���������������������������������������������������������������������������������������������������������������� $ 8�

Subconsultas en MySQL .............................................................................................. 175 7���� ���� # ���! �� ���� ' ���� ����AE F�G H F�G F�G E F�G F�H E C �������������������������������������������������������������������� $ 80 7���� ��# �������������1� �����% �� � �� ����? ����������������������������������������������������������������������������������������� $ 80 7���� ���. �������% �� � �� ����L ��7������������������������������������������������������������������������������������������������������ $ 8� 7����� ���"� ��) ? J ���������������������������������������������������������������������������������������������������������������������������� $ 8� �� ' ���� ������� � �� �������������������������������������������������������������������������������������������������������������������������� $ 88 �� ' ���� ���������� � �� ���; ) K �? � �������������������������������������������������������������������������������������������������������� $ 8

Consultas multitabla en MySQL ................................................................................... 178 M ���� �� �����' ������������������������������������������������������������������������������������������������������������������������������������ $ 8- M : �? ������������ ������! �� ��"��� ����������������������������������������������������������������������������������������������� $ � M : �? ������ 6 ��# ������� � ���� ���� # ���1�� ����������������������������������������������������������������������������������� $ � M : �? �� ���������� � ����' ��� ������������������������������������������������������������������������������������������������������������������� $ $ M : �? ������� ����� ��' 6 �2 � � ������ � �� � �������������������������������������������������������������������������������� $ � M : �? ����������/ ��. ������ ��������������������������������������������������������������������������������������������������������������������� $ � M : �? ��L 7��? : ��� # ���� ��������������������������������������������������������������������������������������������������������������������� $ ( M : �? ��L 7��? : �5 2 � �� ��/ � ���4 � ���������������������������������������������������������������������������������������������������� $ * M : �? ����� 6 ��# ������� � ���� ���� # ���1�� ���� ��������������������������������������������������������������������������������� $ 0 M : �? ��� � ������������������������������������������������������������������������������������������������������������������������������������������ $ 0

Actualizaciones de datos.............................................................................................. 186 ����� � �� ���������������? ���7 ������������������������������������������������������������������������������������������������������ $ � ��� ����"���� �� ��������������� �& �7� ������������������������������������������������������������������������������������������� $ ) �� ��5 �! �� �� ��������������@ � � ) 7������������������������������������������������������������������������������������������� $

ADMINISTRACIÓN DE MYSQL ...................................................................... 190 Administración de tablas .............................................................................................. 190

+ � "�! �� ����' �������) & 7���7) � & � �������������������������������������������������������������������������������������������� $ -� � ���� �� ����' �������� �: � �7) � & � ���������������������������������������������������������������������������������������������������� $ -� � ���� �� ��' ����� �� ��������� �: � �� ) 7) � ) �������������������������������������������������������������������������������� $ -(

Vistas ............................................................................................................................ 193 Administración de cuentas de usuario ......................................................................... 193

��������� �) ? 7���������������������������������������������������������������������������������������������������������������������������������� $ -* ����������K : I � ������������������������������������������������������������������������������������������������������������������������������� $ -0 % �������, ���� � �������7�� ) ��D : �� ��������������������������������������������������������������������������������������������� $ -�

Copias de seguridad..................................................................................................... 196 % �# �� ����� � � � ����+ / �< & � @ + � �A' �Q � # �C ��������������������������������������������������������������������������������� $ -8 ��� # ���! �� ��� ���' ���� �� ���������������������������������������������������������������������������������������������������������� $ -8

HERRAMIENTAS GRÁFICAS DE MYSQL ........................................................ 198 MySQL Administrator ................................................................................................... 198

�������! �� ���� � ����� ��� ��+ / �< & ������������������������������������������������������������������������������������������������ $ - ��"��� �! �� ������3 �� ������������������������������������������������������������������������������������������������������������������������ �� � % ������� ������3 ���������������������������������������������������������������������������������������������������������������������������������� �� � K ���' ���� ���� ���������������������������������������������������������������������������������������������������������������������������������� �� � ) � �����! �� ��� �� ���� �������������������������������������������������������������������������������������������������������������������� �� � % ���. ����� ������3 ��������������������������������������������������������������������������������������������������������������������������� �� $ ; ����4 ����������������������������������������������������������������������������������������������������������������������������������������������������� �� $ ���3 ���& �� � �������������������������������������������������������������������������������������������������������������������������������������������� �� $

Page 6: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

�� �� � � � � ����� ���� ��

���� �� �������= # ��� ���������������������������������������������������������������������������������������������������������������������������� �� $ � �Q � # ��������������������������������������������������������������������������������������������������������������������������������������������������� �� $ ���������������������������������������������������������������������������������������������������������������������������������������������������������� �� � % ��� ��� � ������������������������������������������������������������������������������������������������������������������������������������������������� �� �

MySQL Query Browser................................................................................................. 202 �������! �� ��+ / �< & �< � ��/ �� ��N ��� ��������������������������������������������������������������������������������������������������� �� �

MySQL Control Center ................................................................................................. 204

Page 7: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���8� ���� ��

�� �� � � � � � � �� � � ��� � �� �� � � � �� ��� �� � � �� � �� � �� � �� � � �� �� �� � �

���������������� ����

������� �� ���� �� �� ��������� �� ��� ������� �� ����������� �� ���������������� �� ������������ ������ �� �������������������� �� ��� ������������� ���� �� �������� �� ��� ����� ��� �������� ������� �� ��� �� �� ������������������ ����������� ���� �� ������������� ��� ���� ��� ��������������� �� ����������������� ����� ��� ������������ �������� ���� ��� ���� ����� ������ �� �� ����������������������������������������� �������������������� ������ ��������!����������������������� ���"��� ���������������������������������������������� �������� �� ����� ���� ���� ����������#��� ������� ���� �� �� ��� ��� �� ������ ���������

������������ � � ����������������������������� ������� � ��������� �������������������������� ���������#���������"��������� � ����$�

� "�����#���������������� ��������� ��� ���

� "�������������������������%����������������� � ������������������������

� "��������������������������������������� �������

� &������������������������ ���� ��������������� �� �������

� &��������������������������������������

� ��������������#��� �� �������� ���� ���

� "��������� ��������������������

����� �������� ����

'� �� ������(������� ���� �� �� �����)��� �������� ���� ��������������� ������� ��� ���������� ������#� � ��� "��� ���������� ������(���#����� �� �� ��������������� �� ��������� ���� ���� ���� ���������� �� ����� ������ ������ �������� �����������$�

� ���������� �� ��������� ��� ������� ����������� * �����+� �� ���#�� �� ���������������� �����������������������

� ����������(��� ��� ��� ����� �� ��#����� ��� ��� ���� ��� ������� ��� ���������$��������#� � ������������� ��#������

� ,� ������ ��� ����� �� ������ ��#����� ���� #�� ��� ��� ��� ����� �$� ������������ ����� ��������

'� ������������������������������ ������������!��� ��������������������������������������� �������������� ������ � ��-������������������(�������������������������������������������� ������������������������ ���������������������������� ���������� �� ����#� � �� �� ����� �� �� ���� ���������� �� ��������� "�� ������

Page 8: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ��� � ���� ��

� ��� �������������� ������������� ������������������������ ���*&.+� �����������(�������

��� ������ �� ������������ �%����� � ������ �%����� ��� ������(��������������� ���� �� ��� /�#�������� .� ������� ��� ����� 0.0� ������ ��� �#�������������(������ ��� ��� ����� ��� ������� ��#���������� ������(��� ��� ������ ������������ ������� ������������������ �������������!��� ����������������� ��� ��������������� 1���� �� ��� ���������� �� ��� '�������!�� �� ��� .����������� �� ����������������� ��� ������� �� ��� ������������ �� ����� �� ��� ����������������������� ����� ������� ���(�� �����#� ���� �� ������� � �� ���������� ��� ���������#�� ���� ������ ��� �������� ����� � �� �� �������� ��������������� ����������������������� �� ����������� ����������������������� ������ ����������� ������������������

2��� ����������������� ��&������ ��.�������������!�$�

��� ��������� ��� � ��� ��������� ���� �������� ����� ������ ������� ��� ������ ����������� ������ ��� ������������ ��� ���������� ����� ���� � ������ �� ����������� �� ����������� ����������� ���������������� ������������������������������������ ��� ������������ ��� ��������� �� ����� � ���������������������������� ���� ���������� ��� ���������� ��� ������� �� �������������������������

Elementos de un SI

� ���� ��� ���������� �� ���� ��� �� ��� ����������� ���� �������� ���� �������� ��� ��������� �� �� ����� �� ����#� � �� ��������� ����� ��� ������������������� �� ��� �������� ��� ������#�� �� �������� ������ ������������������������ ����� �������� ��������� ���� ������� ��� ���������������� �� ��� ������(������� "�� &.� �� ������� �� ��� ������� �� ��������������������������������������������������� ���� ������������ ����� ������

� ��� ����� ���� &�� � �� � ������ �� ��� ������� ���� ��� �������� �� ���������� ����� ����������������� �������� ����� ������������������������� ������������������#� � ������������� �������������(��

� ���� �������� �� ���������� .� �#� ��� �� ������ �� ��� ������(������ ��������� ���������������������������������������������(���������#� � ������������� ���������� �������� ����� ������� ���� ���

� ��� ������� ��� �������� ����� ��� �������������� ��� ������������� �� ������������������ �� ������������� ���������� ��� ������ �� #�� ��� ��� &.��-�� �� �������� ��������� �� ����� #���� �� ��#���� �����������$� ����������(��������� �� ���� ���� �����#� ����� �� ��� ����� ����������������������

Estructura de un SI

1������ ��� ���������� �� ��� &.� ���� �� ����������� �� ��� ������� ��������(������ ��������� �� ������� �������(���� �� ��� �� � ���������� ���� ��� ������������ ��������!�������� ��������!�� �������������������������� �������� ����������������� �� ���� ��� ������� ������ ��������������� ����������������� �� ��������������������!�� �� �#������#���� ��������������������$�

� ����� ������������ ������"�����#��������������������������� ���������#� � �� ������ �� ������������� ��� ��������������� ���������� ����

Page 9: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���-� ���� ��

�������� �� ��� ������(�����$� ������������� ������ �������� �� ��� ������ ���������������������������������������������� ���������#� � ������ ������������������������� ������������������������!������������$�

o ��� ����� �������� �� ������������ �� ������� ��� ���� �� �� ��� ��� ���� ������ ��������

o 1��������������%������������������� �����������������

o ������������#������� ���������������

o "%�������������������� ��������������������

�������� �������� ��������������� ���������������������� ��������� ����� �������� �� ���������� ��� ��� �� ���� ��� ������ ���������� �� ���� �� ������ ������������ ����� ������� �������� ������ ������� �������������������%�����������

� ������������������ �� �������������������� ��������� ����������� ���������������� �������� �� ��� ������� * ������� �������� ��������� ����+������� �������������������������������� �������������������(���� �������������������� ��*������#������������ ��������������� �������� ����� ��� �������� ����+�� &�� ����� ��� ����� ���� ������������ ����� ����� ����������� ���������������������������!�������$�

o "���������#��*������������� ���� ��#����������������+�

o ������ ����������� ��*������ ����������+�

o ���� ����������� ����������������

o ��� ��������������������������� ������������� ��

o ��� ������� ������ ������������

� ��� ����� �� �� �� �� ��������� �� ��������� �� ��� ���������� ������#�� ��������� �� �� ��� ���(�� *��� �)�+� ����� �������� ��� ��� �������� �� �����������3������������������������������������ ���������� ������������������$�

o /������� ���� �� � �� ��� !����� *�� ��� �� #����� ���� ������������������� ��������%���������+�

o ����%��������$��������� �������������������������� ���� ������� ������������������ � ��������

o "���!����������������� !����� � ���������������� ������#��������������� ���� �(� ����� ����#��� ��� ��� ����� ���� ��������� *���� �� ����� ������������������������������� ���%��������+��

"��������� �� ������������ �� ������� ��� ��� ������������ ������ ����� ���� ������������������%������������ ������� � ����� ������&����� �������������������� �� ��� ���� ����� ���#�� ��� ��� ����� ��� ���� ��� �#� ������ ������� ������ ��� ��� ������������ ����� �� *�� ����������� ��� !����+� �� �� ��������(�����������#�������� �������#������������� �� ���������������������* ����������������+� ����� �%������ *���� ��������� ��������� ������ �� ���� ��� �������������������������)!�+��

� ��� ����� ��������� �� �� ��������� ��� ���� ���� ���(�� ������ *456� �)�+��������������� ��� ������ �� ��� ��� ��� �!��������������� � �������� ���������������������������������������������������� � ���������������������������������� ����������� ����#�� ����� ����������������������������� �%���� ������� �� ��� �����)!��� &�� �������� ������������ ��� ������������

Page 10: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ � � ���� ��

#���� ������������ ����������%���������� �������������� � ������������ ���� ��#��� ���� ����� �������(� �� �� ������� ��� ������� ������������ ����#���

"%����� �� ������ ����������� �� ������ �� ������������ ��� ��� ������$�����(�������*������������ �������+���#���������* �� ���������������!�+��"���������������������������� ���� �������������������$�

�� ������ ����� ����� �� �������� �� � �� ��� �� �� ��������� &�������������������������� ��������� �� ���������#� � ���� ��������������� �#��� � ��� ���� ������� '������ �������� ��������� �� ������������ ������ ���

!� ������ ����� ����� ��� �������� �� ����� �� � �� ��� ��� &�� ������� ���� ���$� ��������� � ����#������ �������� ��������� ���������� �� #��������������� ����� '�� ���� ��� ��� �������� ��� ������� �� ����!����� ������������������������� ���������������������������������������

"� ����������#��������������������� ����������#��� �������� � �*������������������������ ������+�� ���������������)���� ���������������� ����������������� �� ������������ ��������,������������������������� ���� ����� ��������� ������������ �� ���� �������� ����� �� ��� �������������� ��� � ���������� ���"��� ���������������������� ���������������� � ������� ������ ��� ����� ��� ���� ��� ���� ������������ �� ������ ����������� ���� �%����� ������� ����(������� �� ������������� ����� ������������� �����������"�����������(������������������������!�� ������������������������������(�������������������� � ��

��� �������� ����� �������

�������������� � �� ���������� �����#�� ��������!���� ��� ������ ��������00����������������� ��� ���������� ������������ �����&.��&�������(������������� ������ ����������� ����������������������������� ��������������� ���������������� ����� �� ��� �� �����(��� ��������!�� ������� �� �� ������������ �� ���������������������������'.���

"������������������������������������������&.����������������������(���� ������#� � ����������������������� ��������������(� ���������������������� �� ������ �����(�� �� �����������$� &������ �� .����������� 1�������(� ��*&.1+��

"�� &.1� � ��� ������� ���� ��� ������� ����������� ����� �� ��� ����������� "������ ���� �� ��� ����������� ���������� ���� ���� ������������ �� �� ������������ ���������������������������������������������� ��������&.1��

��� ��������(������ �� ��� &.�� �� ������� ������������ � �� ����������� ������������ ������ 7�������������������������� ���� �� �����7���� �� ������������������ ��� ����������� �� ��� ������������ ���7���� ���� ��������� �� ���� �������� � �� �� ������������ ���� ������ ��� ���������� ��� &.�� ��� � �������� ������7���� � ���� �� ���������� ��������� ������ ��� �����(�� �� ��������(������ ��������������������������� ��#�(��%������������������� � � �������������7���������������� �� ��� ��� �������� ����� ����� ��������� ��������!�� �� ��� ������������������ ��� ������������ �� ���7���� �� �� � �� ��� ��� ������ ��� � ��������� ���������������%���������� ������������� �� ��������� �����7������������&.��

Page 11: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ $ � ���� ��

��� ���� ����� �� �� ���� ���� ��� ������� � � �� � ���� ���� ����

&�� �����(���� ��� ��������� ��� �� �� ������� &.� ��� ����������� ���������� ��� ������� �%���� ������������������ �� ��������� ����!����� �� �� ���� ������� �� ���� �������� �� ������������ ��� ���� �� �������� #����� #���� �� ������������� ������ �� ��� ��� ������� �����#��� "��� �� �� ������� � ��� ����������� �������� �������� �� ���� �� �#��������� ��� ��� ������ ��� ����������������������(����� ���������������� ���� ���������� ���������� ��� ������� �� ������ ���������� ������ ������ ���� ���� �� �������� ������� ���� ����������� ��������� �����������������

"��� �������������� ��� ����� � ��� �� ���� ���������� ������� �� ������������ ������ ��� �������� �� ��� ������� �� �������� ��� ��������� ��� ������������������������������ ��� ������� ���������-���������#���� �#!����� ���������������� ���� �� ���� �� �� ��������� ��� ���� ������� � � �� �� ���� ����������(������ ���������� ��������� �������������������� �����������������������������(��� ���������������������� ��������

-������������������ ���� ������ ����� �����������������������!�������������������� �� ������ �� ���� ������ �� ���%� ��� � � �� �� � ���� ��� � � ������� �� ������ ��� ���� ���������� ���� ������#������� ��� ��� ��� �������� �� ��������� ���������������������

&�� � ����������������������� � � ������������������������ ������������ �� ����������� ���!�������#����������������������� ������� ��� �� ������������������� ������������� ������������ ����������#�(�������� ���� ������ �� ��� ������������� -��� ������� ��� �������� �� ��� ��� ����� ����� �� ��������������� ����� ������������������� ������������#���������� ����� ������������������� ���&.���������������� ������������(����������������������������������������� ��������� ��� ��)� �������������������������������� ��������������������������� ���� �� �� ��������� ��� ����� � �� �� ������������ �� �� �� ���������(�����8� ����� � �� ����� �#��� � � �� #�� ������� �� ��� ��� ��������� �����������

����������� �� ��� �������� ����

1����������� �� ����)������������ ����������#��&.�� ��� ��������������� ����������� ��������� ��������� �� ���������"��� ����������� ��� ��� ��������� �������� !�� �� ��� ���� �������� �� ��������� ��� ��� ���������� �%������� ��� ��������������� �� ������ ����������� �� ������ �9�� �!����� 1������ �� ���� �������#�������� �� ��� �������� ����� ��� ������ ������� �����!��� �� ���� ����� ����������!�������������������������������� ���

-���� ���� ���� ����� ��� ����� ��� �� ���������� ����� ����� ������ �������� ����� ���� ����� �� ������ � ��� ��� ������ ������� ��������� ��� �� ���������� �� �� � �� ���� ��� ���7���� �� � ������������ �� ��� ������������ ���� �� ��������� ���������� ����������(��:�� �� �� ��� ��� �� ���� ������ ��� !�������������������������������

1��� � �����������������!���#��(� ����������� ���������������������������������������������� ��� ������������ ����� �������� �� ������� �������� ��������� �#�������� ��� .������������ ��� ������#�� ����������������� ���� ������!���

Page 12: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ �� ���� ��

��� ������ ����� �� ��� ������������� ���� ������� ��� ���������� �� ���� � !��� ������� ������ �� ��� ����� �������� �� ������ �� ��� ������������ ������ ������������������ ��� ����������� ���� ������ ������ 7�����

1�� ��������� ��� ������#�� �� ��������������� ���� ������!��� ��� ������ ������� *���������+� ������������� �� ���� �� ������������� ��������������"����������������� �� ��� ������������� ���� ���� ������� ���� �� ���� ������ ������ 7����� ����� ��� ���������� �� ��� ������������ ��� ���� �� ���� ������ �� �������� �������� ��������������������������

���� ��� ������� �� #��� ��� ����� � � �� �� ���� �(��� ��� ���������� �� ��������������� �� ��� ����� �������� ������� �� �� �� ������������� 1��!� ����� ������������ ��;��� ��������&���� �������������������� ��������������������� � ��������� �� �� ���������� �� ��� ������������ ��� ������� �� ��� ����� �������� �������� �����#������������������������������ �������������������������������������������%���������� ���� ������ ����� ���������������������� ���������"����� ���� ������������ ������ �$�

� $������ ��� ���� �� �� ��� ����� ���� ��� ���� ��� ��� ���� ������������������������ ������ ����������������������������� ����������������� ������������������������������� ����������������������������!���� �� ��������������������������������

� $������ ��� %�� �� �� ��� ����� ���� ��� ���� ��� ���� ������ ��� ������ � �� �� ��������������� �� ��� ���������� �!���� �� ��� �������������������� �� �� �� ���� ������ �� ��� ��� ��� ��� ��� ���������� ����������������������������� ���������� �����������������������������

���� � ��������������������� ��� �������� ��������� ��������������������

��� ��� �� ��������� ���������������������#���������������� ������������������ ����������� ����������������� ������� � � �� �������������� ����� ������ ����������� �� ��������� �� ��� ��������� ��������� ����������� � ��#������������������������������� �����������������$�

� $������ ��� ��� ���� ������ ����� ��� �� ���� ������������ ���� �������5� 2�� ��� ��� ��� ��� ������������ �� ��� ���� ��� ���������� ��)������ ��� �� �����-�������������������� ����������;��� ���������������������!������������ ������������������ ��������������������������������� ���� ����������������������������� ��������������������� ���������&.�������#�������� �����������(�����������%���#�� �������� �����������

� &����� ��� ��� ���� �����������5� ����� ��� ������������ ���� �� ������� ����������� ���� #�(�� ��� ��� ������������ �� �����(��� ������� ��� ����� ����� ���� ��� ���� ��� ������ �� ��� ����������� 1�� ���������� ����� �� ������ �� ��� ����� ��������� ��� ��� ����� �� ��� �������(��������� �� ������

� '���������������������������������������� ����������������������5��� �� ������� ��� ��� �� ������������ �� ��� ����� ������ ���� ������������ ������������������ ���������������

� '���������������������5�1 ��� ���������������� ������������ ��� �� ������� ��������������������������������������� ������������������� ��������� �� ������������ �� �������� �� ��� ���� �� ��� ����������� �#� ��������������������

Page 13: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ (� ���� ��

� '����� �� ����� ��������� ����� ���5� "�� ��� �������� ������ ��� ���������������� ���������� ����������������������������������"��� ��� ����� �� ������� ��� ��� ��� �� ���� ��� ���� ��� ���� �� ���������������������� ��������������

� '����� �� �� ��� �� ��� �� �����(� ������ ��� �� ������ ��� ��� ���������� �� ��� ��������5� ��� ���� ���� �� �������� �� #��� ��� ���� #�(���������� �������� �������� ���� ���������������#����������������������

� )��� ��� ���� ���� ��� ��� ���� ��������51�� ���������� ����� �� ������ �� ��� ����� �� �� ���� ��� ���������� �� ������������������� ����������������������������������������������������� ����� ����������������������� ���������������

"�������������#������������������������ ��� �� ���$�

� $����� ��� �������5���� ������������� ����������� �� ��� �� �������#��������������������#� ��������������������!�������������������7������ ��� �������� ��� ������������������������� ���&3;���

� *������� ���� ����#����5� �� � �� �� ���� ��� ������������� ����� ������������������(��������� ������������ �� ��� ��� �� ���� ���� ��� ��������������������������(� ���

� $������ ��� ������ �� ��% ���5� �� � �� �� ��� ����� ����������� ���������������� ������ ��� �� �������������������������� �������

� ����� ��� ������������ �� ����� ���#��5� �� � �� ��� ����� ��� �������� ���������������������������� �����������������#���

� �� ���� ��������#� ���5� 2�� ��� ����� ����������� ���� �� ����� �������������������������� �������������� ������ ��� �� ��������������� ������ ���(����������������������������������������� ����������� �� ��� �� ������������������������������� ��������������#��� ���

� +������ ����� ��� ����%�� �� ��� ��� �� ��5� "�� ������ ��������� ����������� ������������� ��� ������#��� �� ����)��� �������� �� ��������������������������� ���������������������&3;�����������

� � �������� ������ ��� �������� ����

-������������;��� ������� �� ���� �������������� ��������������������������� ����������!����$�

� ,������������ ����� ��� ��������� ��� ��� ��� ����� ���5� ���������(������ �� ��� ������������ ��� ��� ��� �� ���� � �� ��������� ���� �������������� ����������� ������������ �������������������������� ����� �������������%������������� ��� �� �����"��������������������������� ������!���� �� ���� ���#� �� ������������ �����!���� �� �����%����������������������!�����

� +������-��5� ���� ���� �������� ��� ������� �� �������� � ���� ������������ ������������������������������ ���������������� ��!���� �� ������������������ ������������ ���������

� '%���� ������ ���5� ��� ��������!�� �� ;��� �� ����� ������ ���� �#������(�������������� �� �������������������#����� ����� �� ������ ���������������������� ��� ������ �� ����������������� �� ��� �����#������������;��� �����������#��������������������� �� ������������������������ ����������� ���������� ���� �%����� ������ ��� ���� � �� ����

Page 14: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ *� ���� ��

������� ������ ��� ������� ��� ��� ������ ��� �%�������� �� �� �� ���������#���� ��� ����� �� ������������� �� ��� ������������� ����� � �� ��������������������������

� &��� ��������� ����5�2��� ��� �� ���� � ���������(� ������� ������� ��� ������� ������ ���� �� ���������� �������� � ��� ��� ������������ �������������� ��� ������������ ���#�� ��� ������� �� ��� !����� �������������������� ������ ������� �� ��� ��� ������ �� ����� ��� �� ��� ���������� ��������

� .����� �����5���� ��� �� ����������������� ������� �������� ���������������������������������������������������������(�� ������ �������� �����#���� �������������� � � ������� ����� �������� ��� �� ���� � �������� �� �� ��� ��������������� ������� ������ ���� ��������� ���#������������ ��� ��� �������������� ��� ��� ����� ���� ������������ �� ����� ����������� ������������������������������������������ � ��%���#���

� $���������5� <����� � � �� ��� ���� �������� �� �������� �� ��������������� �%������� ��� ��� ������� ��� ��� ����� ���� ������ ��� ��� �� ����� =����� ������� �������� ��� ���� ������ �� ��� �� ����������� �������� ���� ������� ��� ����� ���� �� ������ ������� ��� ������������������(����������� ������������� ����� ����� ����� �� ������������������

�������� ��� ������������� ��� ��� ��� ������ ������ �� ���� �#������������(�$�������� ������������������ ������ 7��������7����������1!�� �������� �����������������������������������*������������������(�����+� � ��������������� ��� ������ ��� ���������(��� ��� ������� � � �� ��� ������������ ������� �� ������������������� ������ ���������������������������� �� ��������������� ���� ������ ������������(����

-���� � ���� ��� ������� � � � �� �������(���� ���� �������� �� ���#����� � � �����!���� �� �������������������"������ ��� �� ���� � ������ ������� ����� ������������ #�������������� ��� #������ �� ��� ���� ��������� �� ��� �������������� �� ������������ �%���! �� ��� ������ ������ ������

� .�����������*���� �����5� �������� � ����������� ��������� � � ������ ��� �� ��������������������� ���������������� � ���������������������������� ������������������������� ������������������� ���������������� ���#��� � � �� ���� ��� �� ���� ����� ����������� �� ��� ����#�� �� ���������������������������������(� ����

��� ������������ �� ���� ������� �� ��� ���� ���� #������ ���� ������������� ���� ��� ���� ���� ��� �� ���� � ��� ��������� ��� �����������������$�

o &����� � � ������� ��� ���������� �� ��� ���� ���� �� ���� ��� �������$���������� ������� �������������

o &����� � � ������� ��� ���������� �� ��� ���� ���� �� ���� ������ ��������� *��� 7���� �� ���7���+� �� ������ ���� ��� ���� ��� ����������������

o &����� � �����������������������(� ������� ��� �� �����

o &����� � ���������������� � � ������� �����

Page 15: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ 0� ���� ��

"������ ��� �� �����%����������� �������� �� ������������� �� ��������������� ��� � �� ������ �� �������������� ���� ���������� ������ ���������� ������������ ����#���� ��� ������ �� ��� ���� ���� ��� ������� �� ��� ��� �� �����

� /�� ���5�,��%� ��� � �������� ������� ���������(������ �!���� �� ��� ��������� �������� ��� ���� �����)�� ��������� ��� #������� �� �������������������������������������� ��#���������� �� �������� ���������� �������������������� �� �����

� $����#� �� ��� ������� �� ��� ������5� 2��� ��� �� ���� � �� ������ �������� ���������� ������������������(� �� �!������������� ����� ���7����* ��� �� ��������+� �� ���������������������������(�������� ��� �� �����.������������%������������ ���������������������������������� ����� ��� �� �������������������#����������� ���������(�������1 ��������#������������������������� ��� ��� �� ���� ������� ��� �� ��� ��� �� �� ���� �����������

��������������� �������� ��� �������� ����

"�������������������������������������������(������ �����!��������������� ��� �� ����� ���� ������� ��� ��������!����� ��� ��� ��������� ���������� ��� ��� �� ����� "�� ������� ������� ��� ������(������� ��� ������������������������ ��������������%����������������������������������� � ����������������������������������������������

����� ��� �� ������������ ���������� ��� �� ��������� � ����������������� #����� �� ��� ���� ���� ��� ����(� �� ����������� ������������ �� ����������"%��������������#������ ����� ����������� ��� �� ���$�

� ,������0�����5�"� ���#����� �� ��� ��������������� ����������������� �� ���� ��� �� ����� 2�� ������� ������ ���� ���� #����� �������� �� �������������������������������������#����������� ������� ��������#� � ��"����������#����������������������������������������� ���� ������ ������������ � ���������������!���� �� ������������� ��������������������

>�����������* �������������������������� �����+�#������ �������� �������������� �������������������!���� �� ������ ��������������������� ��������� ����������������� ���������������

"���#������������������ �� ������������������������ ������ �������� �������� �� ��������� �� ����������� ���� ���� �������� ������ �� ��������������� ����� ��� �� �����

� ,����� � �������5�/������������� ������ ����������������������������� ��� ��� �� ������ 2��� ��� �� ���� ���������� ��� ������������ �� ������ ����� ��� ��� �� ������ &�� ���������� ��� � ����� �� ���������� ���������#������ ��� ��� ������ ��� ������ � �� �� ��������!����� �� �������� � ������������������� ���� �����������%�����������������

��� #����� ����������� �� ���� ��� �� ���� �� ���� ��������������� ������� ��� ��� ����� �� �� ���� ������ �� ����� #�� �� ��� ����� �� ����������������� �� ���� #������ �%������ ��� �� ������ �� �� ����� ��������������� ��� �� ��� �������� �� �!���������� "��� #����� ����������� ������ ������������������ ��������������(�� ������ ������

Page 16: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ �� ���� ��

� ,�����%�� ��5�/������������� ������� ��� ���������������������� �������� ������#�� ������������������"���#����� ���� �� ���������������������(������� �!����� ������#��� ��������� ����� �� ����� ���������������� ���� ����������� ��� ������� ��� ��� ����� ����� � ��� ����� ���������������������

"��� ���� #������� ��� ����� � � ������� ���� ��������������� ��� ����� ������� ��� ��� ����� �� ��������� ��#���� �� � ���������� "�� �� �� ��#��� �� ���� ������������ ������������ ����������� � ���������������� �������#��� �� ��� ��� �� ����� "�� ������� ������ ���� ������ �� �� �������� �� ������ ��������������� �������� �� ��� ��������� �%������ ���� ������� ��� ������(������*#����� �%�����+�� "�� ��)� ��� �� �������� �� ������ ���� ������ �� �� ����� ������ � �� �� ����� �� � ��������� �����#��������� ��� ������� ������ ��������� ���������(������ ����� �� �� ���������� �� ��� ����� �������� ���� ���#�� �� �� �� ���������(��������������������������� �����*#���������������+��"��� ������� ��� ����� ��� �� ��������� ������� �� �� ���� ��������#��� �!��������� ������������������������(������ �!����������� ���������(������ �����)��������� ���������*#������!���+��

"��� ����������� ����� ������ �����������#���� ��� ����������������(���������������������� ���� ������ ����� ���$�

� ?������ ������� ����� �����������(�������!������������������� �� ����� ���������� ����������� �� ��� ���� ����� ���� �� ������� ��� ��������� ������������������������������������������

� ?��� ��� �� ����� ����� �� ��� �������������� ����������� ��� ��� ����� ������������������������������� ����� ����������������!���� ��������������������� ��� ��������� �� ������������ ������� �� ���� �� ��� �� ��������� �� ���������������������������� � ����� ��������� �� ������� �� ��� ���� �������#�����

� ?��� ��� #������ �%������ ��� ��� ��� ���� ��������� �� ���#��������������������������������������������������������� ��������������� ���������� �� ���������������#��� ��� ����������

"���������#���� � �������� ���� �����������������������!�� ����� ��� �� ���� ��� �� ��� �� �� �������� &��� �� ������ ��� �� ���������� ���� ������� ���� ������ ����� �����$�

� 2��������������������������������� ����� ������� �������������� ��#����� ������ �!���������� ��� �������������� �!���� �� ��� ���� #�� �� �������� ��������������������������������� �� �����)���

� "�� ������� �� !���� �� ��������� �� ��� ����� ��� ���� ���������������%������ � �� ��� �� ���� ������ �� ����� ���� !���� ���� � ����������� ����������#���������������� �����������������������������������������

"����#�����������������������#������������������������������ ����#������ ������� ��� ���� �� ��� ��� �� �� ���� � �� �� �������(�� ���� ��� ��� �� ������������������� ����� �����������(�������

2��� ���������� ����������� �� ��� ������(������ �������� �� �� ��� ���� � ������ �����#������ ��� ��� ��� ������ �� ���� ���� �� ������ � ��� �!� ����� ��������������%�������������������&�� ���� ��� ���!���� �� �������� �����#��������������������������� ������������������������������������������� ������

Page 17: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ 8� ���� ��

&����� ������ ���������� ��������� ���� �#���� ��������� �� ��������������������������������������� � ������������� ���� ���� ��������������#��� ��� ����������������������������� �� ��� ������������������� ��� �� ����������������� ���=����������� ��� ���������� ����������� ��� ��� ������� �� ���� ������ ����� ������������%���������!�������� ���������������������������� ����������������� ���#�� ����� ������������������������ ������������������� ����������� ���������������������� ���� ������� ��� ������� ����� ��� ������������ ��������� �� ��� �� �������� �������������� ������������#��������������� ������������������������� �����������������������������

������������ ���������#����#��� ���������������� ��� ������� ������ ��������� ��#��� ���� ������ ��� ���7���� ������� �� �� ���������� ��� ������������� #�� ���������(�������� ���� ������ ������������������������ ��� �� �����

� �������� ����������� ���������������� �������� ����

2��� ����������������� ��;��� ���������!�$����

���� ���������������������� ������������������� ��������������� ������������������������������������������ ������������������ ���� �� � ������ �� � ����� ������� ��� ��� ��� ����!�� �������� �����"������� ����� ��� ������ ��������������� �� �������������������� ��������#����� �������������������� ��������� ���$�� �������� �� ���� ����� ��� ������������� ��� ��� ��������������� ����������� � ��� �������������������������$������!��� �������������������������

"� ������������������� ��� ���������������� ������������� ��� �� ������ ������������&������ ��3������ ��;��� ���������������������������� ������������� �� ���� �� �� ��� ��� ���� �� ���� ��� ������������ ������ �� ��� �� ������������!������� ������ ��� �� ��� �� �������� ��� ���������������������� ���������� �� ���� ����� �� ��������!����� �� ������������� ����� ����� ���� ��������������� ��� �� ��� �������� �� �� ��� ������ �� ��� ����� �������� �����������!������%��� �������� ��� �� ���������������������%������������� ������� ���������������������7����������������(� �� ���#������� �� ���� �� ����1��������������7�������������������� ��������&������ ��3������ ��;��� �������*&3;�+��

2��&3;������������������ ����������� ���������������������������������������� �� ��� ��� �� ���� ��� �� ��� ��������� ����� �����(��� ��� ��������������$�

� ����������� ����� ��������� ���������#���� ��� ���������*�!���������������%�����+�

� =������������ �� ��� ���� ��� ��� ��� �� ����� "� ������ ��� ������������ ����������� ���� �������������������������������

� =������������� ������������ � � ����� ��� �� �����.������ � ���������������� �������!����#���������������������������������

� �������� ��������#��� � �������� � � ����� ���������� ��� �� �����

Page 18: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ � ���� ��

����� �����������������������

��������������������� �����&3;���� ��� �� �����������������������������������

Función de definición o descripción

�� �������������� ��)� ��� ����� ��� �� ��������������������������� �� ��������������������������������������������������%�������������������������� ��������� � ����������������!�����������������!����� ��������!���������#����������� �������������

"��� �������� ��� �����(�� ��� ��������� �� ���������� �� ���� *���+� ������� ���� �� &3;��� � �� �� ���������� ��� �� ��� ����� ������� ��� ���� ���������� �� ���� *�%������� ������� �� �������+�� ���������� �� ��� ��������!����� �� ��� ���� ���� ������ ��������#�����

Función de manipulación

2��� #�(� �� ��� ������� ��� ����� �� ������� ������� ��� ���� ��� ����������������#������������ �������������� ��� ��� �� ������������ �������������������(�������������������� �������� � � ����������������������������� ���������(���������������������� ��� �� ������ ����� �� ������$�

� &� ������������ � � ����� ���������������������������� ����� ���� �����;������ ����� ����� �������� �������

� �������� ������#��� ��� ��� ���� �� ��� ��� ���� ������(��� ��� �������� ���������������� �������� ����� ������*��������� ����������+��

����������(����������������� !�� ������ ��� �� �������� ����������� ������������� ������$�

� .�������� �����#������������

� ;���� ���������������� ������������

� =� ���������� �� ��� ���� �� �������� �������� ��� ��� ������ �� ��������� ��� ����� ����

��� �������� ��������������� ��������(����� ��������� ��������������� �� ����*�=�+��������������������������������������(��������������

Función de Control

�� �� ��������� ���� ����� �� ����������� ����� ���������� ��� ������ ���� ������� ���� "�� ��� �����!�� �� ��� &3;�� �%����� ��������� �� ��#������ �������� ���� ��� ������ � � �� ��� ��������� � ������ ��� !����� �� �����(������� ����� ����������������� ������������ ������ �������� � �*������ ������� � �������������������� ����! �� ��������������+��� �������������������������������������(� ���

Page 19: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ���$ -� ���� ��

�����������������������

-���� �����(��� ��� ��������� ���������� �� ������� �� �� ��������� ���� ���&3;�� ������� ���� ���� ����� �� ����������� ����� �������� �� ��� ��������� �� �����������������������������������������������������������

� ��� �������� ��� ���� ��� ��� ������ 1++�2�5� -������� ������� ������������������������ ����� ����

� ������������������ ���������� ���������������������1+.+�2�5�"����������!�� �����&3;���������������������������������� ���������� ����� ���� ��� ��� ��#��� �� �������������� �!����� �� ���� ��� ����� �� ���� ����������� �� ���� ������� �� ��������� �� ���������� ������������������ �� ��� ����� � "�� ���������� ���� �� ������� ��� ������������ ������ ��� ������� �� ��� ��� ����� �� ��� �� ��#���� ��� ���������� ������� ���������� ��� ��� ����� ��� ������ "�� ��� ������������� ����� �$�

o �����������!����� ������ ���������#���������$������ ��� ����������������� � ��� ���������� ������ � ����� �� �� ������ � ��� ������������������ ���������� ��� ���������� ����������������

o ��� ��������!����� ��� ��� ����� �� ��#��� �!���$� ��� � �� �!���� ��� ��������� ��� ���� �� ������������ #�������� �� �����#�� �����(� �����������!����� �!���� �� ������� �� ��� �� ��� �� ��������������� ������ �� ��������������������������

1 ��� ����&�������������������������� ���������������� �� ��� �������� �� ����� � � �� ��� ����� "��� � ��������� �� ����������������� ���������� �� ����*���+���������������������� ���������� ����������������������� �������� ����������� �� �����

� ��������������������� ������������1+'�2�5�=� ��������������������������(��� ������������������������ ����� ���$�

o ��� ���������� �����#����%�������� ��������� ����� �����

o ��� ������������� �� ��� ���8� �� ������ ��� ���������� ���� ����� ���������� �� ������������� �� ��� ���� �������� �� ��� ��� ��� �� �����

����� ��� �� ��� &3;�� �� ����� ���� �� ���� ������ �� ���� ������� ���=�$�

o -���� ���������5� ��� ��������� ���������� ���� ��� ��� ��������� ����������������������������� ������#�������������������������������� � ��������(���������������

o :�� ����� ���������5� &���� ���������� ���� ��� ��� ��������� ������������� ���� ���� �� #��� �� ����������� ��� �� ��� ������� �=�� ���������� �� �� ������������������ ����������������#�������������

"�������������������������������������������%��������������� �� ��������� �� ������� ��� �� ���� ���� �������� ���� ��������� ���������������� ���� �����)���

Page 20: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ����� � ���� ��

'�� ���������=������������������� �� ���� ������#������%������ ����� ����� �� ������ ���������� �� #������ ��������� ���� ��� �������������� ���������� ����� ��� �� ���� ����� ���� ��������������"���#����� ��� ���� ������� �������������� ��� ��� �����(���� �� �������$�

o ������ �������������� ����=��

o ������ ����� ������������������� ����������>;>��������=� �������������� �� �����(��� ��� ��������� �� ����������� ���� ��������� ��� ����������������� ��� ���� �� ��� ��� �� ����� "�� ��� �� ���� ������� ������������������������������������ ����=���

� ����� ����������������5���������� �������#����������������������������������� ����� ����������� �������������� �������� ��� �� ������&�������������� ����� ����������������(� �������������� ��������� �������������� �� ��� �����(� �� ���� ��� �=�$� ��� ������� �������� �!���� ��� ������� ����� ��� �� �����1 ������� ����������� �� ������� ������������$�

o /����������� �����#��� � �������������� ������������ �������� ��� �� �����

o /���������������������������������������������� � � ����� �����

o .�����������������������(��� ��� ������� � � �� ��� ������������ �������� ��� �� �����

� ������������������������������5�"������������������7����������� �� �� �������(��� ��� ���������� ������� !������� �� ���������� ������ ����������������� �� ��� ����� -����������� ���� �������(� ������ ��� ������������ �� �� ��� ��������� �� ������������ '� �� ��� ����������������(� ����� ��� ��� �� ���� � �������������������� �������"����������� �������������#��� ��� �#��#��� ����������� ����������������������� ������������������������������� ������������(���"���������� ��� �$�

o 3������(��� ��� ���#��� � � �� ��� ����� ��������� �� ���� ������ �� ����������������(� ���

o 3������(��� ��� ����� � � �� ��� ����� �����(�� �� ����� �������� ������� ��� ���������� ���� ����� �� ��� ������ ���� �������� ��� � �� �� ������������������ �����������

o 3������(��� ���������� � � ����� ������������� ��������� �������������������������� ��� �� ������������� ��������������� ����� ��������������� �����������

o 3������(����������������������������� ��� �� ���� ������������#��������������� ������� ������������� ������� ����������������#������������ � �� ������������ � � ����� �����

o .�������������������� �������������#����������������������������� �������#�������������������� ���������=����� ����������� � ����������������������#������������������������������������������������� ������������������-������������������ ������ �������������������������

� ��� ������������� ��� ��� ����� ��� ������ 1+3/2�5� "� ��� ������������������ ���� ���� ����� �� ������ ��� � �� ��� ������� �� ��� ������������ ������������� ����� � �� ���#��� � � �� ������� � � �� ��� ������������� �!��������� �����)�� ���&3;��������������������� �����������"���������������$�

Page 21: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ �R������ � ! ������������� ��� ����"��� �! ��/ �������� ����� ��� ����� � � � ����$ � ���� ��

o ����������� ����������������� ����� ��� �� ������� ��������������������

o ����������� ��� ������� �!���� �� ��� ��� �� ����� ���������� �� ������������� �� ��������������� ������ �� �� ������ �� ��� �������������������� �������� ������#���!�����

o ����������� ��� ���������#�������%������ �����������

o �������� ��������#��� � � ����� ������� ��������������� �����#������������������������ ��������������������������������������������� �������� ��� �� �����

o =������������� �� ��� �������� ����� ����� �� �� ����������� ��� ���������� �������� ��� ��� �������������� �!���� �� ��� ���� �� ��� ���� ������� �������������

o "������������� �� ��� ����� �������� ����� �������������� �� �������� � � ����� ��������� ���� �������������������(����� ����������������������������(���������� ������� �������������� �� ����� ��������� � ����������� �����������

� ���������������������������������5���������������������������������� ��� �� ���$��

o 2������ ����������5� ��� ���� �������������� ���� ��� ��� �� ���� �����#�� ����������� ��������������

o 2������ ��������5� 1������� ���� ���������� ��������� �� ���������������#�������������(� ������������������������

o 2������ ��������(� ��5� 1������� ���� �����(��� ��� &3;�� ����� ������������������������ ��������� �������������������������

Page 22: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R���# �������! �� ������� ��' ��� ��� ���+ � � ��������& ���+ � ����� ��� ����� � � � ������ ���� ��

�� � � � � � � �� � �� �� � � � � � �� ��� � � � � � ���� � � � � � �� � �� �� �� � �

-���� ���� ����������������������������������(������ ���������������� � ����������������������������������� ���������������������������� ������ ����� ������������ ������������������������%������������������������������������ ����������������� "�� ������� �� ������������ ��� ��������� ������� ��� ���������(������ �� ������ ��������� ��� ������ � �� ���� ��� ���������(��� �� ��� ������ �� ��� �� ��������������������������������������"�������� ���������� ������������ �������� � ���� ������ ��� ���� �� �� ���� �� ����� ��� ������� ��� ��� ���� �� ������� ���������� � �����������������������������%��������������� ����������� � ������ �������������������������������

1�� ��������� �� ������ � ������ ���������(��� ��� ��������� �� ��� ��������������������������� ��#�������������������� � ����� ���������������������� �������� �� ���������� ������ ���� ��� ��������� �� ���������� �� ��� ������������������ "�� ������� �� �� ��� ������������ �� ��� ������������� ���� ������� ��������������������������� �����������������#�� ����� ����� ���� �� ���������

2���� ���� �� ���� �������������� � ������� �� ��� �������� �� ������������������ "��� �������������� �������� ���� ����� � ��� ��� �� � �� �� �� �������������������������������� �������������������������� ���������

����� ������ �� ���#�������������� �������� ��� �������������� ��������������� �� � ���������� -���� ����� �� ������� ���� ����� �� ����� � ������� �� ���� ����*�������������� �������������+���������������������������� ��#��������� ����� ��� ���������� ���� ��������� ����� ���� ��� ��� ���������� �������� �� �������������������������� ����� ������������ ����������� �����

&����������������� ����� ����������������������� �� ������������ � ������� ������������� �������� ��#����������� �������� � �� ��� �������������������������� ������������������ ������������������� ��������������

2��=� ���� �������*=�+��������������� �������� ������� ���������������� �� ���� ������������������������ ��������=� ������������ ������� ���� �� ���� �� ���� ��� ��� ������ � ������ ���������(��� ��� ���������� ��� ���������������� ���� ������ � ��� �� ����� ��� ������ � �� �� ��� ���������� ��� ����#��������������������������

����������� �������������� ��

=� ���������=������� ���������������������������������������� ���������� ������ ���������� ��� ����� � ��� ������� �� ���� � ������ ������������ ����� ��������������� �9�� ��������� "�� ������ �� ����� �� ���������������� � �� ������������ ����������������$������������� �� ���������������� ��� � � ��������������������� ���������������������

"�� ������� ���� ����� ����������� ��� ��� ����� ��� ��� �� ����� �� ������������(������ ��������� �� ������ ���������� ��� �!����� ��� ��� ������ "�� �������� �� ���������� ���� ���� �����#������ ��� ��� ��� ����� �� ����� ��� ��� ���

Page 23: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R���# �������! �� ������� ��' ��� ��� ���+ � � ��������& ���+ � ����� ��� ����� � � � ����(� ���� ��

�� � ��������������������� ����������������� ������ ������������������������� �� ������ ������%��������"�������� ����������#��������������� �������� � ��������� ������������������������������������ �� �������� � �������� � �������� �������� ������� �� ���� ������� �������� � ���� ��������������������� ������� ���� ������������������ ����������� � ������������������� ��������� �� ��� ����� "�� �������� ������ �� ���� �����(� �� ����� � ���������� ��� ��������� ���������������������� � ��������� ���� ������ ��������������������������� ����� ���������� -���� ��� ��� ��� �� ��� ������ �� ��������� ����������� ��� ��� ��������� ���������� ��� ������ "��� �������������� ������(�� �������� �� ��� �!����� ����������"��������������� ���������� ��������� � �� �� �������� ���� �������������� �������������#���������� ������������������������������������������������ "��� ������� �� �������������� ��� �� �� ��� ��� ������ � � ��� ����������

La abstracción

��� � ��������� �� ��� ������ � � �� ������ ��� ����� ���� ����� �� � ����� ����������(��� ��� ��� ���#�� � ����� �� ������ ���� �������� �� ������������� 1�� ���#��� ������� ��� �������������������������������� �� ��������������������(� ����� ���� ����� ������� ������ � �� �������� ��� ������ ���������(��� ��� ������ ���� ���������������������������� ������������������ ����� ���������� �������� ������� �������������������� ��������������������� � ������������������#������������������"����� ���������� ����� ��������� ����������������(� �� �� �������$�

� 4������#� ���5� "� ��� � ��������� ���� ��� ����� ��� ��������� �� ����� ��� ����� ��� �� ��� #���� ����� ���� ���#�� ����� �� � ����� ������������� �� ���� �� ��� ����� � ����� ��������(� �� ��� ��� �� �� #�(�� �����������(������� ������������ ��� ������-��������������������������#�(������������� *��������(������+� ��� �����������������������(������ �� � ����� ������ ��� ���� ����� �� ������� �� ����� � ���� &�� ������������ ����#� ��� �� ���� �� ����� ��� ������� ��#���� �� �����������(����������������������

� /����� ���5� "� ��� ������ � � �� ���� ����� ��� � ����� ��� ��� �� ���������������� ���������������2��� ����� *������� ��� �������� �����������������(�+� ����� ��� ����������� �� ��� ��������� �� ������ � �� ���� ������������(���� "�� ������� ��#���� �� ��� ����������� �� ��� ������������ ������ ��� ����� �� ��� �� ����������� �� �������� � ����� ������ �������� � ���������������(�������������� ��� ������

�����������(��������� ����������������������"&@2:����������� ����������� ��������� �� ��� ��� ����������� �� �������� � ����� �� ����� �� � ����� ��������������� �� ��� ��� ��� ���� ��� �� ����� �� ��� ����� �� ����� �� � ����� ����������� ��� ����������� ��� �� �������� ���� ��� ��������� -1/'"@�"��� ������������ ������ ���� � ������������ �� ������������������� � ����� �� ����� �� � ������������� ��������������� ��� ����������������������������� ������������(��������� �������������

Representación de los problemas del mundo real

���� ����������������������������������������� ����������������� ��������� �� �� ��� ��� ����� ��� ��� �� ������������ �� ��� ������������������ ������������� ������������������ ���������������� ���������������������������� �������� ����� ��� �� ������� ��� �� ��� � ��������� �� ������ ���� ����� �� ���� ������

Page 24: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R���# �������! �� ������� ��' ��� ��� ���+ � � ��������& ���+ � ����� ��� ����� � � � ����*� ���� ��

"������ ������ �������� �������������������������������� �������������������� ������������ � �����������������#��������������� ������������������� ���� �� ����� �� �� ���� �� ���� ���� �� ��������� ��� ����� �� ���� ������ ����������������� ������� � ���1������������������� ������������� ���������� �� � ����� ��� ������� ��� ����� �� � ����� ������ ����� �� ���� �������������� �������������� �������� � �� ������������ ������ ��������� � �������������� �� ���� ���������������������� ��������������!�������������������� ��#������������� ���������������������� ��� ����� ������������������������

2��� #�(� ����� �� ��� ����� �� � ��������� �����#������ ��� ��� ��� ����� �������� ����� ������ ���������������������� ��������������(� ���������� ��� ����� �� ������ �������!�� �� ���� �������� �� #����� ����� �� ������� "�������������� ����������������������������������(������������������

"������ �� ���� ���������������������� ������������������ ��� ���������������� �� �� ����� �� �� ��� ������� �� �������������� �� ������������� �� ������������������(������������ � ���� �������������#��������������� ������

1� ��������������������������(������������������������� �������� ������-������ �� ���������������� ����� �� ���� �������#�� ����� �� ������������������������#�������(�� ������������������������� ������ ������������������������� ��� ��� �� �� ���� ��� �������������� ��� ����� ����� �����(��� �������������������������������������� �� ����������

1 ��� ���������������"&@2:���-1/'"@�"����� ��� ���������������� �� � ��������� �����#������ ������ ��� ������ ��� ��������� ������ �� ��� ��� ������%��������������� �������������� ���� ������������������������ ���������"����� ���������� �� ��� ��� ����� �� ��������� ��� ���� ����������� ����� ���� ������������������������ ���������"����������������� � ������������������������������������ ����������������� �� ����� ���� ������������������������������� ���������������� ��� ����� �� �� ������ �� ��������������#��� ������� ����!������ ���������� � � �������� ���� ��������

Análisis de los problemas

��� �������������� ����� ����� �� ���������� ������������� ��������� ����������%����������������� � ������� ������������ �� ����������������� �� �������� ���� ��� �������������� �� ��� ������ �� ��� ���������� �� ��� �� ��� �� ���������������� �� � ��#������ ��� ������ 2�� ������� ��� ��� ����� �� ���������� ������� � �� ��� ������� �� ���� ������ ��� ���� ������ ��� ��������������� ���������

1� ���� ������� �� ��� ������� ����� ������� ���� �������� ���� ���� ����������� ������ ��������������������� �� ����� ���'���!��3������� �� &������� ��� ����� �� ��� ��� ��� ���� �������� �� �� �� ��� ������ ��� ����������������� ��� �������� ������

����������������������������������� �������� ���������������������������� �����������������$�

�� ������� ������������������� ���������� ��������������������������� ������ ����������� ������� ������ ���������������������� ����#��������� ������ �������� �����(���� &�� �� ������ �� ��� ������ ���� ��� �� ���� ��#� ��� ���� ���������� ����� �� �� ��� ��� � ��#������ ������������������ ��� ����� �����(�� �� ����� ����� ��� ��#��� �� � ������������#� ��� "�� ���� ���� �������� ���� ��� ����� ��� ������ �� ��������� ��

Page 25: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R���# �������! �� ������� ��' ��� ��� ���+ � � ��������& ���+ � ����� ��� ����� � � � ����0� ���� ��

���� ������8��� ����������������������� ��#� �� � �� ��� �!����� ���������:�� �������� ���� ��� ��� ��������������� �������� ��� ������������������������������%�������

!� ��� ���� ��� ��� ��� ������� ����� ���� ���������� �� ������ ���� ���������� �� ��� ������ ����������� ��� ������� ;�� ���� ��� ���� ���������� ��� ������ ��� �� ��� #���� ����� ��� ��������� �� ���������������� ����� ������������ � �����������������������������!��"������ ���� �� ���� ���� ���� � ������ ��� ��� ����� ��#��� ��� ��������������������������������������� ��������������������������� ������ ������ ����������#�������� ���������������

&����� ��� ��#������������� ������������������� ������� ������!����� ����������� ���� ������ ������ ������������������������� ���� ������� �� ��� ���������� �� ��� ��� ������ �� �� �������� ������� ��� ������ �� ���������� ����� ��������� �� ��� ����� ���� �� ��� ������ �����

"� ������� �������������� ��������������������� ��������� ���������� ����� ��������� ��� ������� "�� ���� ���� �� ���������� ���� � ���������� � ��� ���� �� #���� ��� ��� ��� ���� ������� ������ ��� ��� ����� ������ ����"���� �������� ���������������� ������ ��������������� ����� �����������#����� ������ ��� ��������������� �������� ����������������������-������ ������ ������� ������� ��������$�

�� ��� ���������� ���� �������� ���������� ���������� ����� ������������ �����)�� ��� � ����� ������ ��� ��� ����� ��� ��� ���� "��� ���������� ������� ���� ��������������� ��� � ����� ��� ��� ��� �� �������� ���� ����������� ������%�������� ����������

� ����� � �� ��� � �������� ������ ���� ���������� �� ��� #������������� ��� ����� � �� �� ��� �� ������ ��� � ����� ����� ��� ��� ����� ������ ����-�������������� ������ ������ �������������������� ������������������ ����������������������� �� ���� ������������������ ����� �� � ��� "��� ���� �� �����(�� �� ������ ��� ��� �� �����������(������� �� ������ ���� ��� � ����� ��� ��� ����� �����������(� ���� �������������������"&@2:������������ ���� �������������� ��� ����� �� �� ��������� �� ���� �� ������ ����� �� �� ��������������� ����

�� ��� ���������� ������ � ������ �� ������ ���� ���������� �� �������� ���� ������������ ���� ��������� �����#��������������� ������"�� ���� ���� ��� �� ���#�� ������ �� ��� �� ��� � ���������� ����������� � ����� ������������ ��� � ����� �� ��������� �������������������� ��� ����� �� �� ������ �� ���� ��� ��������� �� ����� �������������������������������� ���������������������������������� ����������������������������� �������������������� ��� ������

'�� ����� ��� ���� ����� �� ���� ��� ���������� ����� ����� ������������ ���� ���� �������� ��� ��� ��� ����� ������ ��� � ������������������ ��� ������ '� �� ��� ���������� ���� � �������� �� ��� ������������������� ����#����������������������������������������������� �� � ����#�� ��� ���� �� �� ����������� ����� ����������� ���� ��������������#����������������������������������������

� &�� �������������������������������������� ���������������� �������� ��� ���� "��� ���� �� ���� ��� ��� �� ��� ��#��� ���� ���� ��� ���������� ���� #������ ��� �� ��� �� � �� ����� �� �� ���� �� ���

Page 26: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R���# �������! �� ������� ��' ��� ��� ���+ � � ��������& ���+ � ����� ��� ����� � � � ������ ���� ��

� �������� ������������� � ��������������������������������������������� ������ ����� ����������

5� "�� ���������������������������(� ������ ���������� ������ �������������� ����������� ����� ��� ������� ����� �� ���� ��� ��������� �� ��� �!�����*� ��� ����+�� ��� ������ �� �� #�(� ��� ��� ����� ����� �� ���� �������� �!����� �� �����)��� ��� ��� ������ ���� �������� ���� ����� ��(����� ������� ������� �� ���� ��� ��� ���� ��������� ���� ���� ��� ��������������������� ��#��������#����������� ���"� ����������� ����� ������������ ������ ���������� ����������������������������� ����������������� �� ����������� ���� ����������� ��������������������� ��#���

"�� ��������� ���� ������� ��� ��� ���������� � �� ��� ������� ������ ����8� �� ������ ��� ���������� �� ��� �#������������ ��� ��� ����� #�� �������������������������������&���������� �������� ������%��������������������������(��������������������� ������#�������� ������������������������� ������ ����������������� ������#�������������� �� ����������&�� ��� ������ ��� �%����� ��� ���� ���� �� ��������� ��� ������ ������ ����� ������������������������������������� ��������(��������������(� ��� ��� �� �� ���� �� ��� � ����� ��� �����8� ����� ��� �� ���� � ����� ��������������������������������������*��� ����������� � ��� ������������������ �� � ����� �� ���������� ��#��� �� � ��������+� ���� ������ ������ ������ ������

6� 2���#�(� ����� �� ��� ��������!�������������� ������� ��� ������������������� ���� ������� � ��� ��� ��� ��� ��� ��������������� ��� �� �������������� &�� ��� ������ �%����� �� �����(�� ��� � ��������� ��� �� ���� ����������������������� ���������������������������%���������� �������� ��������� ����� ������ ���� ����#�� ��� �������������������������� �#������� ������ ��� ��������������� ����� �� ����� �� ��� ������ �� ������#��������������������������������������������� ���������� ����� �����

:�� �%���� ���� ������ �������������� �� ��� ��� ������ �������� ���������� ���#�������������� ����� �� ��������������������������� �������� ������� #�(�� #���� � �� ������� ������ �� #����� ���� ��� �� �� ��� ������� ������ ����������� ������������������ ��������������������������������-������������� ������������ ������������������#����� ����������������� �������� ���������� � ��� ��� ��� �� �� ��������������� ����� ��� ������ ������ ���� ��� ��� �� �������� ������� �� �������� ����$� ����� ��� � � �� �� ���� ������ � � ����� �����������������������������(�����������������

���������������� ����

"�� ������ �� ��� ��� ����� ������ ���� � ����#�� ��������� ��� �� ���� ������������������ �� ��������!����� ��� ������ "��� �� ���� ��� �� �� ��� ������������������ �������������� ������ ������ ������������������������������� ������������������ ������������������������������������������������������� ����� ��� � ���������� �� ������ ��� ������ ��� �� �����(���� ������������������ �������� ����������� ����������������� ������ ��� �� ���������� ����� �� �������� �.78�'/�� "��� �� �� ��� ��� ��� �� ��� � ������������������� ������ ���������� �������������������������������� ��������������������� ���� ����� ������ �������������������������� �������������� ������ �������� �� ���������������� �������������������� �����������2��=��������� ��������� �� ������ ��� ����� ��� ��� ��� ������� ��� ��������!����� ������� �� ������� ������������

Page 27: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R���# �������! �� ������� ��' ��� ��� ���+ � � ��������& ���+ � ����� ��� ����� � � � ����8� ���� ��

:������ =�� ��� �� ���� ��� ��� ����� ������� ��� ��������(�� ������� �� ������� ������������-����������������� ������ ��� �� ���$�

�� 2��� �� ����������� �� �� ������� ��������� � ��������� ������������ ������ �������� ��������!����� ��� ������ ���� ��� ��#�������� ���� ���������� �� ���� � ���������� ��� ������ �� �� �� �� ���� �� ��� � �������������������

!� 2�� � �� ���� ������� �� �� ���� ��� ��� ������ � �� ������� ������������ ���������������������������� ��������������������� ������ �� ��� � ����� �������������� �������� ���� ��� ������ �� ���� ��� �������#��������������� �������� ����������

������������������� ������� ������������$�

���� 2�� ��������� �� ������ �� ������ ��� ������ ��� �� ��� ��������� �������������� ������ ������"��� ��������� �� ��������������� ������������������ ��!� ������ ������ ������������ ������ ��������� ���� ������ �� ��� � ����� ��� ������ �� ��� ��������� ��#���� �� � ��������� ���� ������ �� ��� ����������� ������ ���� ����� ��� ������� � ��� �� ����������������%���������������� �������������� ��������������������

���� 2����� ���������������� �������������������� ��� �� ��������������������%������������������� ���� ����� ����������������� ��� ���� ������������� � ����������� ������� ����������

���� 2�� ��������� �� ���������������� �������� ��� � ���� ��� ��� ����� ��� �� ������� �� ��� �����(� ��� "��� ��������� ������� ��� �!����� �� ��� ������ ��������������������������� �������������!����� ������������������ ��������������� ����������� �����

&����������#��� ��� ������������ ������������������� ������������� ��������������=�������� ������� ����$�

� �0�����5�:�� ��������� ����������� ��� �������� �������� �� ����������������������������������������������� ������������ �������������������#�������������

� 4������5�1�� ����� ���� ������ ���� � ����������� ��#���� ������������ ��������� �������������

� $�����5�'�� ��������� ���!��������������� ������������������ ������������� �� �������������������!� ����������

������������ ������������ ���� ���������������� �������������#������ ��������� ��� ���� ��� �%������ ������ �����(��� ��� ����� ��������� ���� ����������� ������ ��� ���� �� ��� �������� ��� ���� ���� ���(� �� ��� �%����� �������� � ������������� ���������� ������� ��������������������#�(���$�

� '������ � �������5� '�� ���� ������� �� �� ����� ��#���� ���������� ��� ���������� ��� ��� ��� ��������� �� ������������ �� ��� ������� ������ ���� ������ ������������*��� 7������&3;����������+������������������������ ��� �� �������� ��� ��� �� ����� *���� � ��� ���� �������������������������+��&����� ���� ������������ ������������������

� '������&��� �����5�&������������������� ������ ���&3;��������������� �� �� ���� ��� ��� ���� �� ��#��� ������� ����� ��� &3;��� �� ��!�������� �������� ��������� ��� ���� ���� �� ��� �� ��������� ���������

Page 28: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R���# �������! �� ������� ��' ��� ��� ���+ � � ��������& ���+ � ����� ��� ����� � � � ���� � ���� ��

��������� ��� ������� �� �� �� &3;�� *�� ��� �� ���������� ��� ��� �� ����/������������� ������� ������ ����������A��������������+��

"�������� ����������������������������� ���������� �� ������������� ����� ��� �� �������� ���� ��� ��������������������� ����������������������������� �� ��� ��� ������� ��� ��� �������� ����������� "�� ������� ��� #��!�������������#��!�������� ��������������� ���� �8����������������������������� ����������� �� ������ ��� ���� ������� �� ��� ���� ��� ������� ��� ��� ��������� ������������

Submodelos de un MD

��������� � �� ������� ���� �� ������� �� ������$�

������ ���5� .�#�������� ���� ��� ������� �� ���� ���������� ��� ���������� ��������������������������������� �����=�����������������$�

� "�������� ������� �$� > ����� *���� � �+�� ����������� ������ � �����*��������������+�� ������ � �� �� ��������!����� �� ��� � ����� �� �� �������������� *���� ���+�� �������� ��������� �� #������ � ��� ��������� ���������������� � ���

����������������� ��������������� ���� �� ���� ���� ���� �� ������� ��� ������������������ ����������� ���������

� /����������$� "�� ��� ��� �� ������ ��� ���� ������� �� �� �� ��� #���������� ��� ��#������������������"%�������������������������������������� ��� ����� �� ���� �� ���� �� ����� ���� ������� ��� ��������(�� ������ ����������������� �������������� ������� ����������������������������� ��� �� ���� �� ���� ��� ��� ������������ ���������� �� ��� ��������� ������ ���� ��������������� ����������������������������������������� ��� ������ ������������������������� ��������� � ������������

+���� ���5����#������������������� �������� ����� �������������������������� �������� ������ ��������� ��� ������������� ��������������� �� ����� ��� �� ������������������ �������� ��������������������������������� ������������� ���������������������������������������������������� �������� ������ ������ #����� �� ��� ��� �� ����� 1� �� ��� �� �� ��� ��� �� ���� ��������������#�� ����� ������ � �������������������������� ��������� � ��

��� ����������� ������� ����� ���� ������ ����� ��������� ������� ���������� �������� ���������������� ����������� �������� ���� �� ����������������� �� ��� ���������� � ������ �������� ����� �� ������������ ��� ����������� �� ������������������������������� ������������������������������������������������2������������������� ������������$�

� ������(������5� '�� ���� ����� �� ���������� ������� ��� ������(��� ��������������� ������ ������

� 1������5�?����������(��� ��������������������#��������������(� ������� �������������������������������������������(�������

Las restricciones de Integridad en los MD

"�� ��� ��� �� ����� �%����� ��������� ���� ���� � ��� �������� ��� ����������%������������ �� ��)��������;��� �������������������������������������

Page 29: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R���# �������! �� ������� ��' ��� ��� ���+ � � ��������& ���+ � ����� ��� ����� � � � ����-� ���� ��

��� ��� ��� ��� ����� ���� ������ ������ �� �� �������� ��� ������� ������ ��������������������������������������� ����� ��� �� ������������������� ��������� ����������� �� ��� ������ � �� �� ��� ������ � ��!���� ���� ��� ��� �������� ������� ����� �� ������ ����� ��� ����������� ��� ������ ��� ��� ��� ����� �� ����� ��� ����������� �������� ��� ��������� �� ����������� #�� �� �� �����������

��� �������� �� ��� ���� �� �������� �� ��� ��� ���������� ��� ��������� �������������� ���� ������� ������ � �������������� �� ��� ���� �����!��� �� ��� ��������� �� ����� ����� ��� �������������� ���������� �� �� ��� ���������� �� � ����������� ��� �� ���������������� ������ ����������������������������(� ��������;��������������������������=������ ������������������������������������� ��������� � �� �� ��� &3;�� ��� ��� ���� ���� ������ �� ��� �� ���� ������� ������������������������������������������

Los modelos de datos en el diseño de bases de datos

/������ ���#�������� ��� ��� ��)�� �� ��� �� ����� ��������� ��� ���� ���� ��� �� ������������ ���� �� ��� ���������� ��� ��� �� ����� �� ����� �� ���� ����� �������������� ���������� �� ���� ������ ���&3;����� �����������������������#������������������������������ �����;������������ �� ��)�������������������������� ��� ������������������������� ����������������������������!����� ���&3;������ �� �������� ��� �� �� ����� ���� ��� ���� ����� ������� ��� ����� �� �� �������������������������������� ���� ���&3;���������������

-����������� � ������������� ������ ���������������������(�� ������� ��� �� �����!���������������������������������$�

�� ���������� �� ������� ������������������� ����������������������������

!� 1������� ��� ������� ����������� ��� ������ ����� ���� �� ���� ������� ���&3;��������#���������(������� ������������������� ��*��� ��������� ����������������������������+��

"� ���� ������� ������� �� ���� ��� �������� ������� �� �� ��� � ����#�� ����������� ��� �%���� ����������� �� ����� �� ��� ������� �� ��� ��� ���������!������

5� -��� ������� �� ����������� ��� ��� �� ���� �!���� ��� ��� ����������� ������

Page 30: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���(� � ���� ��

!� " �� � � �� �" � ��� � �#��� � � � �� � ������ ���� �� ���������� ������ ���&3;�������������������� � ����

������#��� ��� ������������������������������������������������������� ������ ������������ ��������������� ���������������������������������������������������� ����� ��� ��� ��)� ������ � �������������������������������������"����� ���� �� ���� �� ���� ��������� ��� �� ���� "��� � � B� .������������� ����� ����������� ��������������������

�����������

"��=� ���� "��� � � B� .������������� *="5/+�� ��������� ���� -����� -�� ����� ��� �������� �����!���������������������������� �������������#����������� �� ����� ����� ������ ��� ��� ��� ���������� ������� �� � ������� �� ��� ����� ������������������� ������ �������������� ���� ������ ������ ��������� ��������!�����-���������������������#����� ���������������� �� ������ ���� ������="5/�������� ������������������������������ ��������������

���������� ����� ��������="5/��� ���������� � ��C����������� ����� ��������������������#���� ������+��������������������������������������!���

����� �� ������ ��������������� �� ���� ���� �� ���� ������� ��������� ������� �������� � �$�

� ������ ���5� ����� ��� ��� ���������� ��� ��� ����� �� ������ #��!��� ��� ����������� � 2����(���� ��� ��������� �� ���������� �� ���� *���+� ����� ���� ������

� +���� ���5�-��������������� �������� ������������������ �������������� ��� ��� ������������ �� ��� ��������������-���� �%������ ������������������(�������������� ��������������� �� ����*�=�+��

"��="5/����������������������������������������� ��� ����������� �������� ������� �� ����������� ��� ������ ����������� �� ��������� �!� ����� ��� ������ ���������������� �� ��� ����� -�������������� ����� ������� ���������� ��� �� ������������� ����������� ����������������������� ���������������������(��� ������������������� ������������ �������������������

����� �� ���������������(���="5/������ ����������� �� ��)�� �� ��� �� ���� �� ��� ����� ������ �� ���� ��� &3;�� ��������� ��� ������ ������� ��������������� ��������� � ����������� ��#��������������

������ ���������������� ����������� ����

&����� ��� ����������������������� ���� �������� ���$��������������� �������� ����� *���� �� ���� ���+�� � ��� �� ��� �������� ���� ��� ������ ������ ������������������ ��#�������

Page 31: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���($ � ���� ��

Entidad

"��� � ���������������������������������������������������� �������� ��������� ��� ��� ������� ��� ��� ������ "� ������ � ����� ������� ��� ����� ������������������������������������ ��� �� �����

���������� ����� ��� ������� �� ��� ���������� ��������� �� � ���� ��� �������������� ������ �� ��� �����(���������������� ���������� ������ � ��1!���������� �� ���� � � 12'>/D� �� �������� �� ��� ���������� ���� ��� ���� �� �����������!����� �� ���������� ���������� ������������������������������������� ������������� ������ �������������������������

������������������������ ���������� ������ � ������������������������ ������������ ��� �������� ������ � ����������������� ��������������������

"%����� ������� ������ � �$�

� )�������5��������������� ���������� ������ � �����������������%������������������ �������%�����������������

� +�������5� ��� �%�������� �� �� �� ����������� �� ��� ����� �� ���� � � � ��� ���� �� �� ��� �%�������� �� ��� ����������� ��� ����� �� ���� � � �������� �������� �������� ���� ��� �� ������ �� �� �������� ���� ����������� ��� ����� ������ � ���������� ������������� ��������������� �� �������������� �� ������� � � � ��� ���� ������ �� ��� ������ 2�� ����� �� ���� � � � ��� ���������������� ��������������������������������� ��������� ����������-��� ��������� �� ��������� ��� �� ���� ���� ��� ����������� �� �� ������������������������%�������� �������������� �������������� ���������������� ��������%��������������� �������� ��������� ��� �� �����

Interrelación

��������� ��� �������������� ����� ��� ���������� �� �������� ������ ���������� � �����������9��������������� ����� ���������������������� ������������ �� ��������������� �%������� ������ �� �� �� ����� �� ���� � �� ������������ �������������� ������ ����������������� ��� #������������%������� ������ ����������������������� ���� ������ �� ��� ����� ������ � ����� �����#��������� ��� ���������������1!�� ��� ����� �� ���� � � 12'>/� �� ��������������� ���� ��� ����� �� ���� � � �.;/>��� ��������� ����� �� ��������������/:�8���������������� ������ ��������������������E� ����������������F���������������� ���E �������!��������"��

/������������������� ������������������ ������������ ���������� ������������ ��� ����������������������� ���� ��������������������� ������ � ������������

�������������������������������������������D�������������������� �������������������� ��)�� ����� ��� �� ���� ������ � ���������

"A"=-�1/�

12'>/�

Page 32: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���(�� ���� ��

"���� ����������� ���������������� �����������������������(���������� ������ � ����������

��

2������� ���������������������������(�����$�

� ;������5�-����������� ����������� ���������������������� �� ��������������*��������� ������ �+����� �������������������������������

� 4�����5� :������ �� ����� �� ���� � � ���� ����������� ��� ��� ����� �����������������-�� ����� ����� ��G�* ������+����� ������������ ������� ������ � 8� ����� ��4�*��������+����� ��������������������� ������ � 8�������������� ����� �����������������������#$� �������������� ����� ��G��

� 9������� ��������� ���5�:�������%���� ������������� ���������� ������ � �������� ��������#����������� ������������� ������������� ������ � ������ �����������������������"������� ���������� ��������D$D����� ����������������������������� �������������������%�������������������� �������� ������ � ������� ������������� �������8����D$:������������ ���������� �� ���� � � ��� �� �� ��� ��� ������� �� ����� �� *������ ���� ���+� �������������������:$=��������������������� ������� ������ � ��-����������������������������������������������������������� ���������� �� ������ ������������������������ �����������������

"����� ������� ������ � ���� ���%������� ���������� ����������������

� /��������5"��� ������ ����������� � �����������!����������������������� �� ���� � � �� �� ��������������� 1!�� ��� ����� �� ���� � � 12'>/� ������ ��������� ����%������%����������&��'�(%��������8� �� ��� ���� ���� ��� ����� ������ � ��.;/>�����������������)*�����+��%�������"������� �����������������#$�������12'>/����.;/>���������������� ����,����(��(&�����

"����������� ����� ���#������������� ��������������� �������� �������� ��� �� ��������"�� ������������������� ����������%��������������������� ���� ������ ���������������� � ������� �����-�������������� ���� ���������� �������%������������ �����#�������������)����� ��������� �������������������������������"������ ����%��������� ��12'>/������ ����� ��� ������� ������� �� ������ �� ��� �� #�����8� ��� �%�������� ��� ���� ����%���������#����� ��������%�������� �������� ������ � �12'>/����������������� ������� %����������� �%���� ���� !� ������ ������� ��� ������ ���� ������ ��12'>/��� ���������������������� ������ � ��

12'>/� �.;/>����/:��

:$=�

���� ��������@����

12'>/� �.;/>����/:�� ���� ��������@����

Page 33: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���((� ���� ��

"�� ������� �� ���������� ���� ��� �!������ �� �#���� ��� ����� ���������������������� ���������������������� ��� ������� ���������� ��� ��������������� ���� ��� ������� ���� ��� ����� �� ���� � � �� �� �������������� �� ����������������� ��������� �����-�����������������������������������������������������*����������������� �������� ��� ��� �������������� ������� ���+�������������� ���� ��� ��� ��� ��� ���� ���� ��� ��� ��������� ��� �!������ �� �#������������� �������� ��� ��������*���������� ����������� ��� ������� ��������� �� ����!��������������� ������������������"��������������������������������� ����� ��� ��������������������������� ����������������#���

"����� �� �� ��� ���� ���� �� ��� ����� �� ���� � � � ���� ������� ���� ��#��������� � �������������!#�������!������������ ������ �� �������������� ����� ����� ������ � � *���� ���� � �������� ���������������������B1.-5+�� -�� �������%���� �� �� ��� ���� ���� ���� ������� ���� ��� ������ *���� ���� � �������� ������ � ���� B1.�5+�� �� ��� ������ �� ������ ���� ����� ���������� �� ��� ����� ������������#��*���� ����� �������� ������������#��B1.15+��

��������������� ���������� ������ � ���������� ������������������� ������ �������������� �����-��������������������������������������������������� ��

�.;/>�

���:.�D$:�

&>�.>�

���

��� ���

���������

�� @�� ���

�!�����

� �����

,����@-�������

,����@��#��������

����@����� ��

�@����� ��

���

���

�.;/>�

�.;/>�

. ������ �����

� �����

Page 34: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���(*� ���� ��

���� � � "A"=-�1/� �.;/>� �� &>�.>� ���� ������� �� �� ���� ����� �!� ����� ������� ����&��'�(-�.�������&��'�(��������� ��������������������:.��

Restricciones

��������%�������������!��������������������������������� ����������� �������� ��������������������� ���������������� ������������������ ���� �� ����*���������������������+���� ��������������������������#������������� ���������������� ���� ���� �� �������� ������������ ��� ����� �� �������� ������ �� �������������!����� ��������������������*�������������������+��

"�� ="5/� �� ���� ���%� ��� ������� �� ��� �� ���� ����� ���� ��� ������������������ �������������� ��������� ���� ��������� � � ���1��� ���� . �������� ���-����������� ��� ������������������ ������� ����� �� ������������������������� ������ � �*�������� ���������������� ��������������� ������������������������������ ������ � ����������� ���������������+��

������� ����� ��������� ������

"�� ������� �� �������� �� ��� ��������������� �� ��� �������� �� ������������� ����� ����� ��� ��� ����� � ���!����� �� �%����� ��� ���� ������ ����%�������� �� ��� � �������������� �� �#���� ��������� �� � ��������� *����� �����������(���������������������+��

Cardinalidades de un tipo de entidad

��������� ��� ��� ����� � �� �%���� �� �!����� �� ��� ����� �� ���� � �������������� ��� ��� ����� �� �������������� ����� ��� ������� �%���� �� �!����� ������������� �� ��� ����� �� ���� � � ���� ��� ��� ����� �������������� �� ���� ��������������� ��� ������ �� ����� ����� �� ���� � � ���� ����������� ��� ��� ����� �����������������&�������������������������������������� ��������*H�D+��*D�D+��*H��+���*D��+��������������� �������������������������������������������� ����������� ������ � ����������� ����������������������������������

1!�� ���� ��������� �� �� ������� ��� ��� ����� � �� �� ��� ��������� �������� ������������ *D��+� ��� �.;/>� ��������� ���� ���� ����������� �� 12'>/� ��� �� �����#������ ������D��G�������������������� ���.;/>������������ ����������������/:�8��������������� *H��+� ��� 12'>/� ��������� ���� ���� ����������� �� �.;/>� ��� �� �����#������ ������H��D��G�������������������� ��12'>/���� ������������������� ��������!��������*D+��� �����������%������������ ���*�+��������� ������ �����������������������������*H+�*�����������+�������������*�+��

��� ��� ����� � �� �� �� �� ����� ������ � ��� ����������� ��������� ����� ������ � ������������������� ���� ��������������������#������!��������%���� �������� ����� � ��&��� ��#�������������� ���������� ������������ ������������ ����� � ��%���� ���������� ������ � ����������������������������������

12'>/� �.;/>����/:��

:$=�

*H��+� *D��+�

������@���� ���� ��

Page 35: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���(0� ���� ��

Dependencia en existencia y en identificación

��� ����� �� �������������� �� ����������� ����� ��� ����� �� ���� � �� ����#������������������������������������ ������ � �������������������������������� ����� �� ���� � � � ��� ���� ��� ����� �� ���� � � ��������� 2�� ����� �� �������������� � ����%��������������������� ����� � �� �������� ������ � �������������*D�D+��

������� ���������� ���������������� � ����� ���� ��������$�

� +��������������0���� ���5�&�� ���������������� � ��� � ������%������������ ��������������������������#������ ���������� ������ � ����������������� � ���� �� ���������� ��� ����������� ��� ����� �� ���� � � ���� ������*����� �� ���� � � � ��+� ��� ��� ��� �%����� ��� ��� ����������� �� ��� ���� � ��������� �� ������� ���� ����&�� ������������������������ �� ��� ����� ������ � ������������ ���������������� ��������� � � � ������� ���� �������%�������� ���������� ��������������������1!������������������ ��#������ ��� ����� �� �������������� &�:&� ���� ������ ��� ����� �� ���� � � ����������.":'"� ���� ��� ����� �� ���� � � � ��� �2":'1� �� ���� ���� ������ ����%��������� ��� ���� ��� ���� ������� �� ��� ������� �� ��� �������� ������� ��� ���� �� �� ���� ���������� ��� ��� ��� �� ����� &�� �� �����)� ��� ��������������E"F������� ��������������������������������� � ������� � ��� � ������%���������

� +��������� ���� ������ � ���5� ���� ���� ���� ������ ��� � ����������������� ���� ��� �� ��� ���� ����������%��������� �������������� ��� ����� �� ���� � � � ��� ��� �� ��� ��� � ���������� ���� �� ������ �� ����������� ����� ���� ���� �� ������ ���� �)� ��� ��� ���#�� �� ��� ����������� �� ������� � � �������� �� �������� ���� ����1!������������������ ��#�������������� �����������������:��������������������� ������ � ����������.;/>������������� �� ���� � � "A"=-�1/�� �� ���� ������ ��� � �������������� ��� ���� ������������ �������� ��� � ��� �� ���� ��� ��� �%�������� �� ��� ��������� �������� �������� ������������#�� ����� ���*��($��+� �������� ���� ����������������� ��� �� ���� ������� *%��(��������+�� &�� �� �����������������)� ��� ��������������E.�F������� ����������������������������������

"��1.-� ��"A"=-�1/����� @�� ���I�:��@"���������

�.;/>� �����:��

D$:�

"A"=-�1/�

:��@"��������

�� @�� ���

*D�D+� *D��+�.��

����������������

��.":'"� �2":'1������&�:&�

D$:�

*D�D+� *D��+�"0�

���������� ������

Page 36: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���(�� ���� ��

����� �� ������������ �

"��="5/��������� ����������� ��� ���������� ���������� �%������� ������ �������� �� ���� � � �� ��� ��� ����� ��� ��� �� ������ ����� �� ��� ������� ��� ����������� ����������� ��� ��������(������ �� ���� � ��������� ���� � ��������� ��������������������������������������������� ������ � �"&@2:�� ����� ������������ ������ � ���������� ���������#��� ��� ����������������"�������� ����������������������� �� ���� � � �������� ��� ���� �������� �� ����� �� ���� � � *�� ��������+� �� ��� ����� ������ � �*������������������ ����� ��� ����+��

2�� � ����� �� ���� � � �� ��� ����� �� ���� � � ���� ��������� ��� ����� ���������������������������������������� ������ � �������$�

� /��������� �� ��� ��������� �� ���� � �� ����� ������ � �� ������������������������������� ��� ��������� ����� ������ � ����� ������������������������ �����������������

� ��� ������ � �� �� ��� ��������������� �� ��� � ����� ��� ���� � �� �������� �� ���� � � ������� ������������������ ����� �� �������������� �������������� '������� �� ���� � ��������� ��������� �� ��� ="5/� �������������� ����������������� �������� �������������������� ���������� ����������� � ���� ��������������� �� ��� ��������� �� ���� � ��� ���� ���������� ����������������� ���� ��� �� ����� �� �� �������� ��������� ���� ��������%���������������������������*������������(�����+��

� ;���� ��� ������ � �� �9�� ���� ��� ��������������� �� ��� � ����� ��� �� �� � ������ ������������������������ ��������������#�������������������������� ���������� �5����� ������ �� �� ���� � ����� �� �������� ����� ������ � �� -����� ���� ��� � ����� ��� ����� �� ���� � � �� ��� ��#��� ��� ��������� ������� ���� � ��� �� ��� ���������� ��� �� ��J� � � �������� �� �������� ������ � ��%��������������������������� ������ �������� ���� ������� � ��� ������ ��� ��������� �� ������ � ������ �������� ���� ��������������

� -������ ��� ����� ������ � ���� �������� ����� ����������������� � ������������������������� �������� ������ � ������������������������������ �� �������������� ����������� "��� ��������!����� �������� ��� �%�������� ���������������� ���������������� ���������� ����� ������������������� � ���� �������� ��� ������������ ��� ������ �� �� ��� ��������� ��� ��� �����������������������������

� 2������� ������ � ���� ��������� ������������ ����� ����� ������ � ����� ��� ���� ��� �� ��������� ��������� ���������� ����������� "�����������!������ ������� �� '������� �/������� �������� ���� ��� ����� ������ � � ���� �� ������ � �� �� ��������������� �� �� �� ����� ����� ������ � �� ��� ��������� ��������� ��� �� ��� ������� ��� ��������� ������������������ ��������� � ���9��������������������������� ��� ��������� � �������������� ����������� ���������� ���������������

2������� ������������������������������������������������(������ ���������� ������ � ���������������� ������������ ������ � ��"�����������(��������� ����� � � ���$�

�� 2��� ���������� ��� ������� ��� ������� �� ������ � �� ���� ������� ���� ����� ������ � ���������������� ���������� ��������������������������� ����� �� �������������� ���������� ��� ����� �� ��� ��� �� �������������� �� ��� ��������� ��������� �� ������ � ��� �� ���� ������ ���

Page 37: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���(8� ���� ��

��������� �� � ����� ��� �� �%����� ��� � ��������� �� ������ � ����������

!� ����������#������������� ������� � ����������������� � ������%������������������� ��� �������������������������������� �� �������������������������

"� 1����������������� ����� �������

�����������(������ ���������� ������ � ���������������� ��� �������� ����� �%����#�� �� ������#��� 2��� ��������(������ �0 �������� ������� ���������0�������������������������������������� ������������������� �������� ������ � ����������� ������� ������������������������� ��������������������������� ������ ����� ������ � ���������(� ���

2��� ��������(������ � �������� ������� �� �������0����� �������������� ���������� ��� ������ ������ ���� ��������� ��� ����� �� ���� � �������������� ������������� ����������� ������������� ������ ������

-��� ����� �� ��� ��� ��������(������ �� ��� ����� �� ���� � � ��� ��� ��������� ��� �������� ����������������������2�����������(������������������������������� ������ ������� � ��������� �������� ����������� ������������������������ ����� �� ������� �� ��� � ����� ��������(� ��� ��� �%����� �� ���� � �� ���� ����������(���� �� �������� #����� �� �� �� ���� � ����� �� ���� � �� ��� �%����� ������ � ����������������(��������������#��������� ������� ����� ������ � ��

2��� ��������(������ ��� ���� ���������� ��� ������ �� ���� ��� ��� �%��������� � �������������(������������ ������ � ���������������� ������ �������������������������� ������ � ������������(� ���2�����������(�������������� ���� ����� ������������� ����������� ��� ��� ����� ���� �� ����������� � � �� �� ���������������� ����������� ���������9�� �� ���� �������������� �� ��� �������������� ���������

-��� ������� �� ��� ��� ��������� ������� ����� �� ��������������� ����������������� ��������������� ���� ���������="5/$��������������������������������������������������������������������������������������������������������������1�;������� �������������

���� ������ ��� ����� �� ���� � � -������� *,������ 1+� ��� ����� ��� �� �����������(� �� ��� �� � ����� �� ���� � �1����� �������� �� ������ ������ �� ���������������� 2��� ���� � � -������ �� �� ����������� ��� � ����� 1����� �� ���� ������������������������8��� ����������%������������� � �-����������������������� ������ ��� �������� ��� ���������%����#���������������������� � ������������������������������ ������� ������1 ������ ������ � � ��������� ������� �����#�� �����������(� ���������������� ��������������� ������ ���� ����� �� ����� ���� � ����� �� ���� � �� ��� ����� �� ���� � � -������� �� ������� ������2����� ����� ������ ��� �������� �� �������� ��� �� ������� � ��-������ ���������� ������� ������

"������������;��������������������� ����������(���������������%����#���"������ ���� �� ��� ���� ��� �� ��� ����� �� ���� � � ����������� ���� ��� �� �����������(� �� ��� �� � �����3*���� �� ����������� "��� �������� ���������� ��������� ��������������� ����������� ����������������� ������ � ���������������� ������ ������������ ���� �� ������� �� ��� � ����� ���� ��� �� 3*���� ����������������������� ����%���������� � ���������������������������� ������ �������� �� ��� �������� �� ���� � ����� � � ��� ��� ��������� ��� �������������� ���#����� ������� ������������(� ������� �������� ����

Page 38: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���( � ���� ��

-���������� �������������� �������������������������������������������������������������������������������� ������ � �������������������� ����� ��� �����-/����� �� -������� &�� ��� ���������� �� ��� ������ �� ���� �� ��� �%����� ��� ��� ������� ������ ��������� � ��������� ���������� ��� �������� ��������-/����������-��������� ���� ���� �������������������������� ������������ ����������� ����%����� ���� � ������������ ��������������(� ������������ ������ ��� ������

"�� ��� ����� ��������� �� ��� ��� ������� �� �� ���������� "�� ���� ���� �� ������������ ������������ ������ � �-������������� ����������� ����� ��� �����)��������� �� ���������� �� ������ �������� ���� ������������� "��� ������������������ ���� ���� ���� � � -������ ��� �� ��� ��� �����)��������� �9�� ��� ��������������� �� ���� � ��� ��� ��� �%����� ���� � �� -������� ���� ��� ��� ������������������������� ������ ��� ������

Las cardinalidades en la jerarquía

����� ��� �� ��� ����� �� �������������� �������������� �� ����������� �� �����������%���������� ������� ������ �������������� ������ � ����������#��������������������������������� ���������������������������� �������� �� ��������������

-"/&>:1�

"&@2:�

�>=;/"� =2A"/�

H�D� H�D�

D�D�

�%��

1/2� ":,"/="�1��

"&@2:�

<K/.�1� ;1�'"/.1:1�

H�D� H�D�

D�D�

�����

132�

"=-/"&1�

"&@2:�

-L;�.�1� -/.<1�1�

H�D� H�D�

D�D�

�����

1&2� -"/&>:1�

"&@2:�

'/1;1A1�>/� "&'2�.1:'"�

H�D� H�D�

D�D�

�����

1+2�

� ������������ ������� �� ����!�����

Page 39: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���(-� ���� ��

1!�� �� ������� ���� ������ ��� ������� ��� ��������� ���� ��������� ��� ����������������� ����������� ����������������$�

� "�� ����� �� ���� � � �� �������� �� ��� ��������� �� ���� � � ���� ����������(� �� ���������� ������� ���� ��� ��� ����� � � �!����� D� �� ���� ������ ����� � � �%���� D�� ������ ���� �� ��� ���������� �� ����� �������� � � �������������� ����������(������������� ������

� -���� ���������� ����� �� ���� ����� �� ��������������� ����������� ������ ����� � ��%���� ���� ��� ���� ����������� ��� � ����� �� ���� � � ��� �������� �� �������������� �� D�� ������ ���� �� ��� ���������� �� ����� �� ������ � � ������������������������(��������������������� �����������

� &���������� �� ������������������������������������������������ ���� ������������������������������ ����� � ��!�����H�������������������� � � �������������� �������������������������������� ������ ������

� &���������� �� ����������������������������������������������������� �������� ��������������������� ����� � ��!�����H���D�������������������� � � ��� ��������� ��� �� �� �� #�(� ��� ��������(� �� ��� ����������� �� ���� ��������������������

������� ������������� ��

"�� ��� ��� ����� ��� ��� �� ������ ��� ����� �� ���� � � ��� �� ������������������� ���� ��� ��������� �� ����� ����� �� ���� � �� ����� ��� ������� ������������������� ���� ����������� ��������������������������������������������� ���� �� ��������� ���� ����� �� ���� � � ���*����� -�������� &���������� �� ������ ����� �� ������!������������� ������ ������#�� ���������� ����� ��������������������!�������������� ������������� ������������#�� ������������ �����������!������ �� ������ ���� �� ��� �� �������� ��� �� ������������� ��� ������������������������� ��������!�����������������#�� ����

-������ ���������%����#� � ������� ������� ������������������������������������������ ������ � �������� �������������������������������������� ��� ���������������������������������� �������� ������ � ������������� �� ���������������%����#���

1/'K�2�>�

��/:*�

D$:�

-/><""�>/���������� *H�D+�

��/: �

D$:�

-/><""�>/�*H�D+�

���������

*D��+�

*D��+�

��@��#� ��

��@��#� ��

Page 40: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��(�R����+ � ������� � �9����������! �� � � � � ���*� � ���� ��

��������� �������� �������������������������

"��="5/����������������������������������������������������������� ������������������������ ������������������� ������ ����� ������ ��������&������ ������ ���� ���� ���������� �� ���� ��� ������ ���� ��� �������� ����� ��������������� ��������� ��� ��������������������������� ������� ������ ������������������������ ��������������$�

� "�����#������������� �������� � �������������� �����&�� ����������� ������� ����� �� ��� ��� �������� �� �������� ��� ��� ������� ��� ��� �������� ������������������ ��������������������������������� ��������-������������������� ��������� ����� �������� ������� �� ����������������� �� �� !�������������������������� � ������ �����������������#������������� � �������������#����MDC�N6O��

� "�� ��� #������ �� ��� �������� ������ ������ ��������� �� � ����� ��������� ���� ����������� ��� ����� �� �������������� ������ ��� ����� ������ � ��"� ���������#����� �������� ����� � ���%�������!������

� "�� ��� �%�������� �� ���� � �� �������������� �� ��� �������� �� ����� ������ � ��������������� ������%������������������������������*+�����*+� �� ���� � � *��� ���� � �� � ���� �� ��� ���� ����������� ��� ��� ����� ��������������������������+��

����������������� ������������������%���������������� ����� ������ ���������� ���������������� ��������������� ������ ����������������������� ����������������%����� ����������������������������(���������������������������������������������� ���� ������ ��������%�����������������������������*����� �������������� ������� ��� ��� ������ -���� �� ���� �� ���� ��� ������� ������������� �� ������ ������#�� ��� �������� �� ��� ��� ����� ��� ��� �� ������ ������������� ��������������������������������"�����="5/������ �������������������������������� �����������������������)��� ��������������!��� ���������������� �!������� �����#���� ��#������������� �� ������������� ������������ ���������������������������������%����� ������ ����� ������ ��������

����� ���������������� ����������� ����

������ ��� �� ���!����� �� �� ������� �� ��� ="5/�� ��� �� ������ �� ��� ������ ������� ��� ����� *�������� ������� �������� ����%�� ����� ��� �����������������+8� ������������������%���)������������������������������� ���������������� �� ��� ��)�� ���� �� ��� ���������������� &��� �� ������ ��� #����� ��� �������������� �� ���� ��������� ��������� �� �� ��� ��� ="5/�� "��� ������������������� � ��� �� ������� ��� ������ ������� ��� �� ���� *���� � �����������������������+������������������������ ��� �� ���������������������������������������������������������������� ������������

"��������� ��������� ��������1;�"�*������;�� ���������+��&�>&�1:.�*DPCH+� �� ��� ��"1/� *����������� ��������� ���� "��� ���1� � /����������+�� ->>:":�*DPQC+�

Page 41: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���*$ � ���� ��

$� " �� � � �� �� � � �� � ���� �� �� ������� �� ��� �)�� NH�� �������� ��� ����!�� ���������� �� ���

���������� ��� ��� ������ �� ��� ��� �� ��������� �������� ��� �� ��� ����������������������� ���������� ������ �������������������������� �����#���������"�� ��������� �� �� � �������� ��� �� ���� �� ���� �� �� ��� ��� ����!�� �� �������������� �� �� ��� ���� �� ����������� ������������ ��� ������ �� ����������*�� ��+����� ������ ����#����� �������� ����� ������������������ ���� ������ ������������������������������������ �� ����������������������������������!����� �� ����� �!����� ��� � ����#������������!�� ��� ��� ���� �� �� ������ ��� ���������$�

� $������ ���%�� ��5�"���� ������������������������ ������� � ���������������������������� �������������� ������� ������������������ �������� ���� ��� ���� �� �� ������� �� ��������� ���� ��� ��� ��� �������������������!�����

� $������ ������� ��5� 1)� ���� ��������� ���� ������� ���������� ��������� ����� ��� �� ������� � �����������������������������9��������������������� ��� ����� ������������������ ����������*#���+��

� ��0���������5�"��������� �� ���� ��������������� ������������ ���� �������������� ���� ��������������� ������������������

� 8���������5�������������� ������� �� ��� ��������������������������������*�� ��+�� ������� ��������� ����������������������������� �� ��� ��� �� �������������� �������������

� .� ����#�5� ��� ��������!����� ����������� �!� ����� ���� ��������� ��������� ��������� ��� ����� ����� ������ �� ���� ��� �� ���� �� ����������������������� ��������� ����� �������(������������� �����������������

-����������������� ����#������ ����� ������ ���������������� ������ ���*�� ��+���������������� ���� ����� �����'� ����� ���� ������ ��� �� ����������������� ��� ������ �� ���������� ����� ������� �� #��!�� ��� ��� �������� 2������������� ��� ����������!�� ������������ �� ��� ��������� �� ����� *������+� ���� ���� �������� ����������!������

���� �������� �� ��� ������� ��� �� ����� �� �������� ��� ��������� ������� ���� ���� �� �������� �� ��� ����������� 1������ �� ���� ����� ���� ��������� �� ��� ����!�� �� ���������� �������������#� ����������� ����������� ��������������������� ����� ��� ���������� �������� ���� ����� ������� ����� ��� ������!���������� 1-/1� ��� �� ���� ������������ '� �� ����� ���������� ��� ������������ ������

�������%�����������#� ���� ����������������� �������������� ������������ ��� �� ���� �� � � �� �� �������� ��� ����� �������� ���� ������ ���������� ���� ���� ��������� ������!�� ��� ��� �������(������ �� ��� ��� �� ���� �������������� ���� ���������� �� �������� ��� ��� �������������� �� ��������������������� �������������������� ��)�� �� ��� �� �����������������

Page 42: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���*�� ���� ��

��������� ��������������� ��� ��

�����������)��� ����������������� ��� ����������������������� ���� ����� ����������������������� ������������������������ ���

;���������������

1��� ����D� 1��� ����G� ���� 1��� ������ �

000� 000� ���� 000� ������D�

000� 000� ���� 000� ������G�

���� ���� ���� ���� ����

000� 000� ���� 000� ��������

"�� ����� �� ���� ��������� �� ������� ��� ��������� �� ��������� ������� �� ����������� ���� ����������� ��� ������ � �� �� ��� �� ��� �� ������� ���� ���� ���������(� �� ���� �� ��� ���� �� ��� ��������� �� ����� ����� ������������������������ ��� #���������� ����� �� ������ �� ������� ��������� �� ����������� �� ��� ���������� -��� ��������� �� ������������� �� ���������� ��� ���������12'>/�� �� �� �������� ��� ���������� ��� �� ���� ������������ "�� ����� �� ����� ��#��� ���� ��� ��� ��� �� ��� ��������� �� 12'>/�� ��� ���� ���� *:�� ����:�������� � � �� .���������+8� ��� ������� * �� �� �� ��� ���� ���� ������ ��#�����8� #����� ���� ���� ��� ��� ������ #������ ��� ����� ������+8� ��� ������*�� ������ �����������������������#��������������������� ���������������� � ������ ����������� �� ��� �������� �� �����+8� ��� ��� �� *������� �� ���� ���+8� �� ������ ����� � �*������� �������+��

/89�)�

%����� %������ ����� &�����������

��������A�� :�������������� /����������.��������

�� ����,�� :�������������� /����������.��������

������&�� .�������� -����������� ��=����

&�������,�� "��)���� 2�-����

/���������9�8�*��������&�����������5���/�.�

�4�����"� �

"�������� �������� �� ��������������� ���������� ������������������� ������� ��8� �� ������������ ����������� �������� ��������������������������������� ������������������ ������������#��!������������������

"����������������� �� ����������������������� ������� ������������ ������������ ���������������������������������������� ����������������� ��� ��������

%%%%%%%%%%���

G6�

;�������

"��)����,�������.��������

:��������������

;� �����������

2�-�=�2�-����

-����������� ��=����

$����� �����

+�'$;$�.�

Page 43: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���*(� ���� ��

*��� ���������� ������ �� ��� ����!�� ����������+� ����� ��������� ��� ���������� ��� ����������������� ������������������������������������������������������4��� �������� ����������!�� �� ������#����� �� ��� ��� ����� ��� �� �� �� ����� ����������� ���������(�����������������!����������

1�������������������������������������!�������������������������������� ��������� �������������������

'� ������ #�� �� (������

'����� ,���� /�������

1��� ���� �������� ������

3�� �� :R��������� :R�������

��� ����� � � :R�,���� :R�/�������

Dominio y Atributo

2�� ����������������������� ������� ��#��������������������������<D��<G�������<�����������(� ������������ ��8� ������#���������������������������� �� ��������������������� ������������� �� �#�� ������ ������������ ����������������� ���������� ��������������� ��!�������������������������� ���

'� �� ���������� �������������� ��������������������� ���������������������������� �� ���$��!���������� �� ���� ��� ������� ����������������������� ������������ �� ������� � ��(��'�� ���� �� ��� ��� �� ������� ���� ��� � � ���� � ���������������S��������������������������������

��� ���������� ��� ��������������� ����������0�������-��������������� ������� �� ��� � � �� �� ��� ������� ����#�� �� ��� �� ������� ���� ���������������������� ��������� � ��������� � ��������DC���N6����������������� ���������� ��� �������������������� � ������������������!�������� ������������������������ ��������!�� �� �� ��� �������� �� DH� ������ ���� ���� �� ��� ������������ ������ ��� #�� �� �� ��������� � 8� ���� ������ ��!�� ������� ��� ������� ���� ������� �����%������� ���� ��� ��� ��� �� ��� ������� ��������� � �� ���� � ��������� ���������� ��� �� �����

"�����#���� ��� ������ ������ ��� �� ���� ������������ ��������� ������2�������������� ���� ��� ��������� ��������� ���#��!�� ������ ���� �1D�� 1G�� ����� 1������������ �� ��� ���������8� �� ������ ���� ����� �� #������ �� ��������� �������* ������� � �������+� �� #����� ���� ���� ��� ��� ������ ��� ����� �������� ���������

"���������� �������������� ���������� ��������� �������� ���������"����� ���� �� ���� ���� #����� ��� ���� ���� �� ���� ����� �� ��� ����� �� � ��� �������� �������� �� ������ ����� ��� ��� �������� ������� ���� �� ��� ��� ��� �������� ������ ������������������� ����

2�� ������� ��������� �� ��� �� ������� ����� ���� ��� �������� �� ��������������������������� ������������������������������ ��������� � ��-������������������������� ������������� ��� ��������� ��������*����������5����� ������� ��������� ���� ����� ������� ��&��'��� ��������� �!������������ ���� ���� �� ������������ �� ������� � � �� ���� �� ���� ��� ������������ #������ ���#�� �����������������

Page 44: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���**� ���� ��

1�� ������ ���� �� ��� ��� ������� ������� ���������� �%����� ��� �������� ���� ��������8� �!�� ��� ���� ���� &��'�� �����!�� �� #������ ��� ���������������� ����������� ����

1�� ������ ���� �� ��� ��� ������� ������� ���������� �%����� ��� �������� ���� ��������8� �!�� ��� ���� ���� &��'�� �����!�� �� #������ ��� ���������������� �� ������ ��� ���� '����� ��� ���� ���� ��������� ����� ��� ������������������� ����������� ������!���������������������������E���(�������F� ����������������� �����������#���������������

Definición formal de relación

"������������ ������������� �����������������������������$�

� ;������5����������������� �������������������� ����

� &��� ����������� ���5���������� ������������� ���5 �������� ��������T*1�$��+U

��� �� ������������ �8����������� �������������������������� ��������������������� ������������� ����"�����������1� ������ ����� ������������ �������������������������� ���0��� �����������

� &���������������� ���5���������� ����������T�D���G���������U�� �� ���� ���������������������� ������������� ���5#�����T*1�$<��+U����� ��<������#������� ��� ������� ��� ����� �� ��� ���� ���� 1�8� ��� ������� �� ������ �� �� ������ ����� � ��1!����������� ������ ������������������#������������������#��!����������������� ����������������������������� ����� � ��

� ��������������������� ������������� ������������ ���/�����%������������ ������� ����� ��$�/*�T1�$��U��+��"�� ������� �� ��������� ������������� ������ ����������� �� ������� �� �� �������� ��� ���� ��������� &���������� ����������������������� ���������������������="5/��

� �������������� ����<��������� �������������������������������������������� ���������������������������� �� ��� ������������� ������������������������ ������������������� �������� � ���������������������� ������������� ���������������

-����������������� �����������������������#������������������������� ���������������������� �� ���������������

������������������ ���1$�� ��2=�

12'>/*:�� ��$� %������ :�������� � $� %������������ .���������$�+���������+�

)��� ���1�0�����(����������� ���� ��2=�

12'>/�

%����� %������ ����� &�����������

��������A�� :�������������� /����������.��������

�� ����,�� :�������������� /����������.��������

������&�� .�������� -����������� ��=����

&�������,�� "��)���� 2�-����

Page 45: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���*0� ���� ��

2��� ��� �� ��������������������� ��� �� ��������� � ����������������������������������� ����������������#��!�����������������

Clases de relación

��#� ������ ��� ���������� ��� ������ �� �� ��� ��� ���� ��� ���������������� �������#�(����� �����$�

� *�����������5�1������������ ����������*������� ����������+�������������� ��� ��� �� ����� ���� �������������� ������������������%��!����� ������������������������������������ �#� �����$�

o /��������� ���5� "%����� ���� �� ������ ��� ��� �������� �� ���������������� �� �� ������ ���������� �� �%��!���������� �� ������� ����������� *��� ��� �� ��������� �� ����$� ���� ���5 ������+�� &���%�������� *����������� �� ��� ��������+�� ��� ������ ���� �� �������������� ������������������������� ���

o <����5� &��� ���������� ���#� �� ���� �� ������� �� �� ��� ��� ��� �������%������� �����������&���� �!�� ����������������������#������������������� �� ���������������� ������������ �������������������������� ��������� �� �� ���������� ��� �������� �� ����� ���������� ������� ���� ��� ������ ��� ��� ��� ���������� ���� ����� #���� �������������

o .���������5&������������� ���#� ����� �������������#������� �������� ������������������ ����������������������� ��������������� ������������������� ������������������������ �� ������������������������������� �� �� �� ���� ��� ���� ��������� ���� ��� ���������� ��� ���������(��� ���� �� ��� ���� ��� ���� �� ��� ���������� � ��� ��� �������� ����� ���������� E��������F� *�� ������ �� �����#����� ���+���� �� ������� �������� �� ����� �� ���� ��� �� ��� �� ���� ��� ������� ��� ����������� ��������������&�������� ����������� �� �������������� ��� ����� �������(� �� ���� ��� �������� ���� ����������� E������� �F� ���� ����������

� 9����������5� 1� ���������� �� ��� ���������� ����������� ���� ������������������ ��������� �� ��� ��� �� ���� ��� ��� ������� �������� �������� � � ������������� �� ���� ������!����� ���������8������������������������������������������������������

��� ���������� ��� ��� ��� ��� ��� ������ �� �� ��� �������� ���� ��� �����������(��������������������������������������������(� ������������������� ������ ������ ������ �� ������� �������� ������8���� ������������� ��� ������������������� �����������������������

Claves

2��� ����� �������� �� ���� ��������� �� ��� ��������� �� ���� ���� ����� ������������!#�������!������������ �������� ���������������-������������� ���������� ���������������������������������������#����� � ���������������������������������� ��������� ��� �%����� �� ������ ������� ��� ���� ������� ��� ��������� �� �� �� ������� ���� ������� ������ ���� � ���������� ��!#��������� �� �� �� ������� 2��� ������������ ���������� ���������#����� � ���������������������� � �� ��������$�

� ������ �������5� "� �������� ���#�� ��� � �������� ��� ������� �������� �������� �������������������� ���������������������� ������������������� ���������������

Page 46: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���*�� ���� ��

� ������� ������������5� &��� �������� ���#�� ��� � ���� ���� ��� ���� � ������� ����������#������������

&�� �������� ������0����� ���������������/G������������������#��!�� ������ ���� ����� #������ ���� �� ������ ��� ���� ��� #������ �� ��� ���#�� ��� � ���� ���������������/D��������#���%������������������� ���������#��������������� ������� ����� ��� ����������� ��������

������������ �����#����������������#���%��������������������������������� ��� �� ��� ������� � � ��� �� ���� ������������ �� #��#������ �� �����(����� ��� ��������������!�������

������������

"������� ��������������������������������������� ������%�������������������� ������ ���������� �� ����������� ��� ������� ��� ��� �� ������� ��������� ������������������ ���������� �� ������������ �������� * �� ������+�� ��� ������������ �������� ��� �� �������� ��� ������������������������������������� �� ���� �� ���� �� �������� ��� ������������ �� ������� �� ���� �� ���������� ���������������#�� �� �����������

Restricciones inherentes

����� ���� �� �������������������������������������������� ������������� ��� � ����� ������� ���������8� ��� ��� ������������ ����������� ���� ��� ��� ����� �� ���� ��� �������� ���� � ���� �� ���� ��� ����� �� ����� ��� ���� ���������%� ��� � ����������� ������������������� ��������"�����$�

� :�� ���� �� ������ �������� ���� ������� �� � ���� ��� � ��������� � � �� ������#������������

� "���� ��� ��������������������������#���

� "���� ��� ��������� �������������������#���

� �� �� ���� ���� ���� ��� �� ������ ��������� #����� ��� ������� � ��� ���������� ����� ������� ������ ������������������������������#����

Restricciones semánticas

������� ��� �����%��� ������������ ����� ��� ����� �� ���� �� ����� �%��������������������������� ����������������� ������ � ����������� ���������������� ������� �� ���� ������ ���� ��� ��� ��������� ��� ��� �������� ����� ������������� ��������������� ������ ��������

&����� ������������������������������ ����� ���� ��������������� �������������������������������������� �����������������#���������������������������� ������������� ������#���� ��� ��������������������� �� ���� ������-��������� ������� ��� ����� �)� ��� ������� ������ � �� ���� ��������� ������������ �� ������ ��������������������������� �������������������������� ����������������

���������������������������������� ����� �����������������$�

� &��������������5�-������� ��������������� ������������������ ������ ������������#����������� �������������������� ���������#������������� ����������������� ������������*������� � � �� ������#�+������ ��������� � � ��

Page 47: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���*8� ���� ��

��� ���#�� ��������� �� ���� ����������� ���������� ��� �� ���� ����������8� ����� ��������� ����������� ��������� ������������#����������� ����������������� ���� ����������� ������������ ����� ���� ��� ����� � � ��� ������� �����������������#������ ������������ ������ �������������������������#��������������������������������������������������������#�������������

� 8� �����5�=� ������ ��� ����� �� �� �������� ��� #������ ����� ��������� ������ ����*�������+������� �����������������������������"������������������������� ���������� �����#�����������#���

� ���������������5� ��� ���� �� �� ���� ����� ���� ��� ���� �� �� ���� ���� ������������ ������ �������� �����#������������

� $��������� ����� ����5� &�� ���� ��������� /G� *��������� ���� ����������+������� ��� ���� �������� �� ���� ���#�� ��� � ���� �� ��� ��������� /D� *������������������� �+���� ��#����� �� ��������� ���� � �������� ����������#����� ��������#����� � �������������� �� ��/D��� �������������"������ ����������#���%������ ��������������/G��������#���%��������� �������� ������������������ ��������#����������� ��/G��

��� ������� � ������������������� ����������������������������������#������������� ���� ��� ��� �� ������ ��� �� ��� ������� ������ ��� ������ ��� ���� ��� ����������������������������� ���� �������������������� � � �������������������� ���������������������� ��������������� �������������� ����������������������

1 ��� �� ������� ������#����������������� ���������� ������������������� ��� ��� ������ ������� ����������� * ���� �� �� �� ���������+� �����(� �� � ��������� ������������������������ ����� ��� ��� ��������������������$�

� ����� ��������������5�"�� ���� �� �������� ���������������������������������#������������ ��*�� ����� ���������� �� ��������#�+�������������������� �%����� ������ ���� ���� #����� ��� ��� ��������� ���� ��������� ��� ���#���%�������"���������������#�� ������ ��������

� ����� ��� �� ���������� �� �� ����5� "�� ���� �� �� ������ �� �������������������������������#����� � �������������� ��*������� ���������� �� ����� ���#�+� ���#�� ������� ��� ���� �� *�� �� ���������+� ��� ���� �� �� ��������� ���������������������������������#���%�������

� ����� ��� ����������������5�"�� ���� �� �������� �� �������������������������������#����� � �������������� ��*������� ���������� �� ��������#�+����#�������������������������#������ ��������#���%������ �������������������������������

� ����� ��� ������������������������ ���5�"�� ���� �� �������� ���������������������������������#����� � �������������� ��*������� ���������� �� ��������#�+����#������������������#��������� ���������������#���%������ ����� ��������� ���� ������������ #����� ���� ������� ���� �� �!�� � �� ����� �� �������������� ����������� �������

����������� �� ���� ������ ������������� ������ ��������

1 ��� ������������������������ ���� ���%��������%������������� ��������������� ����� ������������ ���� �� �!���� ������� �� ���'�0�� ��� ��� ���� ������������������������� �������� ������������ ��� �� ����� ��� ��������������� ������ ����� ���������� ���������������� � �����#������� ����������������� ������� ����� ��� �� �� ���������� �� �������(������ ����� ��� ���#�� ��� �� ���������� ��������������� #�� �� ��� ������8� ��� ���� �� ���� ��� ���������� �������� #������ ���

Page 48: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���* � ���� ��

��� ������ �� ���� �� ���� ��� ���������� �� ���#�� �� �� ��� �� ����� �� �����(�� ��������������

"�� ��� �� ���� ����������� �� ��� ��� ��������� �� ������������ �� �����(�� �������� ����� ��� ��� ������������� ����������� ��������� �� ��� ��� �� ������ ����� �����$�

� ,���� � ���5� ������� ��� ��� �� �� ���������� �� �������(������� �� ������ ��� ������������������������������� ������������(������������������������������ ��#�������������� ������� ���������������������*�������� ��������� ���������� �� �������������+������ ���������������� ����

� /��� ���5�1����� ��������� ����������������������������� ���������� ���������� ���� ��� �� ������� �� #����� ��������� *���� �������� �� �� ���������� ������+����� ���������8���������������#����� � ������ ����� �������� ��������������������������������� �������������� �������������������������������������� ��������������������#� ������!�������

'�� ��������� ��� ������������������� ������������������ ���������������������� ��� �������#������������������������������� ���������(����������������#��#�������

'�� ���� �� ����������� ��� ���� ����������� ��� �������� ��� ��� ���� ���� ��#�������� ������ ������ ������������1!�� ����� �� �� #������������ �� ���������� ����������������#������������ ������(����� ��������������������������������������#������������������(������������������

����� ���������������������������� ��� ��

Concepto de valor nulo

&�� ��� �� ������� ��� #����� ����� ����� ���� �)��� �����(� �� ����� ����������������������� ������� ��� �������� ���� ���%�������� ��� #�� ��� ��� ����������� ����� ����� ���������

��� ����� � � �� ��� #������ ����� ��� ��� ��� �� ���� �� �#� ����� ���� �#������(���$�

� ������������*����+���������������� ���� ������� �����������������

� 1)� ��� ��� ���#�� ���� ���� �� ���� ��������� �%������8� ���� ���� ����� ��� ����������� �� �)� ����� ��� ��� �!�� ������� #����� ����� ��� ������ �� �������������

� 1��� ������������ �������������������

"�� ������������ �� #������ ����� ��� ������ ������ �� �����(� �� ��� ���������������%���� ������$�

� ����� �������� ������ ���5�&�� ����� ������������� ����"&@:2�>�������������������������� �������������������������������������������� ���&.@:2�>����������������� �������� ���� �#���#�����#����� ��������������#��������������������������� �#���#�����#����� ������� ���

Page 49: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���*-� ���� ��

� ����� ����� �������� ���5� &�� ���� ���� ����� ��� ������ �� �� ��������������������������� �#� ������� ��������� �� ��������� ����������#������������

���� �� ���������� ������

"�� ��)�� �� ���� ��� �� ���� ����������� �� ��� �� �����(��� �� ������ ������� ����!��������� ���� ���%�������������� �������� �� ������ ������������������������� ��������������������="5/�������� ��� ��������������������������8������������ ������������������� ����������������� ����������������� ��������� �������� ������ ������ �� �������������G�� &�� ���� ������ ���#�������� ��������������%������������ ��� � ���� ��������� ����������������� ������������������ �� ���� ����������� ������� ����������� ��� ��� �� ������ � ������ �� ��� ��������������������������(����������������� �������������������������������

1���������������������������������%����������� ���������������������������������� ���� ��������� �� �� ������� ���� ������� ��� �� �������� � ���#��������� ���E �� � F� ��� ������� � ���� ��� ������� �� ���#�������� �������� ��� ��������� ��������� ������ �� ����� ����%��������������#� �������������������������������� ��� ������� ����������� ������� ���� ������� ������ � ��� "�� ��� ���� ����������� �� ������ ���� �� ��� �� ��� ������ �� ��� ���� ����!�� �� ��)���������������� �%������ * ��)��� ��� ;�� �� ��� ����+�� ��� ����!�� �� �������(��������������������� � ����

"����� ������ ������������ ������������������������������������ ����� ��)������� ���� ���� �� ������$�

� .������� � ������������������������������

� /� �� ����������������������� ��� � � ����������������

� 1� ��J� � ���

� -�� � �� ���������������

� -�� � �� �� ������� ������������ �� ������� � � ���� ��� ������ ������� ���� ��������������� ����*���������������������+��

� 1��������� ��� ��� ;��� ����� ������������ �� ��� �� �� ������� �� ��� ������ ��� ��� #�� �� ��� ��� ��� �� ����8� �� ��� ���� �� ������ ������!�� ������������ ���� ������ �����������

"�������������������� � ����������������������(� ������������� ������������������ ��� ��� ����� �������������� ���� ��� �#���� �� �!� ��� ��� � �� ����������������������������� ����������������

"�������������������������������������� +������������ ����� �������� ���*�� @�� ����'!������" ���������1)�+���� ��� ����������������������������*1�������:�������� � +�� &�� � ��#���� ���� ���������� #���� ���� �������� #����� �� ������ ������������ �����������������

)*+'& )�

/89�)� ;/&$�;/�$+/+� &�+>�$3)�� 9?98��� �+$9�)$/�� /@��

�������������������������������������������

G�Las reglas de transformación del esquema conceptual al relacional se verán en el siguiente capítulo�

Page 50: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���0� � ���� ��

��������� :�������������� G4V44� ���� ��� 1 ���5W� DPPH�

��������� :�������������� 66N6V� &?��&��� �� � 1 ���5W� DPCN�

��������� :�������������� 64G46� 3�� �����.����� 1 ���5W� DPCC�

�� ��"�� :�������������� PQCQ6� /����������=�� 1 ���5W� DPPH�

3�� ����� ,������� 4GGV6� ;��� ������� -��������� DPCN�

3�� ����� ,������� 664NN� ������������;�� "������� DPCV�

<�� ����(� ,������� CNQ6V� ������������;�� "������� DPCV�

X����W�� :�������������� 4GDQN� >>����� ��� 1�=�-��� DPCP�

�����#S�� ���� ����� G4V6N� >>����� ��� 1�=�-��� DPCP�

����������������� ����� ����������������� ���#��� ��������������� � � ��������������������������-������������������������ � � ������������������������ ���� ����������������8������������������ ������� ������� ����������� �������������������� ��������������)�� ���� ����������"����� �� ��������� ��������#�($�

� 1�����!�� �� ����������������� ��� ������������ ���� ������� �������������� ��� �� ��������������������������������������� ����

� 1�����!�� ���� ��������������������� �������� �������� ������� ���� ��������� ��������� ����������������������� ���������� ����

� 1�����!�� �� ���� ������������� ���� �� ������� ���� ������� ������#����������������������������������������� ������#���#�������� ���� �� �����������������#���� ������������������������� �����������������������

<������������������������������(������*������ �������� ���������+� ����������� ����� ��������������������� ��� ���������������(����� ������������� ��� ������ ������� � � �� ��� ��� �� ���� �������� ��� �������� 1�� ������ �� ��� ��� ������ � �� �� ������� � � ���� ���� �)� ��� ��� ������ �� ����������� ����� �� �� ��������������������(��������

1 ��� �� ���� ������!�� �� ���������� ���� �� �� �� ����������� �%������������� ������ ����������������������� ��� � � ������������������������������ ����������� �� ���������������� ����!������������� ��� ��� ��� �� ����� -������������ �� �� �������� �������� ������������ � ��� ��� ������ ��� ���� ��� �%�������������� �� ��� ��� ��� ��� �� ����� ��� ��!�� ��� ���� ������� ��� ���� ���� ��(���������� ������ �� ��� ���#�� ��������� �� ��� ��������8� ��� �������� �� �!���� ����� ������ ��� �������� *������ �� ��� ������ �� ������� � � �� ���� � � ���� ��� �������� ���������������������� �������������������� ��������#����������+��-���������� ������ ��� �� ��������� ���������� ������ ������� ���� �����������*������������#�������� �� ������ ��� ��� �� ���+����#���#������� ���������������� ���������� ��������� ��� �� ��������� �����������������*����������������� �����#������� ����������+��

"���������������������� ��������� ����� � � ����������������������������������� ���� ��� �� �� ��)�$� A� ���� ��������� ��� ����� ���� ���� ���������� ���������� ��� ���� ����� ��� ���������� �������� ���� ��� ���� �� �� �!����#��� ���� �� �������������������������� ������������ ���� ������ ����

&������ ��������#� ������ ����� ��)����������������� �!��������� ��������������� �� ���� ������ "�� ��� ����� �� ���� �� ���� �� ��� �� ������ �� ������� ����������������� �� �� ����������� �� ������ ������� ��� ��� ������ � � �� �� �����%���#�� �������� ��� �����(��� ��� ������ �� �� �������� ��� �������� �� �������������� ������� ����!�� �� ��)�� �� ��� �� ���� �� ���%�������������������������

Page 51: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���0$ � ���� ��

� ���� ��������&������������ ������� ����!�� �� ��)�����������������(�� ����� ���� ��)�� ����������� ��� ���="5/�� ���� �� �� ���� ��� � ��� �������������� ����� ���� ������������ �� �#����!��� ��� ����� ������ ���� ������!��� � ������ ��� ����������� ��� ������� �%����� �� �������� &��� �� ������ ����� ��� ��� ��� � ����������������� �������� ����������������������������������������������� ����������� ������� �� ����� ������� ������� �� ������� �� ���������� ��������� ���������� �����������#��� ��������������������������������������������������������� �� ������� ��� ������������� �� ������� ��������8� ���� ���� �� ������� �� �������%��������������#� ����

Dependencias funcionales

�������!�� ������������(�������� ������������������� �� ���� ��������������������� ��������� ����������������������������!�� ����� ���� �������

2��� ���� ������ ���������� ������� ��$� ��� ��� ������� �� ��������� /�� ����� ��� ��������������� ������ ����1�������6���7�� ��������� ��1��&�� ��������7� ���� ������������������ ��6�������������������6� ���������7��������������� �� #����� �� 6� ������ ����� �� ��� �� �� �������� ��� ������ #����� �� 7��/��������������� ���� ���������������� �������������������$�

6�###8�7��

&�� ���������������������������������� �������������������������������(����� �� ���!� ���� ��������������������������� ������������������������������ ��������

-��������������������������$�

�.;/>*�� @�� ����'!������. ����������+�

-� ���� �������������� ���� ������� ��� �������������!����� ��������

�� @�� ���555Y�'!�����

"�� �� ���� ��� �� ��� �� ��� ������������ �� �!����� �� ��� ������� ��� "��� ���� ��������� ������������!������������������������������ ����� �����

"�� ������ ��������� �� ���� ��� �� ��� ������������ �!����� ���������� ��������������� �� ��� �� ���� �� ��� �� ��� �� ���� � ������ �� ������� �� ���� ���� �� �� �!������&��������� ��� ����������� �� ������������ ����� �� ���������� ������� ��� ������� ���� ����� ������������������������������!������

2��� ������������ ���� ����� �� ��� ����� �� �%��������� ��� ���� ������������������������������ �������� �� ���� ������ �������������� ��������� ������� ������������� ��������� �� ���� ���� �� ��� ���� ������ ������������%�������������������"�������������������� ������ ��� �� ������� ������� ������ ����������� ������ �� ����� ��� ���� ������ ����������� �� ������� ��� ����������� ������ ���������� ��� ���� �� ��� ����������� �� ���� ���� ������ ��� �� ��������� ���� ����� �� ������ �� ������ �� ��� ����������� ���������� ��� ���� ���� ���� ��� ��������� ����������������������� ��������������������� ���������� ���� ������ �����

"�� ��� ��������� ������� �� �������� ��� �������� �� ����� �� #�����(��� ��� ���� �����8��� ����� ��#���������($��� ���������������������������)*���� ��� �� ��� �� ����������� ����� �� ���� ��� �������� ������ ������8� �� ������ ��������

Page 52: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���0�� ���� ��

%��(��� ��������� ��� %������ ����� �� )��.��� ��� ������ �������� ������ ������ ������������������($�����%��(���*����������� ���������� ��������� ������� ������ ��� ����� ��� ���� ��� �������+� ���������� &��'�(�������� ��&��'�(�����

"%���������������������������� �� ���� ���������������������������� �� ���� ������ �������#��� ��� ��������� ��� ��� ����!�� �� ��� �������(������� ����#����������������������

+����� ���� ������������ ��������

&������ ������������������6$�

696:��6;<�

&�� ���� ���� 7� ������ ���� ������ ���������� ��������� �� ������ �� 6� �� ���� ������������������ ��6��������� ���� �� ���������� ��������� ����������� ������ 7� ���� ��� �� �� ��� �� �%����#������� �� �� ��� � ��� ���� ���� �����������6��&����������������6�==8�7��

-������������������������������������������ ���������� � �����������������������$�

-/"&'1=>*�� @�� ���� '!������ " ��������� :��@������ :�� ���� �����������'���������,����@���������,����@ �#+�

��� ���� ����������������

�� @�� ����:��@�����5555Y�,����@��������

�� ���� ����� � �� ��� �������� �� �� ���� �� �� ��� �� ��� ������� �� �������%���� ���� ������ ������ �� ��������� :�� �� ���� �� �� ���� ��� �������� ������� ����������������������!��������������� ������������������������������ �������� ��������� ��� #����� ������ ����� ��� ����� ��� �� ���� ��� �� ��� ����� �� ��� #������������ -��� ������� ��� ���� ������ ���������� ��������� �� ���������� ��� ���� �����������$�

�� @�� ����:��@�����ZZZY�,����@��������

"��� ������� ����� ���� ��� ������ ��� �������� ���������� ���� ������������� ��������������� ���� ��������������������������������������)��������� ������������������������ ���

-�������������������� ���� �����$�

��� @�� ��� '!������" ��������

�:��@����� :�� ���������������'��������

,����@���������,����@ �#�

Page 53: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���0(� ���� ��

�� @�� ����:��@�����5555Y�" ��������

:�����������������$�

�� @�� ���555555Y�" ��������

&�� ���� �������� ����� ��� ��� ���� ������� :��@����� �� ��� ���� ��������������������������� ���� ������*��� ��������� ���2���5+��

+����� ���� ���������������

&��� ��� ��������� /*0�[�\+� ��� ��� ���� �%����� ��� ��������� ���� ����������������$�

05555Y[�

[5555Y\�

[55955Y0�

&�� ���� ������������\� ������ ���� ���� ������ �������#�� �������� �� 0� �����#�� ��[������������������������$�

0�555��555Y�\�

-���������������� ��������������������������$�

�.;/>&*�� @�� ����" ���������-�!+�

�� �� �������� ����� �� �� �� ���� �� �� ����� ��� � ������������ ����� ����� �������!� ������ ��������*����������������� ����������������� ����������������!+������� ��������������� ���� �����$�

�� @�� ���555Y�" ��������

" ��������555Y�-�!�

1 ����" ��������5559555Y��� @�� ������� ���� ���-�!� ��" �������������� ���� @�� ������������-�!� ���� ���������#������� ���� @�� ����

�� @�� ���555�555Y��-�!��

Reglas de normalización

��� ����!�� �� ����������(��������� �� ����� �������������� ����������� ���������������������� �������� � ������������0������&�� ������������������������������� �������� ������������������������������������������������!����� ����������������������������������� ���������(�������������� ��������������������� �� ���� ������ �� �������(������ �� ���� ���������� ���� ����� ���� ��������� ��������������� ������� ���� ������������� �� ������������������$�

� ����������������������������������������� ������ �����������#��������������������� ���� ���

Page 54: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���0*� ���� ��

� :���� ����� ��������#������ ���������������������������� ���������� ������������(�������

� ������� ���� ������������������������������������������������������������� ��������������� ���������� ��������������������������

� "�� ��� ����������� �� ��� ������ �� �������(������ �� ��� � � �� ���������� ��������� ���� ���� ������ �%������� ������ ��� ���� ���� �� ��� ��������� �� ��������������������������

���������������������#������������� ����������� ���������(������#���� ��������� �� ��� ����������� �� ��� ������� ������ �� ���������� ���� ������� ������ ������������������������ � ����������� ��#���������������������� �� ������ ��������� �������� ��� ����������������

������������������#�� ����������� ���������(������������������������������������ �����������������������������-�������������������� ����������������������������� �� ������������ ��� ���������� ����������������� ��� ������������� ��;����5�� �

���������������������� ;��

/���� ����������������������� ������ ��������� ��� ������������������ � ��� ��������������������#����� ������ � �������������������������������

>����������� ���������� ���������� �����������9&%:<����!������������������������������/�������������������!������?�

-������������ ��#������������������ ��$�

*�+$+�*:������� ,������ :��-��#�� :��-���� ���-���� /���� ������������������-�����+�

;������ � ��� ;��*����

;��*��� +��*��� )�� +�� ��� ��� &��� *�� ���

HHHHD� HD9HG9HG� PCQ� -���(� ������G� HHGV� ���#�� GHHHH� H�HG�� � � � � HHG6� -����� VHHHH� H�H4�� � � � � HH4C� '�������� CHHHH� H�HD�HHHH4� HG9HG9HG� PPP� =����(� 3�����G4� DHHG� ����� DHH� NH�� � � � � DHHV� ����� GH� NHH�� � � � � GHHD� =��� 6HH� 4H�HHHH6� HV9HG9HG� 666� ����(� &����DH� 6HHG� �������� 6H� 46�

&��� ��#������������� ���������%�����#�����#������������������ ����/���������������� ����� �� -�����8� �� ������ ������ � ������ ��������� ����� ���!������-���� ����� ���� �� ��� *��� �� ��������� ������� ��� ��� ���,:D+� ��,:D�� �� �������������� ��� ����� �� ���� ���� �� ��� ������ ����� �� �� ���� �� ��� #������ ��� ��������������#��������������������������������������

*�+$+�*:������� ,������ :��-��#�� :��-���� ���-���� /���� ������������������-�����+�

;������ � ��� ;��*����

;��*��� +��*��� )�� +�� ��� ��� &��� *�� ���

HHHHD� HD9HG9HG� PCQ� -���(� ������G� HHGV� ���#�� GHHHH� H�HG�HHHHD� HD9HG9HG� PCQ� -���(� ������G� HHG6� -����� VHHHH� H�H4�HHHHD� HD9HG9HG� PCQ� -���(� ������G� HH4C� '�������� CHHHH� H�HD�HHHH4� HG9HG9HG� PPP� =����(� 3�����G4� DHHG� ����� DHH� NH�HHHH4� HG9HG9HG� PPP� =����(� 3�����G� DHHV� ����� GH� NHH�HHHH4� HV9HG9HG� PPP� =����(� 3�����G� GHHD� =��� 6HH� 4H�HHHH6� HV9HG9HG� 666� ����(� &����DH� 6HHG� �������� 6H� 46�

Page 55: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���00� ���� ��

.����������������� ;!�

>��� �������� � ��������� ��� �� ����� ����� ������ 9&%;<� ��� !� ���� ������������ ��� ������� ����� ������ !� ����� ������� ��� ��� �������� ����������������������������������������������������������������������?�

-���������������� ��������������������������$�

-/"&'1=>*� �� @�� ���� :��@������ :�� ���� ����������� '���������,����@���������,����@ �#+�

"��������������������� ���� @�� �����:��@������������������#������������ ����������������������������%����������������� ���� ����������������$�

:��@�����555Y�:�� ���

:��@�����555Y�����������

:��@�����555Y�'��������

�� @�� ����:��@�����555Y�,����@��������

�� @�� ����:��@�����555Y�,����@ �#�

-� ���� � ��#��� ���� ���� ���� �� ���� ���� ���� ���� ��� �� ��� ���#����������$�,����@����������,����@ �#��"������� ���� �� �������� ��������#���������� ����:�� ����������������'�������� ���� �� ��:��@�������

-����������������������������������������,:G������ ������� ������������ ���� ��� �������� ��������#������� ��������#������������"�������������������������������������#����������������������,:G$�

� .�������� �� ������5� :�� �� ��� ��� �������� ��� ����� ���� ���� ��� ����������������������%�������������������������������� ������������������ ���� ��� #������ ��� ������ �� �!�� #������ ����� ��� ������ �� ��� ���#��*�� @�� ��+��������������#�������������� ��������� � � ��������#���

� ;���� �� ��������5�&�� �������������� �������������� �������� ��� �� �������� ������������������� ����������������������������������������

� 1������(������ ��������5�&������� ������������� ����������� ��������������������������(����� ����������� �� �������(������������� ��������

-��������������� �����������#������������������������(������������� �� ������������ ��������������-/"&'1=>���� �����#����������������������������,:G��"���������������� ��!��� ��������������������$�

-/"&'1=>*�� @�� ����:��@������,����@���������,����@ �#+�

&>�.>*:��@������:�� ���������������'�������+�

<���� ���� ��� ���� ���� ���� ���� !��� ��� ���� ���� :��@����� �� ����������� �� �� ��� ��������� ���������� ������ ��� ������ ���� ����� ���� ���#�� ����������&>�.>��"���������#������������������ ���� ������� ���� !���������#���������������� ���� ����%��(��� �� ��� ���������-/"&'1=>���� ����� ����������#���%���������� ��� ��������� &>�.>�� ����� ���� ���� ��� �� ������ #������ ����� �� ���� ������ ��

Page 56: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���0�� ���� ��

#������ �%������� ���������� ������ �� ��� ���������&>�.>�� ������ ����������� ����� � �� ���������������

9�� ��������������� ;"�

>����������� ��������������������������������9&%@<����!�������������������� �� ����� ����� ������!������ ������� �� �������� ��� ����������� �� �����������������������������������������?�

-���������������� ��������������������������$�

=1'/.�2�1* ��@�������������������������������� �������+�

"������������������������� ���������������� ������������ ������������������������������������������� ���� ���������� ������������� �������� ����#���� ������ ���� ������ ��� ���#�� ���������� ��� ��� ���� ���� ��@������� �� ����������� &��� ��#��������������� ���� �����$�

��@������������������555Y������

��@������������������555Y������

�����555Y�� ��������

����� �� ��� �� ���������� ��� ��������� ��� ���,:G�� ������� ��� ���� ���� ������������������ ���� ��� ��������#����������� ������������������������������ ������������ ���� �� ��� ���� ���������� �������������� ��������� ���� �� �� ��� ���#������������� ���� �������������#�� ����(��������� �������555�555Y����������"� ����� ��� ���� ������������ ���� �� �������������� �� ��� ���#�� �� ���#�� ������� ����������������������������� ��������#���

��� �%�������� �� ���� ���� ������ ������ ��� ���� ���� ��� ���������������������� ������������������������ ����������������$�

� .�������� �� ������5� :�� �� ��� ��� �������� ��� ����� �� �� �� � �������������(� ���������� �������� ��������������������������������������������������� �������������������

� ;���� �� �� ������5�2���#�(� ���� �� �� �� ������������������� �� ������� ����������� �� ���� �� ��� ������������ �������� ������ �� ��� ����� ���� ��� �������������(� ���������� ���������

� =� ���������� ��������5�"%��������������� �� ������ ��������������������������������������� ���������������������������������� ����������������� �� ���� �� ��� ����������� ������ ���� �������������� �� �������� ��� �����������

-������������������� ������������������������������������%�������� ������ ���� �������������#����������� ��������������� ���������������� �� �� ��������������������$�

=1'/.�2�1* ��@�����������������������+�

2;.�1�.>:*������� �������+�

Page 57: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���08� ���� ��

��� ����� ��#������������������=1'/.�2�1�������,:4����������� ����� ���� �����������%��������������������������� ��������������������������#�� ���������������&����������� ���������#������������2;.�1�.]:���������������������� ��������� �� ���#��� �� ������ ��� ������ ���� ���� ��� �������������������� ��� ����� ���� ����������������� �� ��� ���#��� ���� ������� ��� ���� �� ���������� ���,:4�� "�� ���� ��������� �� ������������=1'/.�2�1� � ��� ����������������#���%������ �� ������������2;.�1�.]:�� �� ������ ���� ����� ���������� ������ �� ��� ��������� =1'/.�2�1� �������� ����������� ��������#������������� ������������#�������%����������������������� ��������������2;.�1�.]:��

�����������������3�� �:&����1 ;3&2�

>����������� ����������������������������!��#����9&%��<����!������������������������&%:��!��������������������������������������������������� ����������� ?�

> ��#�������������������������

=1'/.�2�1*� ��������������������� ������ ��������������+�

&�� � ��#�� ���� ���� �� ���#�� ��� � ���$� ���� �� ������� �� �� ����������������� ������� <���� �� ������� ���� ��� �%����� �� ������� ���� ��� �������� ����"���������������������� ���� ����������������������������������� ������������������ �������� ��I��������2��� ���� ���������������������������� ��

6�###8�7�

7�###8�6�

[�����������������6�^555Y�7��"����������������������������������������� ���� ���������������������$�

���A###8����������������

1 ���� ����� ���� ���������������������� ���������%����������������� ���� �����$�

��������������555Y������

��������������555Y������

����������������� ������ ���555Y������

����������������� ������ ���555Y������

<���� ���� ��� ���� ���� ��� ����������� ���������� ���� ������ �����������������������������#����� � �����

"�� ��� �� ���#�� ��� � ���� ��� �������� ��� ���� ���� ������� ��� ���� ������ �������� ��� ����� ������ ������ �� ��� �� ������������ ������������ ���� ��������� �����#���������������������� ���������#����� � ������ ������������������� ������ ������ ��������������� ������ ���������� ������������� ������� �� ������ �� �� ��� ��� ��������� �� ���#�� ������� �� ��� ��� ����������������� ������������������������� �� ��� ����������������������������#�������

Page 58: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���0 � ���� ��

��������� =1'/.�2�1� ��!�� ���#�������� ������������ ��� �� ���������� ����������������,:;������ �� �� �������������������$�

=1'/.�2�1* �������������������������+�

1�2=:>* ���������� ������ ��+�

��� ������������ �����(� �� ��� � �$� �� ����� ���� ���#�� ���������*=1'/.�2�1+����� ��� ����������#���������������� �� ������#����� � ���� �� ��������������������� *�������������+��� ������� ����������� ������������� �������������#�� ��� � ���� *����� ����+�� ���� ��� ���� ���� ���� ���������� ���� ����������������������*���A###8������������� ��+����������������������*1�2=:>+��������������� �����������������#������������*��+�����������������#����������*��������������+�� �� ���� ������ ����� �%����� �� ��� ���� ������ ���������� ������ ����������!���� "�� ���� ���� �� ���� ��������� *1�2=:>+� ����� �� ����� ���#�� ����������*��+��������������������������*=1'/.�2�1+����#���%���������������

&�� � ��#������ �� ��� ����� �� ��� ������ �� ��������� ������ ����� ���#���������� ��� ��� ��������� 1�2=:>�� �� ���� ������ ����� �%����� �� ��� ���� ���������������� ������ ������ ��� �� � ��������� ������� "�� ���� ���� ��� �� ��� ���������=1'/.�2�1������#���%����������������������1�2=:>��

� ��������� ����������� � ���������� ����� ��� ����

�� )�������� ��������� ����� ���5�'� �� ������������ ������� ��� �� ���� ����������� � �� ������������ �%��!���������� �� ��#��� �������� �� ���������������������� ��� ��#����������� ����-� �!���� ���������������������������� ���� ����� ����������������

!� / ���� ������#����5� '� �� ���� � �� ��� ����� ��� �� ������ ������� �������� �������� ��� ���� �������#����� �������#���������� ��� ���������������

"� 9���������� ��������� �� ��� �������� �����5� ��� #������ ������������������ ������� �� �� �������� ���� ���� �� ��� ����� ���������������� ���� ��� ������� ��� ����� ��� �� �������� ��� ������ � �������������������������������

5� &�������� � ����� �� �%��� ������� �� ��� ������� ���� �����5� ����������������� �� ��� ���������������� * ���������� �� ��� ��� �� ���+� � �� ��� �������� ��� �� �������� ��������������� � ���� ��� �����(�������� �� ��� ��� ����� ��������� ����������� ���� �� �����(�� ����� ��� ��� ���8� �� ������ ��� �� ���� �� ���� ����� ��� ���������������� � �� ������ ����������������

6� .������������������� ��������5��� ���%������������������������������������������������ ����� ��� �� ����* ���������� �� ����� ���������� ��#������������������ �� ����������������� ��������� � ��������(���������������� �������������+��

B� / �����#� ��� ��� �������5� '� �� #���� ������������� �������(� ��� � ���� �������������(� ����������������

C� $��� ����(������ � ������������� ������������������5�'� ���������������� ��������������� �� ����*��������� ������������ ������������ ���� �+� � ���������� ������������ ��������

Page 59: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��*�R����+ � ������������� � � � � ���0-� ���� ��

D� $������ ��� %�� ���������������5� "�� ������ ������� �� ��� ���� � ������������ ����������� ����� ���� ������� �� ���������� ��������� ������������������

E� $������ ��� ���� �� ��� ���� ������5� ��� ��������� �� ����������� ��� � ��� #���� ������ �� ���� ��� ��� �����(� �� ��� ��� �� ��� ���� ������������ ��������������������������#�������������������

�F� $������ �������������������5����������� ��������� � � ������ ��� �� ���� � ��� ��� ����� ��� ���� �� ��� ��� � ��������� �� ��������������� �� �� ��� �� ����������� ��� ��� �������� �� ��� ��� �� ����*���� ��+�������������������� ��������������

��� $������ ��� ��� ��� �������� ���5� �� �� �%����� ��� � ��������� �� ���� ���� ��� �� �������� ��� �� ���� ���� �� �� ��� �������� ������������ ����������������� ���� ���� �������� ����������������#�(������� ���� ������������������������

�!� )����� ������ �� ����������5� &�� ��� &3;�� ������� ��� ��������� �� ������#����������������������������������������������� �������(������������������� ������ �� ������� � � �%���� �� ������ ��� ��� ��������� ���� �������#����

Page 60: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ����� � ���� ��

%� & � � � � �� � �� �� � � �� �" � ��� � �#��� � � � �� � � �� � � �� �� � � �� � ��

<������������������������ �������������� ������� ����������������������������� ����� ������� �����������������������������(� ���� ���������="5/����������������� �� ���������� ����������������

"��������� ����� ������� ������������������������������������������������������� ���� ����� �� ���� ����� �� ������ ����� ������ �� �� ��� �������������������� ����������� ��� � ����� �� ���� ������� ��� � ��������������������� ���������� ��������"����������������������� �������������� �����������#���� ���������������������������� ���������� ������ � ����������� ���������������� ���� ������� ������ �� ��� ������� ������������� ��� �� ��� ����������������������� ��������������#���������������������������������������

���� � ������������� ��� ���������� ����

-��#��� �� ��� ����������� �� ��� ������ �� �������������� �� ����������������������������������������� ��������� ������������� ��#�� �������)9�&/)�������#����������������������� �������������������������� �������������������� �� ���� ������ ������������� **)9�&/)+� ���� ���������� �� ����������� ������ ��� � � ���������� �����������������

��� -/'"�1/� �� ���� ��� ��� ����������� �� ��� �������� ������ ������� �� ���� ����� ���� ������� ������ �� ��� ������� ������������� &�� ���� ������ ���������� ��� ����� �� ���� � � ����� �� �������������� ��� ��� ��� ��������� �� ������ ��� � �����������*��������������������� ��������������+��������������������������� ���� ���� ������ �� ��� �� ��������� �� ���� ����� �� � ����� ��� ���������������!�$�

�� 1������� ���� ���� �������� ������ �� ��� ����� �� ���� � � �� ���������������������������#����������������

!� 1������� ���� ���� �������� ������ �� ��� ����� �� ���� � � �� ��������������������������������

"������������������������������ ��������� ������� �����%�������������������������������������� ���������#��������������*��� ������������������ ���,:D+��=������������������ ��������������������������������������� �������� �� �� ���������� ��������� ��������������� �������������

Eliminación de atributos múltiples

�����������������������������������$�

,'#)+-'./B� )��� ��� �������� �/������C� ��� ������ ��� �������� ����������� ����� ���� ��� ��� ����� ��� ��� ���� ��� ��� ����� ������ �������� ���������������� ������ ��� ��� ������� �.��� ����2����������������������������������������������'��9:B%<�������������������������������������������������� ������������������������*�������������������������������������/������

Page 61: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ����$ � ���� ��

��������������������������������������?��������������������.����������������������������������� �����������������������������������/���������������������� ������'��������?���������������������������������������������������������������������.��������������������������������� D������� �������������������������������������������������� ��������������������� ������B�

:? "������� ������ � � � ������� �������� ���������� � �������� ��������������������������������� ����� � ����������������������������������� �� �������������������� ���� � �������� �����&��������� ���������������� �� ����� ��� ����������� �� ������������������� ������ � �������� ���� �� �������� ������ � �������������� ��������������� �����������������

;? &���)� ���������#������ ����*�%���������������� ������� ������ ����+�������������� ��������������� ��J� � ���������� � �� ����������� ������ � � � ����

"�� ��� ��������� �������� ��������� ��� ����� �� ���� � � �.;/>�� ��� ��� ������%����������� ��������������������� �������������������� ����������� ������ ������������������ ������������-�������������� �����������-/'"�1/5D��������� �����������������#���� ������������� ������ � � � ��������%����������������������������� ������ � � �.;/>�� ������� �� 12'>/�� "�� ����� �� ���� � � 12'>/� ������ ��������������� ��������������������������!���������� ������ � ��.;/>������ ���������������� �������������

Eliminación de atributos compuestos

"�� ���� ��������� �������������� �� ��� ������� ������������ ����� ���������������������������������������������������������� ������������ ���� ��������� �������������������� �������������������������� �������������������$�

,'#)+-'.0B� )��� ��� �������� ��������� ������� ��� ��� ���� ���������� !� ��� ���� ��� ������������ ������ ���� ������������ ��� ��� ��������

��.;/>�

� ��

� ������

� ��������

������

�����

������_�

*)9�&/):��

12'>/�������:/�

:$:�

*D��+� *D��+��"0�

���� �� �@�������

��.;/>�

� ��

� ������

� ��������

������

������

������

Page 62: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ������ ���� ��

������� ���� ������ ������ � ������� ��� ��� ��� �������� ����������������������?� ��� ����� ������ ��� ������������ ��� �������� ��� ���������������� �������� ��� �������� ������� ������� ��� ��� ���� ����� �����������������������������������������������������������?�

"�� ��������������������������������������� ������������� �������������������� �� ���� � � -"/&>:1�� "��� ����� �� ���� � � ������ �� ���� ���� *�������� !������#������������ ��� ���������� "�� ���� ��������������� ��������� ����������� ������������/��������������������������#���������������!�������?�"������ ���� �����#������� �� ������ ���� ��� ����������� �� ��� ���� ���������� ����������� ��� ����� �� �� #�(� �� ��������� ���� ��� ���� ���� ������:� �� ������;�������� �� �������� ���� ������ �� ���� ������� �� ��� ���� ���� ��������� �����#������������������

�� ����� ������������� ��� ���������� ����

1����������������#���������������������� ������������������������������ ����� � ����� �������� ��� ��� ������� ������������ �� � ����� #�� �� ��� ���������� ������� ������������� "��� ������ ��������� ��� �������������� �� ���������� �������� ����� ������ � �� �� ������������� �� ���� ������� �����#�� �������#��� ���������������� ������ �������������������� ����������� ���� ��� �$�

�� "������� ��� ����� ��������������������������� � �������������

!� ��� ��� ����� � � �� ��� ���������� ���� ��� � ����� ���������� ���� ������ ������������������������������

Transformación de los tipos de entidad

'#)+-'./1)��� �����������������������������������������������������������������������������������������������������������������������������/���� !� ��� ��� ��������� ��*� ��� ��� ��������*����� ��� ���������� ��� ������������?�

�-"/&>:1�

���������

�����

������

������

������

���

������ �

���#�����

�� 5�����

��

� �

��� ��5���������

������ ����� ��

������ �D�

������ �G�

�-"/&>:1�

������ � �

���#������

�� 5������

��

� �

��� ���

������ �D�

������ �G�

�����

������

������

������

���

*)9�&/):!�

Page 63: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ����(� ���� ��

-����������������������� ������ � ��.;/>� ������������������������� ��� �!��������������������$�

�.;/>*� ���� �������� ���������������������+�

12'>/*�����+�

Transformación de tipos de interrelación uno a uno

����� ��� �� ������������������������������ ������� ������ � ������������ �����������������������������������������������������$�

'#)+-'0./1�������������������������������������������������������������� ��� ����� �������C� ��� ������ ����� ���� ��� ������� ��������� �����������������*����!���2��� �����������������B�

� &����� ������� ������ � ����������������� �������� ��$�

:? ��� ������� ������ � ����������������������������� �������� �������������������� ��������� ���� ����� ������� ������ � ��

;? ������#�� ������� ��������� �������� ��� ���������� ������ � ��

� &�� ��� ����� ������ � � ������� ��������� � �������� ������ ������� ������ � ���������������������� ������

:? �� ���� ������ ����������#������������ ��� � �������� ��� ���� ������ ���������� ������ � � ������������� ���#���

;? �� �� �� ��� ��� �� ����� ���#�� �%������ ��� � �������� ��� ��� ����� ����� ������ � ������������������������� ���

� &����� ������� ������ � �������������������#������������ ����������������� �� ���� � � � ���� �������� �� ����� �� �� ������� �� ��� �� �������%������������������������������� �������������������������������

&�������������������������������������������������

"�������� ����!�$�

1/'.�2�>*/���� ������������#���������@����+�

�1'>&@<":'1&*)��� ��� � ��� �� @�������� �� @#������ �����@�������������@#����+�

�1'>&�<":'1&������/:��

D$D�

*D�D+� *D�D+��.��

�@��� ������

�1/'.�2�>�

/����

����������

�#��

������@����

/������� � ��

�� @������

�� @#����

�����@������

�����@#����

Page 64: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ����*� ���� ��

1��������� �������� �!���� ���� ���� ��������������������$�

1/'.�2�>*/���� ����������� �#��� ������@������ ��� � ��� �� @���������� @#�����������@�������������@#����+�

-����������� �����������������������������������$�

"�������� ����!�$�

�>:�2�'>/*�������� ���� ��������������� ���+�

12'>;2&*����!����������������������� ���������@��� ��� �����)����+�

'#)+-'0.01� �� ��� ��� ��� ������������ ������ �� ��� ��� ��� ���� ������������������������������������������������������������������������������������������������������������� ��� )��� #:�!���������������� ��������������������� ������B�

:? "�� � �������� ��� ��� ����� ������ � ��������������������������������������� ���� ������� ����������� ������������������������� ������������� ������ � �� "�� ���� ���� ���� ���� ���� �� �� ������ #������ ����� ����� ��������� ������ �� ���� �� ���� ��������� ��� �������� �� ��� ����� �������� ����������������

;? &�� ��������� ���� ���#�� �� ��� �������� ������ ��� ����� �� ������������������� ������������� ����� �������� ���� ����� ������� ������ � ��&������ �������������#�� �������� ������� �������� ��� �������� ������ � ��������������� �� �������������������� ����� �� ���������������������� ���� �� ���� �� ��� ������ ��� ����������� ���� ��� ���#�� �� ��� �� ����������� ������������������������� ���������� ������ � ��

-���������������� ������������������������������������

12'>;2&������&:/�

D$D�

*D�D+� *D�D+�

��� ��� �@���� ��� �����>:�2�'>/�

�����

��� ���

���������

����!������������

�����

�� ���

����@��� ��� ��

�)�

Page 65: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ����0� ���� ��

"�� ������� ����������� ��� ����� ��� �� ��� ���������������� �� ����������������������$�

"=-�"1�>*�������� ���������� ������������+�

=1?2.:1*�R@������������������������ ������+�

"��������� �������� �!��������������������� ������������������������$�

"=-�"1�>*�������� ���������� ������������+�

=1?2.:1*�R@������������������������ ���+�

"=-5=1?*G>��������+�

'#)+-'0.21��� ��� ��� ��� ��� ������������ :B:� ����� ���� ��� ������������������������������������������������������������� ��� )��� :������������ ����� ��� ���������� ��� ���� ������ !� ��� ������� ��� �� ���� ��� ���� ��� ������� ������B�

:? ��� � �������� ���� �� �� �� ���� �� ��� ����� �� ���� � � ����� �� ���������������������� ���� ������� ����������� ������������������� ������ � ��"������� ��������������������#���%��������������� ���

;? &�� ��������� ���� ���#�� �� ��� �������� ������ ��� ����� �� �������������� ������� ���� ���� ���� ��� � �������� ���� �� ��� �� ����� �� ���� � �� ������#������������ ������� ��������� ��������� �������� ��� ������ ���������� �� ���� � � ��� ��������������� �� ������� ����� ���#�� �������� ���� �������� ��� ������������� ������ � ��

"�� ������� ����������� ��� ����� ��� �� ��� ���������������� �� ����������������������$�

=1?2.:1�������:'�

D$D�

*H�D+� *H�D+�

������� �@���� ���������"=-�"1�>�

�����

��� ���

������ ��

�R@�������������

�����

�� ���������@�����

=1?2.:1�������:'�

D$D�

*D�D+� *H�D+�

������� �@���� ���������"=-�"1�>�

�����

��� ���

������ ��

�R@�������������

�����

�� ���

Page 66: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ������ ���� ��

"=-�"1�>*�������� ���������� ��������������G>�����+�

=1?2.:1*�R@������������������������ ��������������@�����+�

"��������� �������� �!��������������������� ������������������������$�

"=-�"1�>*�������� ���������� ������������+�

=1?2.:1*�R@������������������������ ���+�

"=-5=1?*G>��������(�������@�����+�

Transformación de los tipos de interrelación uno a muchos.

"���������� �� ������ ����� � ���!��������� ��������������������� ������� ������ � $�

'#)+-'.2./B� �� ��� ��� ��� ��� ������������ ������ :B%� ����� ���� ���������� ��������� ��� ����� ������ � ��� ��� ��� ������� ���� ��������� �������������� ��2��� ���'�� �������� ��� ����� �������� ��������� ����� ��� ���������� ��� ���������� ��� ���� ������ ��� ��������� ��� ��� �� ��� )��� #:�� !� ����������������������������������������������������������2������������������� ������ ��� ��� ������ ������������� ��� ��� ��� ������� ���� �������� ����������������2������'�?� ����� ������� ����� ��������������� �2������ �������� ������ ���������� ���� ���������� ��� ��� ������ ������������� ��� ��� ���������� ���� �������� ��� ����������� ��2��� ��?� �� ��� ��� ��� ������������������� �������� �������� ����� �������� ������ �� ������ ������ ��� ��� ���������������������������������������������������������������2������'�?�

���� �������������������������$�

"�������������������������� ���#���$�

"�.'>/.1�*��� ���� ��������� ���������������� � +�

/"<.&'1*�!����������� ����������������:��������������������+�

'#)+-'.2.0B���������������������������������:B%���� ������ ������������������������������������2���������������������������������������������������������������������������������������������� ��� )��� #:�!���� �������������������������������������������������������?����������������������������� ��� ������������ ��� ��� ���� ��� ������� ���� ���������� ��� ��� ��� ���������������!���� ���� ��� �������� ������� ��� �����������������?� $��������

"�.'>/.1��������:'�

D$D�

*TH`DU��+� *D�D+�

� ���� �@� ��� �@����/"<.&'1�

�!�����

����� ��

�������

��� ��� ��������

��������

������ � ���������

Page 67: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ����8� ���� ��

�������� ��� ����� ������ ����� ��� ������� ���������� ������������� ��� ��� ���������������������������������������2������'���!� ������������������������������2�����������������������������������������������������������������?�

���� �������������������������$�

"�������������������������� ���#���$�

,1�'2/1*������@���������������������@�������+�

1�;1/a:*������@�� ����������@#�����������@�� ������� ��@��#!�+�

,1�'51�;*������@�� �����������@��������� �������+�

Transformación de tipos de interrelación muchos a muchos

.� ���� ����������� �� ������ ����� � ��!����� �� ��� ����� ������ � ����������#����������������� ��������������������������������������������������$�

'#)+-'.3B�������������������������������%B%����������������������������������������������������������������� ��� )��� #:�!���� ���������������������� ����������������� ��� ��� ��������������?������ ������ ������� ������� ��� �������������������������������������������������������������������������!����������������������������������������������?�$��������������������������������������� �� �����������������������������������������������������������������������������������������������������?�

"�������������������������� ���#���$�

12'>;2&������&:/�

:$=�

*D��+� *D��+�

��� ��� �@���� ��� �����>:�2�'>/�

�����

��� ���

���������

����!������������

�����

�� ���

����@��� ��� ��

�)�

��������

1�;1/a:������ :/�

D$:�

*H�D+� *H��+�

�@�������@��� �������� �@��,1�'2/1�

������@��������

������

������

������@�� ���������@#�����

�����@�� ���

�� ��@��#!� �������

Page 68: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���� � ���� ��

�>:�2�'>/*�������� ���� ��������+�

12'>;L&*����!������ �������� ������� �� ����� ����@��� ��� �����)�+�

�>:512'*�(�����% �������������+�

Transformaciones de tipos de interrelaciones n-arias

"������������ ���������������� ������������������������������#�������� �� �� ����� �� ���� � � �� � �� �������� �������� ������ ��������� */'"�1/5V+�� �� �������� ������� ������ � ���������������������� ������������� ��������������������������������������#���� ������������ �������������� ����� �������� ���� ���������� ������ � ������������������������� ������������������������� ��������� ����� ����� �� ���������������������#�� ������ �� ������ �������������� �� ������� ����� �������� ���� ���������� ������ � ��

&�� ��� ��� ��� ����� ��������� � ��� ��� ���� ��� �� ��� ������� �� ���������������� ��� ����������� ��� ������� �� ���� �� �� ���� �� ��� ��� �� ���� �� ����� ������ �� ��� ������ ��� ���� �� #����� ��� ������� �� ������ �������� ��� ��������������������������$�

������!���� �����������������������������������$�

�>:�2�'>/*�������� ���� ��������+�

12'>;L&*����!����������������������� ���������@��� ��� �����)�+�

�231/*��� � �����������#�����+�

�>:512'5�23*���������!��������� � �������������+�

"���������������������������������������/'"�1/5V� � ��������������� ���� �� ��� ����� �� ���� � � ����������� ��� ��� ����� �� �������������� ���� ��� ����� � ��%�����������"������������������� ���������� ������������� ������ � �����������

12'>;2&����&:/:��

:$=$-�

*D��+� *D��+�

��� ��� �@���� ��� �����>:�2�'>/�

�����

��� ���

���������

����!������������

�����

�� ���

����@��� ��� ��

�)�

�����

*D��+�

�231/�

��� � �

���#������

�����

���@����

Page 69: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ����-� ���� ��

����������� ����������������������� ����� � ��%������������������������������������ � �������� ��� �� ���� ����� �� ���� � � ������� �� ������� ������ �� ��� ���#�� �� ����� ��� ���� �� ���#�� ��� ����� �� ��������������� > ��#��� ���� ��� ���� ��� ����� ������ � ������������������ ����� � ��%������������������������� ����������������� ���������������������������� ������������� ��������� �������������������� ������ � ����������������������������� ������������������������ ���������������������� ����������� ������ � ������������ �����������������

Transformación de tipos de interrelación reflexivas

��� ����� �� �������������� �����%�#��� ��� ���� ������� �� ������#����������������������������������������� ������������������������� ������ � ��������������"� ������������������� ���������������������������� �����#�������� ����� �� ���� � �� -���� ���� ����� �� ��������������� ��� ��� ���������� �����$�

�� "������� ������ � ������������������ ������������������ ����� � ��%��������� �� ��� ��� ����� ������ ���� ��� ����� � ��%����������� �� ���� �� �������������������� ����� � ��%���������

!� "������� ������ � ����������������� ����������������� ����� � ��%�����������

"��������� ���������������� �� ���������������������� �������������������� ��������������� ����������������������"� ��������������������� ���������������� ������ � ���������� ���������������� �� ��������������*������/'"�1/5V+����� ��������� ���� �������� ��$�

� ������� ��������� ���������� �����������������

� "��� �������� ��� �������� ������ � � �����)�� ������ ����������������������� �����������������

� "�� � �������� ��� ��� ����� �� ���� � � �����)�� �� ��� ����� ������* �����)�� ��������+������������ �����������������

��� ���#�� �� ���� �� ��� ��� ��� � �������� ��� ��� ����� �� ���� � � *���� ������ �+��������������������������������������� ���������$�

1������ ������������ ���������������������������������� �$�

>;A"'>*� ����������������+�

>;A5>;A*� @������������� @������� �������+�

������:��

:$=�*D��+�

*D��+�

���@����� ��

�����@�����@ ��

>;A"'>�

� ��

��������

�����

�����

Page 70: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���8� � ���� ��

��� �� � @����������� ���������� ��� � �������� ��� ��� � ��������� ��������� �������� ������ �� � @������� �� ���������� ��� � �������� ��� ��� � ����� ������� ������������������ �������� ������

&������������������������������� ������������ ������������ ��������������� �������� ����� ���������������!��*��������������������+��������������������������������� �������������������� �� ��������� ����� ����������������$�

�� &��������������� ���������������� ������ � ������������� ������)� ����������#���%��������� � �������� ��� ��� ����� ������ � ������������������������� ����� ������ ������ �� ��� ���� � ������ "�� ���������� ��!�� �� ��� ������*���� �������� ����� � ��!����������+$�

>;A"'>*� @������� ���������������������> ������������+�

!� &�� ������� ���� �� ��� ����� ��� ����� �� ���� � � �� ����� ����� ��� ����� ��������������������� ������������� ��������� ���������� ��������������������� �������� ��� ��� ����� �� ���� � � ��� ����� ��� ��� ���#�� �� ��� �� �������������� ����� � ��������� ������������ �� ������ ������ �� �����#������ �������� ��� ��� ����� �� ���� � � ���������� �� ��� � ����� ��� ����� ������������������� ����� ���������������!���"���������������������������������� �� �����������*���� �������� ����� � ��!�����������������+$�

>;A"'>*� ����������������+�

>;A5>;A*� @��������������������> ������+��

���� �������� ����� ����������� �� ��

"�� �� ���� ����������� ��� ������ �� ��������� ���� ���������� ������������������ �����������������������������������������#���������������������� ������������ �� ��� ���������� ���������� ����� ���� ���#��� ��� ������� ���������������� �� ��� ������� ������������ �� ������������� "�� ��� ������� �������������� ��������������������������� � ������������������ ����������������� ���� �����������������������������������#���� ���� ��� �$�

� ���������� � �� �����������(���������� ��� � ����� �� ���� � � ������� ������������ ��� ��������� �� ����� �� ���� � � �� ��������� ��� ��������(���������������� ��� � ����� �� ���� � � ������� ����� �� ��������� ���� �������� ����������� �� ��� � ����� �� ���� � � ��� ����� �� ��� � ����� ����������������� ����� �� �������������� ���������� ��������������������� ������ � ��

� "������� ����������(���������������������������� ������������������������������ ����� ��� �� ��� ������� �� ��� ��������$� ������ �%����#��� ���������%����#���������������#������������������#���

� >���� ����� �� �������������� ���� ���������� ������ ��� � ����� ����� ������������ ������ � ��

� ��������� �� ������������� ��� � ��� �� ��� ��� ������ ��� ��� ���� �� #�� ������ �������� ������������������������������������������������ ����� ������ � �������������� �������������������������������

"������������������������������������������������������������#����������������� ��� �������� �� ����������� �� �� �� ���� �� ���� ������� "�� ��������

Page 71: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���8$ � ���� ��

���������� ���� ����� �� �����#�� ���!����� � ��� ��� ������ �� ������������� ����������������������� ��������� ����� �������#����� ���� ��� �� ������� ������ ���������� ��� �� ��������������������������� ������������ ��������������������1 �������������������������� ����� ��� �� ���� ������ ����������#���

'����� �������������� ������������)��� ���������������� �������������� ���������� ������������������������������������������� �������������������$�

,'#)+-'.2�� ��������� ���� �������� ��� ������B� ��� ��� ��� ���������������������������������������������������������������������������������������������������������������� ����������!������������ ��� �������������������������������������������������������������������������������������������������������.��������������������������������������������������������� ����������� ��� ��� ������� ��� ������?��� ��� ��� ������������������������� ��� �2�������� ��� ������� ������������ ��� ����� ������� 9������������*�������<�����������������������������������������������������?�

"��� ������ ���� ��� �� ��� ������ �� �� ����� �� �������������� ��������������������������������������������������� ������������ ������ � ��������������� ������������ �� ���� � �������������(� �� ��� ��� ���������� ������1 ���� �� �������� ����������������������������������#������������ ����������������������������������#� � � ��� ��� ���#�� ����� �� ������������������ ���������� ���� ��� � ��������� ��� ������������� �� ��� ����� �� ��������������������� �� ���� ��� ��������� ������ � �� -��� �� ������� ����� ������ ����� ��� �������� ���� ����� ����� ������������ ������������� �����������������0 ���������

2��� �������������� ������ �� ��� �� ���� ������ ����� ���� ������������#��������������#�������������������������� �$�

Page 72: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���8�� ���� ��

�� ������������ ���� ������������ ������ � �������� ������� ������ ������ ���������� ���������� �� ������ ���������������

!� 1�� ���������� ��� ��������� �� ���� � � ��������� ��� ��������� ���������%������� ������ ��� � ������ ��� ����� ��������� �� ������� �� ������� ���������� ������ � � ��������������������

"� "�� ������� �� ����� �� �������������� �������� ��� ������� ���� �� � ���������������������� ��������������������������!�������������� ������ � ������� ������ ������ ������

5� :������������������������������������ ��������������������������*����������������� �������� �� � ����� ��������� �� ���� � +� �������������������������� ��#���������� ������ � ���������� �����������

"������������� � ���������������� �����������������������#�������8��� ������ ���� �� ��� ������� �� ���� ���� �������� �� ��� �����)�� �� ��� �%���������������� ������������������������������������������������ ������ � ���

"�������������������� ��!�� ��������������������$�

"�������������������������� ���#���$�

�"/;.�.�1*��� ��5��� ��� ���������������������+�

&"�1:>*��� ��@�����#������������������5���������+�

/"31�.>*��� ��@�����#��������������������5���� ��+�

Page 73: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���8(� ���� ��

&2;<":�.>:"&*��� �_�� ���������� ����#��� ����� � �� �����> ������(������+�

1;1&'"�.=.":'>*������������+�

/"31@1;1&*��� ��@�����#�����������������������+�

A�)3>.�&/1�����:����� ���(������: ������(������(� ������2�

A�)3>)�4/1�����:����� ���(������: ������(������(� ������2�

&�� �������(������������� ����������� ����� ������� ����� ��� ��#��� �����������$�

� ��� �� �������%,� �� �E��+,� ������� ��� ����� ���#��� �� ���� ������� ����%���� ������� ��� ���������� ���� ���� �� ���� ��� ����� �����#�� ��� ����������� ����� ������ ��� �� �� �� ���� ����� ���� #�� ��� ������� �� ��������������� ������ ����������������� �� ��� ��������������#������ ���� ���������� ���� ������ !����������� ����� �����������������������1!������ �������� � ��� ��� ���#� �� �%����������� ���� ��� ������� �� ����������� ��������������� ������������������������������� ����

� ��� �� ���1� �( �E�� ��1� �(����� ��� � �������� ���� ��� ���� �� ������������ �� �� �� ��� ��������"������������� ���� �� �� ��� ���� �!����������������������� ����������$�

A�)3>&8�91�����:����� ���(� �����: ������(� �����(� ������2�

���������� �� ������ ��� �%����#� � � ���� �%���� ������ ��� ����� �������#�� �� �� ��������� ������ ��� ��� ��� �� ���� ��� �����(� �� ����� ���������������

1����� ����� ��� ���� �� ��� �� �������� ��� ��� ����� ��� �������� �� ���������� � �� ������ ���� ��!�� ��������� ������� ��� ���#�� �� ���� �� ��� ��������#���%������ ������� ���&"�1:>���/"31�.>����������!��������������-������ ��� ���� ����� ���� �� ��� ��!�� ��� ���� ��������� ��������� ��� �� ���&"�1:>���/"31�.>���������������� ������������������ �� ������� ���� ���� �� �� ��� �� ���� ��!�� ��� ���� ����������� ���� ��� ��������� ����� ������������������������������������������ ������ � ��������� � ���������������� ����

� "�� ������� ���� �� ��� �� �������� ����� ����� �� �������������� �����������������������������������������������������������!������������������� ��������� � ������������������������������ ������

,'#)+-'.3�� ��������� ��� ��� ������� ��� ������B� ��� ��� ��� ��������������� ���������� ��� ������������ ��� ������� ��� �������� �������.��������� ��� �������� ��� ��� ������� ��� �������� !� ����� ��� ��� ��� ���� ������������������������������ ��� ���������� ������� ��������������������������������� ������.������ ��� ��������� ��� ���� ��� ������������ ��� ��� ����������� ����������������������?�

�� ��� ��� ������������������������� ��� �2�������� ��� �������� ��� ����������������� ��� ����� ������� 9����������� �*���� ���<� ��� �������� ���� ��������������� ����������� ������ ��� ������� ��� ������?� ��� ���� �������

Page 74: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���8*� ���� ��

9�������<� ���������� ��� ���� ������������� ���� ���������� ����� ������ �������������������������������������������������������������������� ��?�

"����� ������������#���� �������������������������������������������������� �� #��� �� ��������������� ��� ��� #������ ����� ����� �������� ���� ������������ �� � ������ ����������������� ������ � ��1!������������ ����������������� � �� ������������#����������#� ��*�� �������������������� � �� ���� ������ ������ ����+����������� ��#���������������������#� ���1 ����������������� �� ������ �� ��� ������������ �� #�� �� ����������� ��� ������ ����������������� ��� ������� �� ���� ��� �������������� � � �� �� ���� ��� ��� ��������� ������ � ��������������� �� ����������������������� ���� ��� ������������������������������������������������������������������� ����������������������� ������ ������

"���������������� ������ ��� ������������� ����������� �� ��� ������� ����� ������������������������������������������� ����������"�������������������� ������������������������ ��!���!$�

"�������������������������� ���#���$�

�"/;.�.�1*��� ��5��� ��� ���������������������+�

�2�'.<>*��� ��@�����#������������������������5���������������5���� ��+�

&2;<":�.>:"&*��� �_�� ���������� ����#��� ����� � �� �����> ������(������+�

1;1&'"�.=.":'>*������������+�

1;1&@�2�'*��� ��@�����#�����������������������+�

A�)3>&8�91�����:����� ���(� �����: ������(� �����(� ������2�

Page 75: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���80� ���� ��

&�� �������(������������� ����������� ����� ������� ����� ��� ��#��� �����������$�

� "�� ��� �� ��� &2;<":�.>:"&� �%���� ���� ���#�� �%������ *��� ������������#��������� ��+������������������������ #�������������� ������������������#��� ����� �� � ��!���� ���������� ���� ��� �����#�� � �� ��� ��� �����#�� �������� *���� �� ������ ������������� �� ��� ��� ��� �������������� ���������+��

� -���� �� ��� ����������� ��� ����� �� �������������� ���������� ������#��� � ������ ������ ���� ��� ���� ���� ��� ������ ������ �� ��� ���#�� �� ��� �� ����2�'.<>�� �� � ���� �� � ������ ������� ��� �� ��� ��� ������� �� ������������������������#�� ������� ����2�'.<>��

,'#)+-'.4?������������� ����������*�B����������������������������������� ������������ ��� ������ ���� ��� ������������ ��� �� ��� ��� ������� ���������� ���.�� ����������� ������.����� ��� ���� ��� ������������ ��� ��� �������������� ����� ��� �������� ��� ��� �������� ��� ������?� ��� ��� ���� ��������������� ����������������������������������������������������������B�

:? &�� ��� ����� �� �������������� ���������� �� �%����#��� ������������ ������� ����� � ��!�����������

;? &�� ��� ����� �� �������������� ���������� �� ������#��� ������������ ������� ����� � ��!�����������������

��� ����� ���� ��� ������������ ��� �������� �������� ��� ��������������*����!���2��� �������������������������������� �����������������������/���������������������.��������������������������������������������������� �� ��� ��������� �� ��� ������� ������������� ���� ���������!� �.����� ����2��������������������?�

"��� ������ �� ��� ���������� �� ����������� ����� ��� �������������� �� �������������������������������������#������� �������������������������������#����� �������������� �� ��� �����������%��������������������������� ���� ����� ������ � ������#�� ��������#������� ���������������� � �������� ����� ��� ����������� ���������������������� �������������������������� �������������������� ���

,��������������������� ��������������� ��!���!$�

Page 76: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���8�� ���� ��

"�������������������������� ���#���$�

�"/;.�.�1*��� ��5��� ��� ���������������������+�

�2�'.<>*��� ��@�����#��������������������+�

&"�1:>*�����> ������(����������������5���������+�

/"31�.>*�����> ������(������������������5���� ��+�

&2;<":�.>:"&*��� �_�� ���������� ����#��� ����� � �� �����> ������(������+�

1;1&'"�.=.":'>*������������+�

1;1&@�/"31*��� ��@�����#�����������������������+�

A�)3>&8�91�����:����� ���(������: ������(������(� ������2�

&�� �������(������������� ����������� ����� ������� ����� ��� ��#��� �����������$�

� &�� ����� ���������� �� ��� �������� �� ��� ��������� ����������� �� ���� ��� �� �� �� ��� ���� ���� ��� �� ���#�� �� ��� �� ��� �� ��� �2�'.<>� ����� ��� ����������� ����� �� �������������� ���������� �%����#�� ��������#���

Page 77: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��0�R�7�� � ! �� ����2 � �� ���% ���# �� ������������������ � � � � ���88� ���� ��

� ��� �� ��� � #�������������� ������ ����������� ���� ��� ���#�� �� ��� �� ���&"�1:>�������������������!��������������������������� #�������������� �� ��������������#�� ���������.�������(��������������� ����������������� ���1;1&@/"31��

Page 78: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ���8 � ���� ��

'� � �� � � �� �� �� � � �� �� � � �� � ���( �) � �� � � �� � ��

"���� ����������������������� ���� ���� �� ��������#������� ������������������*���������� �� �����������+� ���� ������� ���� �������� ��� ����������������������� �� �� ��� ��� �� �����"����������������� �������� ����������������� �� � ����#�� �� �����(�� ������� �� ��� ��������� �� ����� ����� �� ������ ��������������#������� ������������������������$�

� .�������� ���������

� ;���� �� ���������

� =� ���������� ���������

� ��������

&��>����������� ����������� �������� ��������� ����� ��� �� ����*; �+��������� ��� ����#��*;��+������ ���%�����$�

>*;��+�Z�;���

'����� ��� ��� �� ������� ����� ��� ��� �� � ����#�� � ��� ��������� ��������������� �� ������� � � �������� �� ��� �������������� ��� �� �������� ��������������� ��������� � � �������*��������� �+��

��� ������� ��� �� ���� ����������� ������ � ��� ��������� �� ������ �� ���%����� *�� �� ������ ��������� �� ������������� ������������ ���� ������� ��������%�� ����������� ������������������ ������������������������������������������� ����� ������������ ����������� ��������������������� ����#������������ ��������������������� �#� ������ ������$�

/������� ��=������������(���������� ������ ��� ����� ����������������� ������ ������������ ����� ������ �� ��� ���������� �� ����� ������ �� �����������������3���������������������������������������� ������

*���� ������=� �� �� ��� ��� ��� �� ��� �� �� ����������� �� ��������� ��� ������ ������������� ��� ����#����� �� ����� �������������������������������(������������������������3���������������������������� �� �������� ��������� �#� ������ ������$�

� ������� ����������

� ������� ���� �������

������ ���� ��� ��

��� ������� ��� �� ���� ������������ ��� ��� ���� ��� ��� ��� �� ��������� ������������� ���� ���������� �� ����� ���� �� ����� ��#��� ����� ������ �� �� �������������� �������������� �����#�������������&����/���/b� ��������������>���� ����� ��� ����������� ��� ��� ��� ������������ 2��� ���������� ��� ��� �������������� ������� ��� �������� >� �� ��� ��������� /�� � ������ ��� /b�� 1�� ��� ���

Page 79: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ���8-� ���� ��

������ �� �� ��� ���������� ����� ���������� �� ������� ���������������� �����(��� ��������>D��������>������������������ �������������$�

>��*�����*>D*�/�+�+�+�Z�/b�

��� ������ �� ��� ��� ��� ��� ������� ���������� �� ��� ����� ���� ����������� ���� ������� �� ���������� �� ���� �� ��������� �������� �� ��� ��� �� ������>��� *DPQG+�� �� �������������� ����� �������� ���� ������ �� ���� ��� ����������%����#�� ������������ ������� ���� ������ ������������������������������� ����������� ������������ ��� ����� ���� �� �� ��� ��� �N����� �� ��� ��� �� �� ��������� ����

��� ����� ���� ���� �����N� ���������������� �>���� ���� �� ������� ����� ���� ����������� 5�>��� *DPQH+5�� ������� �������� �� ��� ������� ��� �������������� 5����� �>��� *DPQG+�� �1�/>.0� *DPQN+�� �1'"� *DPCN+�� ����5�� �� � ������� ����� ����� ���� ����� ��� ��� ��� ������������ �#� � �� ��� �� ������ ��������$�

� �������� ���� ��� ��������� ����������$� ������� ������������� ��������������� ����������������

� ��� ����� ���� ������������ ��������$� ������������ ��������������� ���������� �#������

1������ �� ���� �������������� ��� ����� ���� �� ��� ��� �#� ��� ��� ���� �������� �����������#��������� ���� ���#� �$�

� ��� ����� ���� �������#�� ��� ��� ����� ���� ��������� ���� ������ ��� � ������� �� ����� *��� ������ ��� ��� ��� ����������� ��� ����� ��������������������+��

� ��� ����� ���� ���#� �� �� ��� ��� � ������ ������� �� #����� �� �������� �����������#���-� �!���������� ��� ���������������������������� �� ���#�8� ��� �� ������ ��� ���� ������� �� ����������� ������������������� ��������

>���� ��� ��� �������������� ���� ��� �� ��� ������� �� ������ �� �� �� ������� ������� �#� ����$�

� 2����������������� ��������������������������������������� ���

� ;������������������ ��������� ����������������������� ���

"���� ��� �������� �� �!�����������������#������������������������ ����� ���� ������� �� ��� ����� ����������� ������� ���� ������� ���� �� ����������������������� ���������������������������� ���

1������ ��� #���� �� ����� ����� ���� ��������� ;:,� ����� ��� ��� ��������������*��������������������1'"�*DPP4++�������(������������������������������� ��� ���������� �� ��� ����� ���8� ��� �� �� ����� �%���������� �������� ���������������������������������������������� ������������������

Page 80: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ��� � � ���� ��

Operadores primitivos 8;/)$�.�

��� ����� ����������� ������� ����������� ������������ ��������8������ �� ����������������(��������������������������$�

&���/�*1+����������� ���������������������%����������������� ������ ����1� ����� ��� ��������������� �� ��������$�

/�*1+�Z�/�*�1D�$��D���1G$��G�������1��$����+�

�������������c�� ����� ��� �������������/�� ����� ����!���� ����� � ���������������� ����������������������������$�

�c�Z�T����+�DZD�

�� ��

���Z�^�<�D��<�G� <���Y�9�<���∈����

�������� ����������������������������������������������

/����������*σ+�

����������������� ��������� ������������ ����������������� �����������%��������������*��� ��� �� ����������+�� ������������� �������������������� ������ ��� � ��������� �� ������ ���� �������� ����� �%�������� ��� ��������������������������������� �������������(������ ����c��1���������������������������������� ���������� �� �������� ��� ����� ��� �� ����������� � ��� ��� ���� ��������������������� ���12'>/��

12'>/�

:�� ��� :�������� � � .����������

��������A�� :�������������� /����������.��������

&�������,�� "��)���� 2�-����

������&� .�������� -����������� ��=����

/�����.�� "��)���� 2-<�

σσσσ�� ����������H�I����-���J�1/89�)2�:�� ��� :�������� � � .����������

&�������,�� "��)���� 2�-����

/�����.�� "��)���� 2-<�

,����������$�&����������� ��� ��������������*Y��^��Z�� �Y��Y��_+�!������ ��� ��� �� �� ���������� ����� �� ���� ���� �%������� ������� ������� �� ����������� ����������$�

1��θ�1����1��θ����������

Page 81: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ��� $ � ���� ��

��� �������������� ���� ��������E[F�*1:�+��EHF�*>/+��E:>F�*:>'+��

"�� ����� ��� �� ��������� *������ �� �� ��� ��������� /� ���� ��� ��� ��� �� �� �� �����$�

σ��c�

����� �������� ���������� ����������������������� *�� ������/+� ��������%��������b���$�

�b�c�Z�T����∈���c�9��*��+�Z�E������F�U�

������ �� ������������������������������������������ ��������������������� ��������������/�������� ����� � ��b⇔����

����������������������#�� �������� ��� �������������������������$�

σ���*σ��5D�������σ�Dc+�

������������������������������ ������������������� �������� ��� ���D���G������������ �������������� ��� ��������E[F�

σ�D����G��������

-����������*π+�

�������������� ���������������� ������� ��������� �������� ������������������� ����� �� � ��� ������ �������� �� ��� ������ ������ �� ���� �� �������� � �� �������8�������� ����������� ���������#�������� �� ��� ����������� ������������������������ ����

�������� � �*12'>/+�

:�������� � �

:��������������

"��)����

.��������

���������=�.���K������ ����������� ��������� %�����/=��

0�⊂�1���0�≠�φ�

�������������� �������� ��� ��������������/������������%��� ��0�������� ���������$�

π%�c�

��� ����� ��������� �b� ����� ������� �� /b� *0+� �� ����� �%������� �� ������������ �� ������ �� ��� ��������� ��������� ����� �� � ��� ��� ���� ���� 0���������� ����������������� ������ ����� ������

�b*/b+�Z�T���*0+�9�0�⊂�1U�

Page 82: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ��� �� ���� ��

"����� ���b��� ������ ����� � ��b� �������������������������������$��b�^������b�^������� ����!�� ���������#�������������� ���������� ����� � � ������������������������

���� �� ������ ��� ���� ���� 0� �� ��� ��������� /� � ��� ��� ���� �� ����� �������������� �� ���������� ���� ���#�� ��� � ���� �� /�� ������ �� �� ��� ��� ����������� ������ �8� ���������������������������� ������ ���� �������� ������� ����� ��� ��� ���� �� ��������� ��� �� ���������� �������� ���#�� ��� � ����� �� ������� � ��� ���� �� ��� �(���� ������ ������ �� ���� �� ��� �� ��� ������� ������ ��� ������ *������ ������� ��� ���� ���������� ���� ������� ����������� ������ ����%����� ������ ������+��1�������������� ������������������ ������� ����� ����������������������������������������#������������

3$;/)$�.�

��� ����� ���� ������� �� �������� �� �� ����������� �� ������� �� �����*������� �����������������������+��%������������ ��������������#������ ��&���� �������������� �� �������� &�� �������� �� ������� �� ��������� /D� *1D�� $��D �+� �� /G� *1G �� $��G�+��������� ����� � ���D����G������������ ������������ �� ����� ����� ����� ���� �� �� �� ���� ����� �� � ��� ��� ����� ��������� �� ���������������� ��$�

∀�1D��∃�1G��9 ���*1D�+Z� ���*1G�+�d�∀�1G��∃�1D��9� ���*1G�+�Z� ���*1D�+�

�� ������ /D� �� /G� ���� ������������� ����#�������� ��� ���� ��� ������� ��������� ��� ��� ��� �� ��� ���� ���� ���� �������� *���� ����� ���� ���������� ���������� � ��� ������� ����#�����������������#�+�������������� ������� ����� ��� ����������� �������*�����������������������������+��

> ��#�����$� &�� ��� �� � ����� �� ���� ���������� �� ������� ��� � � �������(������ ����������������� ����� ������� � ����������� ��#�������������

&�� ��� ��� ��� �� ��� ���� ���� �� ��� �� ���������� ��� ������� ������ ��� ������� �� ���� �� ������ ��� ���� �������� ������ ���� �� ���� ������ ������ ��� ��������� ���� ������������/D���/G�������������������������� ����������� ��������� ���� ���������� �������������������������

&���������������������������������� ��� ������������ �� ������������������������� ����������������������������� ���� ����� ��� ����������� ������8� ��� �� ������ ��� ��� ��� �� ��� ���� ���� ��� ������ ���� &�� ��� ������� ��������������������������� ������� �� �� ��"�.'>/�D$�

"�.'>/�*:�� ����:�������� � ��.���������+����"�.'>/D�

12'>/�

:�� ��� :�������� � � .����������

��������A�� :�������������� /����������.����&�������,�� "��)���� 2�-����������&�� .�������� -��������=����

�+$9�)��

:�� ��� :�������� � � >�����(������

������-�� :�������������� "/�.��������[������� :�������������� 2�:�[��

Page 83: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ��� (� ���� ��

������&�� .�������� -��������=�����

8���182�

��������� �� �������������D����G������������������� ���/D���/G����������������� ����� ��� ������������������ �������������������%�������������������� ������������������ �������������������(�������D������G�*���������������������� ������ �������������������� �������������+��

1���������������������������������� �������$�

12'>/� � "�.'>/�:�� ��� :�������� � � .���������� � :�� ��� :�������� � � .����������

��������,�� :�������������� /����������.��������

� ������-�� :�������������� "/�.��������

&�������,�� "��)���� 2�-���� � [������ :�������������� 2�:�[��������&�� .�������� -�����������

��=����� ������&�� .�������� -����������� ��

=����

12'>/�2�"�.'>/�

:�� ��� :�������� � � .������������������,�� :�������������� /����������.��������&�������,�� "��)���� 2�-����������&�� .�������� -����������� ��=����������-�� :�������������� "/�.��������[������ :�������������� 2�:�[��

,����������$� &���� �� ���������� �D� �� �G� ���� ������� /D� �� /G�������� ������������� ���� ��� ����� �����$�

/D�2�/G�

���������������������������/�*/�����������/D�����/G���������� ���������#������+��������%��������$�

�c�Z�T����9����∈��D�∨����∈��G�U�

�����������*�5�+�

��� ���������� �� �������������D����G������������������� ���/D���/G��� ����� ��������� ����� �� � ��� ��� ����� ������� �� ��������� �� ������%������� ����� �������� ��������� ��������� �� �����������������(������ �D������������G��

1� ������������� �� ������� ��� �������� �� ���������� ������ ��� ����������12'>/���"�.'>/��

12'>/� � "�.'>/�:�� ��� :�������� � � .���������� � :�� ��� :�������� � � .����������

��������,�� :�������������� /����������.�������� � ������-�� :�������������� "/�.��������&�������,�� "��)���� 2�-���� � [������ :�������������� 2�:�[��������&�� .�������� -����������� ��=���� � ������&�� .�������� -����������� ��=����

Page 84: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ��� *� ���� ��

12'>/�5�"�.'>/�

:�� ��� :�������� � � .������������������,�� :�������������� /����������.��������&�������,�� "��)���� 2�-����

,����������$�&���� �� ����������������� ���������������/D���/G�� ��� ���������� ���� �� ����� �����$�

/D�5�/G�

���������������������������/�*/�����������/D�����/G���������� ���������#������+��������%���������

�c�Z�T����9����∈��D�∧����∉��G�U�

*���� ��� ����������������#����102��

"����� �����������������������(� �� �� ������������ ����� ����� � ���D����G���������������� ����� ��� ��� ��������� �� ������� ���� ���� ��������������������%�������������������� ����������D�%��G������������ ������������ ���� �������� �� ��� �������� ��������� ���� �� �� ���� �� ��� ������ �� ��� ���� ��*� ��#����������!�������%����������� ����������������������� ��������������+��

1� ������������� �������� ��� �������� �� ��� ����� ���������� ��������(� ���������������������&>�.>����.;/>��

&>�.>� � �.;/>�&������ ;������ +��� ��� � ������ /����� ����������

D� "�����=�������� <����#�����G6� � �;�&����� ��������A�� 1 ����G� =������3���!�� -�<��������6N� � ;��� ������� ������&�� ������ � � � &?��&��� �� � ��������A�� 1 ����

.�&$��0��$3)��

&������ ;������ +��� ��� ������ /����� ����������D� "�����=�������� <����#�����G6� �;�&����� ��������A�� 1 ����D� "�����=�������� <����#�����G6� ;��� ������� ������&�� �����D� "�����=�������� <����#�����G6� &?��&��� �� � ��������A�� 1 ����G� =������3���!�� -�<��������6N� �;�&����� ��������A�� 1 ����G� =������3���!�� -�<��������6N� ;��� ������� ������&�� �����G� =������3���!�� -�<��������6N� &?��&��� �� � ��������A�� 1 ����

,����������$�&������������������D����G������������/D���/G������� ����� ���� �� ����� ������/D�%�/G����������������� ����� ���D�I��G�������������/����������� ����������D�I��G����� ���$�1D�2�1G��

Operadores Derivados

��� ����� ���� ���#� �� �� ��� ��� �%������ ������� ��� �������� �� �������� ���� �������#��� ����� �� ����� ������� �� ����� �� ���� �� ����������� ������������

,����������$�&������������������D����G������������/D���/G������� ����� ���� �� ����� ������/D�%�/G����������������� ����� ���D�I��G�������������/����������� ����������D�I��G����� ���$�1D�2�1G��

Page 85: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ��� 0� ���� ��

Operadores Derivados

��� ����� ���� ���#� �� �� ��� ��� �%������ ������� ��� �������� �� �������� ���� �������#��� ����� �� ����� ������� �� ����� �� ���� �� ����������� ������������

&����� ���

������ ��������� ����� ���������� �� ������������������������������������ ������ ����� ��������������������������������� �������� ���������� ����������� �� ��� ��������� ��� ����� ����� ��� �� �� ����� ��� �������� ������ ��������������� ��� ��� ������ ��������� ��� ��� ������ �������� �� �%������ ������ �������� �� ������������

/D*1DD��1DG�������1D��+���/G*1GD��1GG�������1G�G+���/D����/G�

��� ������

��� ��� ������ �� ��� ��������� ��� ��� ������� ��������� ���� ������ �� �� ������ ����1D�� ��1G����� ������ ��������������������������� ����� ��������������� �������������� ��� ���������������

1D��θ�1G��

"����� ����������������������� ������ ���� ��� �� ������ �� �� ����� ���� ������ ������ �������������� ��� ��������E[F$�

1D�D�θ�1G�D�[�1D�G�θ�1G�G������

-�������������� ������������������� �������������������� � ���� ��������������� ��� ��� ������ �� ��� �������� �� �������� �� ��� ���� �� ��������9F�!� �<� �� ����%������$�F���

,����������$������� �������� ����� ������������ ���������/D�*1D+���/G�*1G+��������� ������������F�!���� ����� �$�

/D��/G�

S�θ�D�

���������������� ����� ���D�I��G�������������/����������� ����������D�I��G����� ���$�

1��2�1G�

��������%��������c���� ����� ����� � �^Z��D�%��G��

��� ����� �� ��� �������� �������� * ����� ������ e+� �� ���� ��� ����������������� � � �� �������������� ��������������������������������� ����� ������ ��������� #������ ��� � �������� "� ��� ���� �� �����(� �� �� ��� �������� ��������������������������������� �����������1���������������������������������$�

12'>/� � � � �.;/>� � �;������ ;� ��������� $����� ��� � ������ /����� ����������

��������A�� :�������������� /����������.���� � �;�&����� ��������A�� 1 ����&�������,�� "��)���� 2�-���� � ;��� ������� ������&�� �����������&�� .�������� -����������� ��=���� � &?�� ��������A�� 1 ����

Page 86: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ��� �� ���� ��

&��� �� �

/89�)�L��$3)��

*12'>/���� ���Z��.;/>������+�

;������ ;� ��������� $����� ��� ������ ������������������A�� :�������������� /����������.���� �;�&����� 1 ������������A�� :�������������� /����������.���� &?��&��� �� � 1 ����������&�� .�������� -����������� ��=���� ;��� ������� �����

���� ��������� ��������������������������� �������� �� ������������������������������� ������ ����� ����������

.�����������*∩+�

��� ������������ �� �� ���������� /D� �� /G� ������� ��� ��� �� ������� ���������������� ����� ��� ������������������ �������������������%�������������������� ������ ��� �����������������(�������� �� �����������1� ��������������������������������$�

12'>/� � � � "�.'>/� � �;������ ;� ��������� $����� ��� � ;������ ;� ��������� $����� �����������,�� :�������������� /����������.�������� � ������-�� :�������������� "/�.��������&�������,�� "��)���� 2�-���� � [������ :�������������� 2�:�[��������&�� .�������� -����������� ��=���� � ������&�� .�������� -����������� ��=����

/89�)�∩∩∩∩��+$9�)�

;������ ;� ��������� $����� ���������&�� .�������� -����������� ��=����

,�����������$�&���� ������������������� ��������������/D���/G�� ��������������� ���� ��� ����� �����$�/D�∩�/G�������������������������������/�*��������/D�����/G���������� ���������#������+��������%������$�

�c�Z�T����9����∈��D�d����∈��GU�

Operadores relacionales con valores nulos

������)���������������!��������������� ���#������������ �������� ������������������������������ ������������������� ������������� ����������

"����� ��������������������#�������� ������ ������������ ��#����������8���� ��������������� �#���#���������� ������ �������� ���������#�������������������������� ����������������������������������� �� ���#������������ ������������������(�� �� ��� ����������� � �� ��������� ������ ������ �� ������ �� ��� ������� ���������

<������������������� ������� �� ���������������� ����������������������������#������������

&����� ����0�����

"����� ��� ����� ���� ��������� ����� ��� ������������ �� #������ ������ ������ ��� ����������� �2������9�������<������ ���� �� ���� ������(���������� ���� �� �� ������� ��� ��� �������� ���� ����� #���� ��� ��� ��!���������������� ������� ��������������������!�����������������������������������

Page 87: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ����R�� �� � �� ���+ � ��������������S �� �' ������������ � � � � ��� 8� ���� ��

#��������� ������ ��������������������� ���������� ���12'>/����.;/>8���������������^&�������"��)�����2�-���Y� ��������������12'>/����������������������������������������������� ������������������������ ���������������.;/>���� ������������ �������������������

-�����#������������������ ���������������������������������������������� ����� ����� ������(���� ��� ��� ������ ��� �� ���� �������� ��� ����� ��� ����� �������� �%������ ���� ���������� ��� ������ ���� ������ ����� ���� ����������� #������ ������ � ������ ��� �!�� ����� ��� �������� ���������� ��� ������ �������������������������������������"���������� ������������������������ ��� ����� ���������%�������(����� ��9������������<����������� ��������� ����� ����������� ������� �����������������(����� ������ ������������ ����������� �� ���������������������������*����������������� ������9e+�

12'>/� � � � �.;/>� � �;������ ;� ��������� $����� ��� � ������ /����� ������������������A�� :�������������� /����������.���� � �;�&����� ��������A�� 1 ����&�������,�� "��)���� 2�-���� � ;��� ������� ������&�� �����������&�� .�������� -����������� ��=���� � &?��&��� �� � ��������A�� 1 ����

/89�)�L��$3)��

*12'>/���� ���Z��.;/>������+�

;������ ;� ��������� $����� ��� ������ ������������������A�� :�������������� /����������.���� �;�&����� 1 ������������A�� :�������������� /����������.���� &?��&��� �� � 1 ����&�������,�� "��)���� 2�-���� � �������&�� .�������� -����������� ��=���� ;��� ������� �����

Page 88: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ��� � ���� ��

*� � + � �

����� ������������ ������������� ��� ��

&?�� �� ��� ��������� �� ��������� �� �� ���� ���� �� �� ��� ��������� ��������� � ��� �����(��� ����� ���� ��� �� ��� �� ����� :�� ���� ����� ������� ��������������������� ��� �� ����������������#�� ��&?����� ������&?���������� ������ ����� ��� �� ��������������� ������������ � ������(���&?�������������� ������������������������ ��� �� �����������������

Historia

&?���������������������� �������� ��������� ��DPQH������������"�,����� ���������� �� E����������� ����� �� ����� ��� ��� �� �'����� ����� ���F�F� *"�� �� ���� �� ���� ������������ ����� ���� �� ����� �� ���� �������� �+�� .;=� �����(�� ����� ���� ������� �� ���� �� � ����� ���������� ��� ��������� ����(� �� �������� �������������� ���� ���� ����������� ���!����������&"?2"��*������������� ��'�G>��!�$�� �� �+�� &"?2"���� ��� �� �� ���#������ ���&?�� *&�������� �?����� ��������+����������������������� ���������������������� �����$�&"?2"���"��DPQP������ ������� �������������� �� �����������H���������������������������� ������������� ��������������� ���������� �� &?��� �����������H������ ��� ����������������,�������

������ �� GH� �)��� &?�� �� �#!�� �� *�� ��+� ��� �� ��� ��� ��� ������������ �� ������ �� ��� �� ���� ������������� "�� DPPG�� 1:&.� �� .&>�*������(������� ���� �� ��������� �� ��� ������ ��� ���� �� �� �� ����+�������������� ��� ���� ���(������ �� &?�� �� �� ������� ��� ��������� �� ��������� �������� � !���������� ������������������������������ ����� ����"���&?���� ��� �������� 1:&.5&?�� �� &?�PG�� ���� ��� !�� �� �� ��� ��� �� ����������������������������� ���1:&.����������� ���� ���������)� �����������������������&?���

SQL como lenguaje estructurado

"�� ����� � �&?����� ����� ��������� ������ ������� �!�� ������ ��������� ��������������� ��4f������������*���-����g+����������������� ���������������� ���� ������ �� ������������� �� ��� �� ���� ������������� ���� &?�� ����� ������������������ ���� �� ���� ���� ��� �� ��� ��� �� ����� ����� ��� ������� ��������������!����� �������������� ����������������

2��� ����� ������!�� �� �!�� ��� ��� ������ �������#��� "�� �������(� ������� �� �����&>���� �� �� �� ���������������������� ���� ��� ��� ������ ���������������������� ������������������ ��������������&?�������� ���������������������� ���� ���������������������������� ����� ��� �� ��������������� �������������&�� ��������&?������������� ������������ ����������������� �� ������ �� *������ ��+� � ������� ����� ��� � �� ���������� 2�� ��������� �������� �������������� ���� �������� ��$�:������%�:����������"���������������������������� ���������� ������������� ��&?���

Page 89: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ��� -� ���� ��

1��������� ������������������������ �������� ��������������� ���������������� ��������� ������� �� ��������� ������ *H5:+��� ��������� ������� �� ������������������*D5:+��1 ���&?�����������������������������������E�����F� ����� ������������������������������������������������ �(��������� ���

��������� ����!�� ���"�

��� ����� �� ���� ������ �� ���� >������ �� �������� ��� ��� �������������������

� ��� #������ ������������� #��� ������� �� ������ �������� �����$�h1�����������b�

� ���#������������������������������$�DG4�

� ���������#���������� ���������������������$�h 9��9����b�

� ���#������ ������������� ��������������� ��*���������#� ��g+�

���� ��������������� ����� � ��������������������� �� ����������� ������ �� �� ��������� "��� ����� �� ���� ������� ��� ������� �� #���������� �� ������������� ��������������� ��������������� �������������� ���������������������� ��������������!�� ������� �� ���� ��>������&?��

&����� 9���� .���� ���� )����

<1/��1/G*�+� <���� ��� �������� �� ������� � �%���� ��� ���������������� ��������"���%��������)���� V�HHH� ���� �� ��� �!����� �� D�� &�� � ����������������

D� ���VHHH� �

:<1/��1/G*�+� <���� ��� �������� �� ������� � �%���� ������������� �� ���� ��� ��������� �� ��� ��� ���� ��� �� �������������� �������������� ������������ ����������� "�� �%���� ����)����� ��������� �� ���� ��� ������� �������������� ����������� ������������������� ������������������!������������� ��V�HHH� �����&�� � ����������������

D� ���VHHH� �

�>:3� �������� ��������� �#���� ��������G�3 � D� ���G�3 �

��1/*�+� ����� �������� �� ������� � ����� ��� �������������� �� ��� ��� "�� �%���� ����)�� ��G�HHH� �����"���!���������)�������� ���������D��

D� ���GHHH� �

:��1/*�+� ������������� ��������� ��������������������� ���������������� �������� ���� ��� �� ������ ������ ��� ��������� �� ��������������������� "�� �%���� ����)�� ��� �������� �� ���� ��� ������� �� ����������� ������������������� ������������������!������������� ��G�HHH� �����"���!���������)�������� ���������D�����������D� ����� ���� ��� �� ������������ �������������

D� ���GHHH� �

��>;� 2�� � ����� �������� ������ ��������� ������������ ������ ��� ����� ��������� ������������ �� ������ ����� �� ������ #���� ������ ������ ���� �� �� ��� �� ��� ��������� �� ���������� �� ��� �� ���� ��1/�� "������)���%������V�3 ��

D� ���V�3 �

�� ����

:��>;� 2�� � ����� �������� ������ ��������� ������������ ��������� ��� ����� ��������� ������������ �� ������ ����� �� ������ #���� ������ ������ ���� �� �� ��� �� ��� ���������

D� ���V�3 �

Page 90: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���-� � ���� ��

�� ���������� �� ��� �� ���� :��1/�� "������)�� �%���� �� V� 3 �� 1����������������� �� ���� �����������������������

:�������� :2=;"/*��+� :������ ���� ��������� �� �� ������ � *������� �� !���������� ������� ��������� ������+��"�������� �� �� ��� ������ D� �� 4C�� ��� ������ ����� ��#������ � ��5CV���DGQ�

�1'"� ,����� ���� ������ #�� �� � �� A������� D��VQDG�;������������ ���4D��PPPP�1���

'.="&'1=-*��+� 1)������� !����������������� ���<������ ���������� �������� ���������������� �� !������������������������������ ��������������5�����&"�>:���

.:'"/<1��["1/*�+� '>�=>:'��

-���� �� �� ������� ��� �)�� �� ���� ������������� �� *��� �� #������ �� H� �� P� �� ���� ���������G+��

,����9�����

.:"/<1���1[*�+� '>�=>:'��

-���� �� ������������ !���������������������� �����������������*��� ��#������ ��H���P������� ���������G+��

/1W*�+� ����� ������� ����� ��������� ���� ���������������� �� ��� ��� "�� ����)�� �%���� ��G�HHH� �����

D� ���GHHH� �

�>:3�/1W� ����� ������� ����� �� ������� � ��� ���������G�3 ��

D� ���G�3 ��

;�>;� 2�� � ����� ������� ������� "�� ����)�� �%������V�3 ��

D� ���V�3 ��

;�������

;,.�"� ������������������(� ��� ������������� ��������������������� �������� ����� ��� �� �����-�� ������ ���� ������ .9>� ����� �%����������� �� ��� ��� ��� �� ���� ��#� ����� "������)���%������V�3 ��

D� ���V�3 ��

/>W.�� �� ���� ��%� ������� ���������� �� ��� ������ ��������� ������������������ ���

�,����

2/>W.�M*�+O� �� ���� ��%� ������� ���������� �� ��� ��������� ������� �� ���� ����� ��� ���� �� ���������(� �� ���� !� ����� "�� ����)�� �%�������� �������*�+���V�HHH� �����

��� ������������&?�����>����������������� �� ������� ��������(��� ����� �� ����1:&.5&?���>������������������������ �� ����������������� �� ��������������� �����#��������������� ���������� �����������$�

9������������/;.$:.7�� 9��������������� �����1/1�'"/*�+���1/*�+�

��1/*�+�

��1/1�'"/�<1/[.:3*�+���1/�<1/[.:3*�+� <1/��1/*�+�

:1'.>:1����1/1�'"/*�+�:1'.>:1����1/*�+�:��1/*�+�

:��1/*�+�

:1'.>:1����1/1�'"/�<1/[.:3*�+�:1'.>:1����1/�<1/[.:3*�+�:��1/�<1/[.:3*�+�

:<1/��1/G*�+�

:2="/.�*��+��"�.=1�*��+�

:2=;"/*��+�

Page 91: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���-$ � ���� ��

.:'"3"/�

.:'�&=1��.:'�

:2;"/*4C+�

,�>1'* +��>2;�"�-/"�.&.>:�/"1��

:2=;"/�

��������� ����!��� �"�

��� ����� �� ���� ������ �� ���� =�&?�� �� �������� ��� ��� �������������������

� ��� #������ ������������� #��� ������� �� ������ �������� �����$�h1�����������b�

� ���#������������������������������$�DG4�

� ���������#���������� ���������������������$�E����5��5 F�

� ���#������ ������������� ��������������� ��*���������#� ��g+�

1� ������������� �� �������� ���� �� ��� ���� ��� ����� �� ���� � ���� �� ���&?�������=�&?���-������ ��������������������������������� ���������� ����������#����� ��� �������� ��� "������������� �� ���� ����%���� �������� �� #�����(������*����������������D���G66+������������������ �������������� �� !������������������������ ������������������������������������������������������ ����������������������������

&����� 9���� .���� ���� )���� ,�������������

:�������� '.:[.:'M*�+O� "���������������)�� 5DGC���DGQ� :2�����H�� &=1��.:'M*�+O� "�����������)�� 54GQNC���4GQNQ� :2�����H�� ="�.2=.:'M*�+O� "�������� ��� 5C4CCNHC���C4CCNHQ� :2�����H�

� .:'M*�+O� ��.:'"3"/M*�+O� "������������� 5GDVQVC4NVC� ��

GDVQVC4NVQ� :2�����H�

� ;.3.:'M*�+O� "���������� �� 5GN4���GN4�B�D� :2�����H�

� ,�>1'M*�� +O� :��������������� ����������������������������

MiD�DQ6VPV4"54C��i4�VHGCG4VN"54CO��

:2�����H�

� �>2;�"M*�� +O� ��/"1�M*�� +O�

:������ ���� �� ��� ���������������� � ������������

MiG�GG6HQ4"54HC��iD�QPQNP4D"54HCO��

:2�����H�

� �"�.=1�M*�� +O� ��:2="/.�M*�� +O�

:������ ��� ����� ����������������� ��������� ����

MiG�GG6HQ4"54HC��iD�QPQNP4D"54HCO�� :2�����H�

�� ���� ��1/*�+� �� ���� ��������� ������ D���G66� :2�����H�

� <1/��1/*�+� �� ���� �� ������� �#���� ���

H���G66� :2�����H�

� '.:[;�>;� -����)��#�����;�>;� H���G66� :2�����H�� ;�>;� <�����;�>;�������� H���N6646� :2�����H�� ="�.2=;�>;� <�����;�>;��� ��� H���GGV�5D� :2�����H�� �>:3;�>;� <�����;�>;����� �� H���G4G�5D� :2�����H�� '.:['"0'� -����)��#�����'"0'� H���G66� :2�����H�� '"0'� <�����'"0'�������� H���N6646� :2�����H�� ="�.2='"0'� <�����'"0'��� ��� H���GGV�5D� :2�����H�� �>:3'"0'� <�����'"0'����� �� H���G4G�5D� :2�����H�,����� �������

�1'"� ,����� ��� �������� 11115==5���

DHHH5HD5HD� �� PPP5DG54D�

:2��� ��HHHH5HH5HH�

� '.="� ����� ��� ����������$��$�

5C4C$6P$6P� ��C4C$6P$6P�

� �1'"'.="� ,����� �� ����� ��� ��������1111==����$��$�

DHHH5HD5HD� HH$HH$HH��� PPPP5DG54D�G4$6P$6P�

:2��� ��HHHH5HH5HH�HH$HH$HH�

� '.="&'1=-M*�+O� ,����� �� ����� ��� ��������1111==����$��$�

DPQHHDHDHHHHHH� ������� ����)��GH4Q� :2���

� ["1/� 1)�������������1111� DPHH���GD66� :2�����HHHH�

Page 92: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���-�� ���� ��

���� ������� ��

[�� ����� #���� �������������� ���� ����� �� ���� �� ��� ��� �����(��� ���>��������=�&?���[����������������� ������� ��������������������������!������������� ���� ���������������������������������� �����������(�����

�������� ��������� ��� �#� ������ ����������$�

� 1���������$������(���#���������������

� ������� *�� �������� �� �� �����������+$� �����(��� #������ �������� ����������

� �������������$������������� ���� �������������

Operadores aritméticos

/�����������#��������������

��������� .���� ���� ��������I� >������������� D�I�G�5� >�������������� D�B�G�e� >������������������������ D�e�G�9� >���� ��� �#����� D�9�G�

Operadores lógicos

/�����������#������������*#�� � ����������+�

.%������ .���� ���� ��������Z� .���� � � D�Z�G�jZ�^Y�dZ� ������� � � D�jZ�G�D�^Y�G�D�dZ�G�Y� =��������� D�Y�G�^� =��������� D�^�G�YZ� =����������������� D�YZ�G�^Z� =����������������� D�^Z�G�.:�*/&+� .���������������������� ���

����������D�.:�*D�G+�M'/2"O�

^���Y� 1:[� ^���Y� &>="�*����>�����+�

^��Y� �� ������ ��������� ��� ������ ��� * ������+���� �� ��� ����� ����� � ������ Z��jZ��^��^Z��Y�� YZ������ ��� >/� ������� �������� ���������������

DH� YZ� 1:[� *D�G�4�DH+�M'/2"O�

^���Y�1��� ^��Y� �� �� �� ������������ ��� ������ ���* ������+�� �� �� ��� ���������� � �� ���� Z�� jZ�� ^��^Z�� Y�� YZ� ����� ��� 1:��������� ������ �� �� �������������

DH� ^Z� 1��� *D�G�4�DH+�M'/2"O�

;""'W"":�%�1:���� >����� �� �� ��� �(����� ��������%������"���#������������YZ�%�1:�����^Z���

DH�;"'W"":�D�1:��DHH�

"0.&'&� ^� �������Y�*����>�����+�

&�� ��� ^� �������Y��������������������������

"0.&'&*� &"�"�'� D� ,/>=��21�+��

Page 93: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���-(� ���� ��

�.X"� "������ h����b��.X"�h��kb�.&�:2��� &���������� D.&�:2���.&�:>'�:2��� &����:�������� D�.&�:>'�:2���:>'���� �� :����� ��� ��� ������

����������:>'� "0.&'&g� :>'�;"'W"":�:>'�.:�:>'�Z�

��� �1:����� � ����� ��� 1:�� ������� ������ ����� �������

DZD�1:��G�.&�:2���

��� �>/���� � ����� ��� >/� ������� ������ ����� �������

DZD�>/�G�.&�:2���

"������� ����.X"���#������������������ � ���������� ��������������e���l� ��=&5�>&��"%��������������������� ���$�

k$���������� ��:�����������* ��H���∞+��"��=�&?����� �������������e�

@$�2��������������

"������$�

��������������� ����������������'/2"�

h�������� ���.X"�h@��k��k @b�

h����b��.X"�h���kb�*�� ����������������������h���b+�

h������b��.X"�h���kb�

h������b��.X"�h��k��b�*�� ����������������������h��b����������������h��b+�

h�� ����b��.X"�h��k��b�

Operador de concatenación

/�������������� ���� ������������*����>�����+��

.%������ .���� ���� ��������mm� ���������������� ����������� h����b�mm�h����b�MbA�������bO�

>������ ��� �� ������ ���� ���#������ ���������� ���� �� �� �������� ��������� �������#��������������$�

DH�mm�GH�Z�hDHGHb�

"��� ������� �� �������� �1&'.:3��� �� ��� �� �������� ��� �� �� ������������ ������� �� �����(�� #������ ��������� ��� ������ �� #������ ������������� ���������#���#�����

La ausencia de valor: NULL

'� ��#����� *��� ��� �����������+���� ��������������#�����:2������������������ ��� �������� �� #������ 1!����� ���������� �������� *:2=;"/�� <1/��1/G���1'"g+� ��� �� ����� �� :2���� 2��� ���������� �������� :2��� �� ����������� �� ��������� ����:2����-���������� ���������#�������:2����������(���������� ���.&�:2�����.&�:>'�:2����

Page 94: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���-*� ���� ��

������� ���������

"���=��*�����=��������������������+��������������� ������������������������� ���� ��������������������� �� ���� ������ ��������� ���"���=�������� ������������������)�� ������ ��&?���������� ����� ������������ ������� ��������������� �� ������� ���� ������� �� �������� � ���� ;��������� ������ �����������������$�&"�"�'��.:&"/'���"�"'"��2-�1'"��

-���� ��� �������� ���� #��� �� �������� ��� ��� �� ��� ��������� ���������#�������������������� ��$�

9����� � �����M;������ +�� $������� � ��� +����1DDD� D� 6H� D69DG9GHH4� H�1DDG� 4� DG6� DQ9DG9GHH4� H�1DD4� 6� GHH� DQ9DG9GHH4� H�1DDV� 6� Q6� DC9DG9GHH4� D�1DD6� D� DHH� DP9DG9GHH4� G�1DDN� Q� DVH� GH9DG9GHH4� D�6�1DDQ� 4� DG6� GD9DG9GHH4� H�1DDC� G� D6H� GD9DG9GHH4� 4�1DDP� P� GHH� GG9DG9GHH4� H�

9�����&������M+�� ;������ /��������� +��� ��� *���� ��� &*�

D� A��� 3���(�����(� �9�=������D� ��� � �� DVHHG�G� A���� =���!��(�&���(��� 1#��-���DH� A���� G4HH4�4� A�#���� 1�����:����� -(��=�������DG� &�#����� VDHHG�6� 1������� ��������;����� �9�,��������C� � �(� DDHHV�Q� 1���� �� ;������&������ 1#��A����00...��G� ����#�� GDHHV�P� =����� ������>� -(��=��������D� 3���� �� DCHHQ�

La sentencia SELECT

��� ��������� &"�"�'� �� ��� ������� �� �� ��� ������������� *��������+� �� ����� ���� ���������� ����� �� ��� ������� ����������� �� �� ��������� 2��� ���������&"�"�'� �������� ��� ������ ��� *��������� �� ������ �+�� ���� ��� ���� �� �� ��������� ��������������������� �� �����������������������

�������%�� �����$�

SELECT ítems de selección FROM tablas WHERE condición GROUP BY agrupación HAVING condición agrupada ORDER BY ordenación;

'� ��������������������������%������&"�"�'���,/>=��1��������������#���������������� ���������� ��#�� ���� ��������$�

.���&9$��� � ����� ��������!���� ����������������� ������������������ ������ ������ �������!���� ����������� � ����������������� �����������

Page 95: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���-0� ���� ��

*E�F+���� ��!���� ������������������������������������ �� ������ ������������������ ��� ���(����� ���� ��������2��!���� �������������� ����$�

• 2�� ��� ��� �� ��������� � ��������� �� ���� �������� �� ��� �� ��� ����� �� ��� ��� ������� ,/>=�� ���� �� ��� ��� ��� �� ���������������������!���� ������������&?���������������������#����� ������������� ���� ������� ������� ��� �� ��� �� ���������������������� ����� �������� ������ �� ��� ������ �� �� ��� ���������>������������� ��� �� ��� ��������� �� ���� ��� ��� ��� �� �� �� ��������(�� ���������%�$�'1;�1��>�2=:1�

• 2��� ���������� ���������� �� ���� ��� ����� #����� ��������� #�� ���������������� ���������� ����������� �� ��������������

• 2��� �%������� &?��� �� ���� �� ���� &?�� � �� ��������� ��� #����� ���������� ��� ��� ������ ��� ��� �%������� �� �� ����� ��������� ��������������� ��� ��������������������&?���

)�'$����� ������������������ ���� ���� �������� �������������� ����������� ��� �� �� ��� � ��������� ���� �� ������� ��������� ���� �� ���������� ���� ������������ "��� �� ��� �� ��������� ������� ������� �� ��� ��������� ��� ������������������������� ���� ����� ����������������������������� �������� ��� � ����%�������������%����������������������!������������

"�������� �� ��������������&?����������������� ��� �� ��������������������� ��� ����� ��� �� �����&�������� ���������������&"�"�'������(�� ��&?�����������#������������ �� ��� ��� �� ����#�����(������������ �� �� �������������� ������ �� ����� � ��� ��� ��������� ��� ������� ���� &�� ��� ��������� ��#!�� ������������ ��� ������ �� ��� ��� �� ���� �����(�� �� &?�� �������� ��� ��� �� ��� �������� �� �� ��� �������� �� �#���#�� ��� ���������� "�� ���������� ����� ��������� ���������������������������������� ����� ������9����������������� ���������#�� �� ��� ��� �� ����� 3������������ ��� ������ �� �� ��� ���������������������� �������#���������������#�����������

Consultas sencillas

��� ��������&?���� �������� ��������� �������� �� ���� �������������� ��������� ��� �� �����-�����������

SELECT dni, nombre, dirección FROM Cliente

Columnas calculadas

����� �� �� ���� ��������������� � ��� �� ��� �������� ����� #���������#������ ������������ �� ��� ��� �� ����� ���� �������� &?�� ��� �� ��������������������������������#�������������������������� �� ���#������ ����� ������������ �������������9�����������&?���-�������������������������������� ����� ���������� ���� �%������� &?�� ��� ��� ����� �� ���������� -���� ��������� ����%��������&?������� ��������(����������� ����#�����������������������������������#�������������������-�����������

SELECT numero, importe, importe – (importe * dto) FROM Factura;

/��������� ��� ������� �� ��������� �� �������� �� ��� ������ �� �� ������ ������������������������� ��� ���������"����������� ����������������������������������������� �����#������ �� ���� ���� ��������

Page 96: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���-�� ���� ��

-�������������������������������$�

SELECT numero, MONTH(fecha), YEAR(fecha) FROM Factura;

���������!��������� ������������������������������ ������ ����������������)���

Selección de todas las columnas (Select *)

1�#���������#��������#�����(������������� �� ���� ������������� �������� ����&?���������������(��������������*e+���������� �� ��� ����� ����������������� ��#������� ���� ��������������"�������� �������� ���� �������������������������� �������������� ����� ���������� ����-�����������������������

SELECT * FROM Cliente;

���������!������������� ���� ������������� ������� ������������'�� �������� ������������������ ������������������������ ��� ������� ����

SELECT Cliente.* FROM Cliente;

1 ��� �������������������������!���� ������������� ������� ������� ���)� ������!���� ������������-����������$�

SELECT *, dni FROM Cliente;

���������!�� �� �� ��� �������� �� ��� �� ��� �������� �� ��� �������� ��� �� ���������� ����

Filas duplicadas

&�� ���� �������� �������� ���� ���#�� ��������� �� ���� �� ��� ��� �� ����� ������������ �������� �� �� ����� �� ������ �� ���������� &�� ��� �� �������� ��� ���#����������������������� ����� ������ ����������� ������ ���-�����������

SELECT dni FROM Factura;

-�� �����������

1 3 5 5 1 7 3 2 9

1������������� ������ ��������������������������#��������������&����� ������������ ��� ����� ������ �� �� ��������� �� �� ����������� ������� �� ������� ������#��+$.9$;&9����������������&"�"�'����������� ���������� ������������1!�

SELECT DISTINCT dni FROM Factura;

/��������*�������� ����������������+�

1 3

Page 97: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���-8� ���� ��

5 7 2 9

&���������(�������������.&'.:�'����������������������� ����������� �� ������� ���� ��������#��������� �� �� �� �������-��� ��������� �� �� ��� ����������������������)� ����������������������

SELECT DISTINCT dni, importe FROM Factura;

"�������� ����$�

1 50 3 125 5 200 5 75 1 100 7 140 3 125 2 150 9 200

����� �� ��� �� � ��#���� ��� ���� �� ����� �������� '�� ���� �� ��� �������������������� ������#��1���������� ������%��!���������������������� ������ ������������������������������������������������������������������ ��������

Selección de fila. Cláusula WHERE

3�������������� ���������������������� ���������� �������� ������������ ��������� ��� ����� ��� ��� ������ ��� ��� ������� W�"/"� �� ������� ���������������� ���� ��� ������� � ��� ��������� ����� ���� ���� ����� ������ ������ ��������� �� ������� ��� -���� ��������� ��� ��� ������� �� �� ��� �����(��� �� �� �������� �����������#�������������������"���� ��������������� ��������������������� �� ��������� ��������������� ���#�� �� �������� ���� �������1:����>/��

-�������������������� ��������������������������������DHH�n��

SELECT * FROM Factura WHERE importe > 100;

&���������������������������������#�����:2���������������������������� �������%���������� ���������������������W�"/"����������� ������������������������������������������������������ �������� ���

&?�� ������� ��� ������� ��������� �� ��� ������� �� ���� ������ �������������������� ������ ����� ��������� �� ��������� ������ ���� ��� ��� �������W�"/"��1�����������������%����������� �����

Test de comparación (=, <>, <, <=, >, >=)

������ ������ �� ���� ���� �����������(� ����� ������������&?���� ������� ���������������"��������� ���������������&?�����������������������#������ �� �� �%�������� &�� ���� �� �� ����� �� ����� ��� �%�������� ��� ��� ��� ��������������������� ��� ������������������������������� �������%������������������� ���������� ��� ������������� �� ����� ���� ��� ����� ���� ���������������!������-�����������

Page 98: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���- � ���� ��

SELECT numero, dni FROM Factura WHERE importe > 100;

��������������/������������ ��������������������������������������DHH�n��-���������� ��������������

SELECT * FROM Factura WHERE dto = 0 OR importe < 200;

�������������������������������������H������������������������GHH��>���������������� ����������������������������������� ���

SELECT numero, importe – (importe * dto), fecha, MONTHNAME(fecha) FROM Factura WHERE importe – (importe * dto) < 150 AND MONTH(fecha) = 3;

"��������������������������������/����������������������������������'�������������� ������ ��������'�� ������������������������������������������D6H������ ��� �� ��� ���'�� �� 4�� ����� �� ��� �� � ��#���� ��� �� ��������� ���� ����������� ���� �����#������ ��� ��� ���� �� ������������ �����(���� ��� ��� ����� �������������

Test de rango: BETWEEN

&?������������������������ ��������� ����� ������ �� ���� ������������� �� ������� "��� ������� �� �� ��� #����� �� ���� �� ���������� ������ �� #��������������� ���.������������� �������%��������&?���������������%������� ��������� #����� �� ������ ���� ��� �%�������� ���� �� �� �������� ������� ��� �%�������������� �� ��������� ��� ������ �� ������ ���� ��� ����� �� ���� �� ��� �����%�������� � ������������� ����-�����������

SELECT numero, dni, importe, fecha FROM Factura WHERE fecha BETWEEN ‘01/01/2004’ AND ‘31/01/2004’;

�����������������������������������������������������������D� �������� ���GHHV������4D� �������� ���GHHV���� ������������������������ ������ �������� ���GHHV�������������������������!����������$�

SELECT numero, dni, importe, fecha FROM Factura WHERE fecha >= ‘01/01/2004’ AND fecha <= ‘31/01/2004’;

-���������� �#���#�������������������������� �������� ��������������������� �������� �%������� ����� ��� ;"'W"":� ��������� ������ ���� ��� �%����������� ����������%��������������� ���������������������������������%����������� ����������%�������������� ����������

Test de pertenencia a conjunto (IN)

>������� �������� ��������������� �������������������������*.:+��"%�����������#����� �� ���������� ���������� ����������� ��#������� ����#���-�����������

SELECT * FROM Factura WHERE dto IN (0, 1, 2);

Page 99: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���--� ���� ��

��� ��������� ��������� ����� �� �� ��� �������� ����� �������� �� H�� D� �� G��&��!������#���������

SELECT * FROM Factura WHERE dto = 0 OR dto = 1 OR dto = 2;

'�� ��������� �������� ����������#����� �� ������������� �������������� ���������� ��#������� ����#������������ ��������� ������#��:>'��-�����������

SELECT * FROM Factura WHERE dni NOT IN( 2, 3, 5 );

"�������������������#�����(��!���� ���������������������������G��4���6��

Test de correspondencia con patrón. LIKE

1������������� �� ���� #���� ������� �������� ��� ����� ��� �.X"�� 1����� ���#����������������������&"�"�'��&����� �������(���������� ������������������������� ���������� ��� ����� ��� �� �� ��� ������� �� �� ���� �������� �� ��%��� ���������� �������������������������������%���������������-������������������������������������������ ������������������������������ !���-�����������

SELECT * FROM Cliente WHERE nombre LIKE ‘J%’;

�#��#��!���� �� ������������������� ���������(������ hAb����� ����������������� ������ ����"�����������������������

SELECT * FROM Cliente WHERE poblacion LIKE ‘S%a’;

�#��#��!���� �������������������� ������������(������ h&b������ �����h�b��"�� ���� ������� ��������� �� �%������� ���� ������� ��� �� ���������� ���� !�������%������

'�� ����� �� ������� �� ���� ������ ��� �%������� �� ��%��� ��� �� ������ ���������������� ������������������� ���:>'����.X"��-�����������

SELECT * FROM Cliente WHERE nombre NOT LIKE ‘PE%’;

�����!���� ��������������������� ��������������������h-"b��

Test de valor nulo (IS NULL)

1�#����������������� ����%��!�������������#������:2������������� ������ �� ���� �������������� �������������&?����������������������������� ��#�����������"�������������������� ������������������ ����������������

SELECT * FROM Factura WHERE dto IS NULL;

������������� �� ������� ��#����������*.&�:>'�:2��+��������������������������������������#�����:2����-�����������

SELECT * FROM Cliente WHERE direccion IS NOT NULL;

Page 100: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � � � ���� ��

Ordenación de los resultados de una consulta. Cláusula ORDER BY

1�� ������ ���� ��� ����� �� ���� �� ��� ��� ��� ��� �� ���� ��� ����� �� ��������� �� �� ���� �������� ��� ���� ������� ��� ������� �� ��� ������������ &����� ���� �����&?�������� ������������� �� ���������������������� ������������>/�"/�;[����������������&"�"�'������������>/�"/�;[����� ��������������� ����������� ���� ���� ������������� ������������-�����������

SELECT * FROM Cliente ORDER BY apellidos, nombre;

����� ��� �������� �� ��� �� ���� ����������� ���� ������ �� �� ��� ���� ������������������������� ���� ��������*�������+��� ������#�� ���� ������������������ ���� ��� ����� *�����+� ��� �������#������� ���#�� �� �� �������� �������������(� �� ����� ��������� ���� �� �� ����� �� ������ �� ������� ��� �����#�����������������#����������2����(�� ������������>/�"/�;[������ �������������� �� �������� ��� ��������� ���� ����� �� ���� ����� �� �� ��� �� �� ����� ����������������������������������������������������������������� ������������

������� �� ���� ������� �� �� ��������� ���������� �%������� ���� ��� �����������������&"�"�'���� ��������� ������������������������������*������������� �������������������� �+���%�������������������&?����������������!������ �������������� �������������������������� ����������������������� ������������������������� ������ ���&"�"�'��������� ��������� ����������������

������ �� �� �� �������� �� �� �������� �� ��� �� �������� ���� �� ������� ��� ����#� �� /.&� �� +�.&�� ����� ������ �� ��������� 1&��� ����� ���"&��� ������-��� ���������������������� ��������1&���-�����������

SELECT * FROM Factura ORDER BY numero DESC, dni DESC, importe ASC

����� ��� �������� �� ��� �� ���� ������� ���� ���������� ��� ���� ������������������������ �����������

SELECT * FROM Factura ORDER BY 1, dni, 4;

������������������ ��� ������������*��������D� ��������� �+�����������������'��*��������V� ���������� �������� �+��

&������������� �������� �� ������������������(� ��������� ���������������������� ������� ��� ��� ������ ��� ��� �� �������� ���� �� ��� �� �������� ��� ������������������ �� �� ��������� "�� ���� ����� � �� ������������ ��� ������� ������������������� �������� �������������������������

SELECT numero, fecha, importe – (importe * dto) ORDER BY 3;

������� ����� � ��

2����������������� ���������(����������� �������������������������������������������������#������������������ ����������������������������������������� ������ ����� ��g���� �������� �!����� ��� ����� ������� ��� �������� ������������������������������� �����������������������

Page 101: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � $ � ���� ��

2��� �������� �� �������� &?�� ������� ���� �������� ������� �� ���� ��������������� �� ��� ���� ��� ������ ���� ���� �����(�� ��� ��������� -��� ��������� ����������� 1<3*+� ������� ���� �������� �� ���� �� �������� �� ����� ���� ��� ���!����������������������(������������� ����������1<3*+������������������#���������� ��� �� ���������� ������� ���,��������

SELECT AVG(importe), AVG(dto) FROM Factura;

��� �������� �������� ����� #������ �� ��� �������� ������ �� �������� ������� ����������� ������� ������#������ ������������������������������� ������������������� �������� �����������(������ ���� ������� ���,��������'�� �������#������ ������� ����� ����������%�������

SELECT AVG(importe – importe * dto) FROM Factura;

������������ ��������������� ����������$�

� ��� +�� ��� ���&2=*�#������+� /���������������1<3*�#������+� /������������ ��������������=10*�#������+� /�����������%�����=.:*�#������+� /�����������!������>2:'*#�����me�+� /������������������

'� ������������������������������������ ����� ����.&'.:�'� ������� ���������� ��#������������������������������ ���

Cálculo del total de una columna (SUM)

�����������&2=*+���������������� �������������� ��#������ �� �������� ���� ������������� � ������ �����������������"�������� ���� �������������������� ���� ���� �� ��� #������ �� ��� ��������� ����� ��� ������ �� ��� �� ������ ����������������������-������������#�������������������� ����������� ��������������

SELECT SUM(importe) FROM Factura

"�������������� ������������� ������� �������������������������������������������

Cálculo del promedio de una columna (AVG)

�����������1<3*+����������������� ��� �������������� ��#������ �� �����1�� ������ ���� ��� �������� &2=*+�� ��� ���� � ��� ������ ����� ���������� [�� ���� �����������1<3*+��������#������ ������������������������ �#� ���������������� ��#��������������� ����� ���������������� �� ���� ������������ �� ���#������ ���������������

Determinación de valores extremos

��� ��������� �� ��������=.:*+� ��=10*+� ���������� ��� #������������ �������� ����������������������#����������� ���� �� �������������� ������ ������������������� �����������9������"�������� �� �������������������������������� �� ����������� ���� ��������������-������������������������������������������ ��������������

Page 102: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � �� ���� ��

SELECT MIN(fecha) FROM Factura;

-����� ������������������������������� ���� ������������������

SELECT MAX(cp) FROM Cliente;

-����� ������������������%����������!���������� ��������������

SELECT MAX(importe), MIN(importe) FROM Factura;

Cuenta de valores de datos (COUNT)

����������� �����������>2:'*+������������������ ��#������ �� ������������ ��� ���� ��������� ��� ���� �� ��� �������� ��� ��� ��� �� ���������� ������ ����������� �>2:'*+� �#���#�� ������� ��� �������� �� ���� ����������� ��� ����� �� ���� ��������������-�����������

SELECT COUNT(dni) FROM Cliente;

��������������� ��N�������������N����������������� ������������

SELECT COUNT(importe) FROM Factura WHERE importe > 100;

"�� ������ �� ��� N�� ��� ���� ��� �� ��� ,������� ���� N� �������� ���� ������������������DHH�n��> ��#������������������>2:'*+�����������#������ ����� ������������������������������������������� ���������"����������������������������������������������� ������������ ��������������� �� ��� ���������>2:'*+�� "������������������� �!���� �����������������������!�

SELECT COUNT(nfactura) FROM Factura WHERE importe > 100;

�������������%���)���������������������������E��������������������� ���������F���E�������������������� ���������8������������������������������� �� �� E������� ������ �������F�� -��� ���� ��(���� &?�� ������� ���� �������� ���������� �������� �>2:'*e+� ?2"� �2":'1� ,.�1&� ":� �231/� �"� <1�>/"&� �"��1'>&��������!�������������������������������#�(�������������(��� ��� ���������>2:'*e+��

SELECT COUNT(*) FROM Factura WHERE importe > 100;

����������������� ��� ���������>2:'*+����������������������������� ��������������� ��#����������������#��������������������������#�������

Valores NULL y funciones de columna

��� ��������� �� ��������&2=*+�� 1<3*+��=.:*+��=10*+� �� �>2:'*+� ���������� ������ ������������������� ��#������ �� ������������������������ ��������������#���������������� ���o?������ ������������ �����#������ ���������������������#�����:2��l�"����� ���&?��1:&.9.&>������������������#������:2��� ����������������������� ������������������ ������������� ���������� �����������

Page 103: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � (� ���� ��

�������������������� ��������!�������%�������������#������ ������������������������������#�����:2�������������������������� ���

Eliminación de filas duplicadas (DISTINCT)

/���� ������������� �������������������� ������#���.&'.:�'����������(�� �� ��� ����� �� ��������� ����� ��������� ����� ������ �� �� ��� ������ �� �� ������������ '�� ���� �� ��� �� �� ��� �� &?������ �������� #������ ������ �� �� ������������ ����� �� ���������� ���� �������� �� ��������� -���� ��������� #������ ������ ��� ��� ���� ��� ���#�� �.&'.:�'� �� �������� ������� ��� ���������� �� ����������� �����������-�����������

SELECT COUNT( DISTINCT dni ) FROM Factura;

�#��#��� ��� #����� N�� ��� ���� ���� ��� �������� ��� ������ �� ��� ��� �� ���,��������"����� ����������������.&'.:�'����������������&2=*+���1<3*+�������������=.:*+���=10*+��������������������������� ������������ ���"���>2:'*+������ �� �����(��� ������� ���� �� ����������� ���� �������� ����� ����������� ��� ����� ��������(���������>2:'*e+������������������ �����������������������������

1 ���� ������� ��� ���#���.&'.:�'�������� �������������������� #�(�������� ��������� &�� �������� ��� ��� ���������� ������ �������� �� ��������� ��� ��� ����������������������������

������� �� ���� � ��

������������������ ��������������������������������������������� ����� ��������� ��� ����� �� �� ��� ���� ������ �� ��� �������� ��� ���� ������ ������������ �� �����1���������������� �������������������������������������������������� � �� ���#�������� �����(��� ��� ������ �� �� ��� �������� �� ��� ��#���E� �����F�� ��� ������� 3/>2-� ;[� �� ��� ��������� &"�"�'� ������������ ���������� � ��-�����������

SELECT dni, SUM(importe) FROM Factura GROUP BY dni;

"���������������������� ������������������������������������#����� �� ���� ���� �� ��� ��� ������� &"�"�'� ��� �� ��������� ��������� �� ������ ������������3/>2-�;[�������#���������������������&"�"�'��.&'.:�'���

&?�������������������������������$�

D� &?�� �#� �� ��� �������� ��� ������ �� ��������� ��� ������ ���� ����������� ���� ����������� ����������������������������#�����������������������

G� -����� ���������&?�������������#������� ��� �� �����������.=->/'"������ �� �� ��� ����� ��� ������� �� ������� ���� ������ ����� ������� �������� �����������������������#����� ��������������������������� ��������������

"�������� ������ �����������$�

dni sum(importe) --- ------------

Page 104: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � *� ���� ��

1 150 2 150 3 250 5 275 7 140 9 200

2��� �������� ���� �������� ��� ������� 3/>2-� ;[� �� �������� �������������� ��� �������������� ��� ���� �� ��� �� ��� ������� �� ��� ���� ���������� ������������������ �������� ��������������������� ��� ���������������3/>2-�;[��� ����������������� ��� � �������� �� ��� ��������� ������� ����� ��� ������� ����������������� �#� ����������������������

"������� ���������������� �$�

SELECT fecha, COUNT(*) FROM Factura GROUP BY fecha; SELECT dni, AVG( importe ) FROM Factura GROUP BY dni; SELECT dni, MIN( importe ) FROM Factura GROUP BY dni; SELECT dni, fecha, MAX( importe ) FROM Factura WHERE fecha > ‘15/12/2003’ GROUP BY dni, fecha;�

�������� ���������!������ ������ ��� ��������� �� ��������&?���� ��� �������3/>2-�;[������ �� ����������3/>2-�;[������������� ����������&?������ � �� �#� ��� ��� �������� ������ �� ��� ������ �� �������� ��� �������� �� ������������� ����������� ������������ ����� ����������� ������ �������� ���������"���� ����������� ��� ������ �� �� ��� �������� ��� ����� ������� �� �� ��������������� ���� �� ������������� ��� ������������������� ��� �������� ���������������������������������� ����� �������� ��������� ����������'����

��� �������� ������ �� ���� ������ �� ������� ������������ ��������������������������� ������������� � ��������������������#�� �� ����� ��� ����� �� ��� ��� ������� ,/>=� �� ��� ��������� :�� �� ��� ��� �������� ��� ����� �� ���������#����� �������%�������������� ���

'�� �������� ������������ � ��� ��� ���������������� ������������ ��� �������� �� ��������� �� ���� �������� ������ ��� '� �� ��� ��������� �� ��� ����� ����������� � ��� ������ ��������� #����� ���� �� �������� �� ������ ;���������� ����������������������������� �������������������������������� ����� ����$�

• 2�������������

• 2����������� ������������������ �������������#����������(�� ���������� ����������

• 2����������� ���������������������� ������������������������#���������� ���������� ����������

• 2����%����������������������� ��������� ����������������

Page 105: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � 0� ���� ��

"�� ��� ��������� ���� �������� ������ �� �������� ������� ���� �������� ��������������������������� ��������������� ����� ������������&������������������������� �� ��������� ��� �������� ��� �� �%������� �� ������������� �����(�� ��&"�"�'��.&'.:�'�����3/>2-�;[���

2�� #����� :2��� �������� ��� ��� ����� �������� ���� �� �������� ��� ������������ ��������������&����� #����� �� ������������� ������� ��� *������������� � ��!����������� ��� ����l�"�� ����������W�"/"������ ������������� ��#������:2��� ������������������� ����:2���*���'/2"+���� ��������� ��#������:2������������ �������������1������ �������������#�����������������:2��������(��!����&?�������������� ����������������������� �������������:2�����������������������

"�������� �������������� ���&?��1:&.9.&>����� �������� ��#������:2������ ������� �� ������� �� ��� ������� 3/>2-� ;[�� &�� �� ����� �������:2��� ��� ���������������� ���������������#������� ��������������������� ���������������� :2���� �� �������� ������ ��� ����� ������ �� ������ &��� �� ������ ���������������������� ��������������� ������ �����&3;���

Condiciones de búsqueda de grupos. Cláusula HAVING

1�� ������ ���� ��� ������� W�"/"� ��� �� ��� �����(� �� ����� ����������� �������(��� ����� �� �#� ����� ���� ����������� ��� ���� ��������� ��� ������� �1<.:3���� �� ��� �����(� �� ����� ����������� �� �����(��������� �� ������ "�� �������� �� �����������1<.:3��� ������� ��� �� ��� �������W�"/"�� �������� �� ��� ������� ������#�� �1<.:3� ���� �� �� ���� ��� ������ �� ���� ��� ��� ������� �1<.:3���������������������������� ������ �� ���� ��������������-�����������

SELECT dni, AVG(importe) FROM Factura GROUP BY dni HAVING SUM(importe) > 200;

"����������������������������������1<.:3������������������������������������� ��� ������ GHH� n�� ,����������� ��� ������� &"�"�'� �������� ��� ���������� ���������� ������ ������������������������������������� �� ��������������

>��������������!�$�

SELECT dni, fecha, SUM(importe – importe * dto ) FROM Factura GROUP BY dni, fecha HAVING COUNT(*) >= 2;

��� �������� ��������� ��������!�� �������� ��� ������ �� ��� �� ���'�� ����������� ��� �� ������ �� ������������������� �� ������ �� ��������� ������(�� ���������������������������>������������

SELECT dni, MIN(importe) FROM Factura GROUP BY dni HAVING MIN(importe) > 50;

"���������������������������������������� �����������������������!���������������6H��-������ ��������������������� ���������������������!������

��� ��������1<.:3� �� �����(�� ����� �������� �� �%������������ �� ����� �� ��������� �� ������������������������������� ������ �� ���� ���������������� � ����������� ����������������������� � ���������� ����������� �#� ������"������������

Page 106: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � �� ���� ��

�������������������������(��� ������ �������� ������ �� ���� �����������������1<.:3���� ����$�

• 2�������������

• 2����������� ������������������ �(������������#������������������������� ����������

• 2����������� ���������������������� ������������������������#������������ ���������� ����������

• 2����%������������������������ ��������� ����������������

"�� ��� ��������� ��� ��� ������ �� ���� �� �� ��� ������� �1<.:3� ��������������� ��� ����� ���� �������� �� ��������� &�� ��� ��� ��������� ��� ��� ������ �� ���� ���� �!���%���������������������W�"/"��������������������� �#� ������"���� ��������� �������������������� ������ �� ���� ������������������������W�"/"��������������1<.:3�������� �������������������� ��������$�

• ��� ������� W�"/"� �� ������� �� ����� �� �#� ������ ���� ��� ���� ����%��������������������� � ������������ ��������������� �#� ������

• ��� ������� �1<.:3� �� ������� �� ������ �� ������ ���� ��� ���� ����%���������������������� � ������ ������� ��� �������������� ��������

��� ��������1<.:3� �� �����(�� ���� ������� ����������� ���� ��� �������3/>2-�;[��������������%�� ��������������&"�"�'���������������&��������������1<.:3�����������������������3/>2-�;[��&?������ ����������������������� �������� �� ������ ����������������������"��������������������������� ���������� �� ��� ������� �1<.:3� �� �������� �� ��� ���� �� ������ ������ ����� ���������� �� ��������� ��� ������ �� �� �%���� �� �� ��� ������ ��� �� ����������������� �������� �����������"����� ��������������1<.:3�����������������������������3/>2-�;[�������������#�����������������

���������� ��

�����������!����� �� � ��������&?���������������(��� ��� ������ �� ������������������������� ��������2���� ���������������������������������� ������ ������������W�"/"����1<.:3� ����������������&?���������!������������

Listar el dni, nombre, apellidos y dirección de los clientes que tienen facturas con importe superior a 100 �.

.������������� ��� ��������� &"�"�'� �� ��� �������� ��������� ��!�� �����������$�

SELECT dni, nombre, apellidos, direccion FROM Cliente WHERE dni = ???;

���������� ��� ��#������������������������������������������� ������������������������������������*lll+��"��������������������������� �������� ����� �������� ���� ������� �������� ���� �������� �������� �� DHH� n�� ���� �� ��� ����� ������������������������������$�

SELECT DISTINCT dni FROM Factura WHERE importe > 100;

Page 107: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � 8� ���� ��

���������� ��� ��#������������������������ ��� �!����� �������� ������������������������������ ������������������������DHH�n��"��������������������� ������ ���� ����������� ��� ��� �� ��� �������� ���������� -���� ������ �� �� ����� �������� ��������������������$�

SELECT dni, nombre, apellidos, direccion FROM Cliente WHERE dni IN ( SELECT DISTINCT dni FROM Factura WHERE importe > 100 );

��� � �������� ��� ������� �� ������� ������ ���������� ����� ������ ����������� ������� �� ���� ��������� &"�"�'�� ���� ���� ������� ,/>=� �� �����������������W�"/"��3/>2-�;[����1<.:3��"���������� ���������������� �������������������������������������&"�"�'������������������������������������ ���������(��� ������ ������� ���������&����� ��������������������� ��������������������� �����������������������&"�"�'�������

• 2��� � �������� � �� ��� ����� ���� ������ �������� �� ���� ����������� ���"��������������������� ��������������������������������������� �����������������������&"�"�'��

• ����������>/�"/�;[������� �������������� ���������� ������������ ������ �� �� ��� � �������� �������(��� ����������������� ������ �� ��� �������� ���������� �� ������ ��� #�� ��� ��� �������� ���� ���������������������� ���� ������� ����������� ���

• 2���� �������������� ��������2:.>:� ��#��������������&"�"�'� ���������������������������������&"�"�'��

• ������ ��� �� ��������������������� ������� � �������� ��� ������������ �� �������� �� �� ��� ��� ��� �������� ����������� "���������������2��������� ���� �������������������

������� ���������� ������� �����������������������������������������������#����� �������������������������E������F� ���������������������������� ���������������������������

Listar el dni de cliente, número de factura, fecha e importe de las facturas cuyo importe supere el importe medio de las facturas del cliente. SELECT dni, numero, fecha, importe FROM Factura AS F1 WHERE importe > ( SELECT AVG(importe) FROM Factura AS F2 WHERE F2.dni = F1.dni );

"�������� ������ ����������� ����������������� ��� ������������� ��������������������������������!�������������������������������� ���%����� ������ ����������W�"/"� ������������������������&����� ��������� ��#������&:?��� ������������W�"/"�������������� �� ��� ��������������� ����������������������'�������� ����������������������������� ���� ������������ ����������������(�����������*,D���,G+������ ������������� �����������������������������������������������������������*&:?��+������� ������������������ ��������*&;?��+��"����� � � ���������� �������������������� ����������� ���� ��������������� ���������� ��� �����������,����������� ��!��������������������� �� �!��������������(��� ������ ��� �� �� �������������������� ��� ���� ������#��������������������������������� ��������

Page 108: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � � ���� ��

����� � � ��� ��� ������� W�"/"� �� ��� � �������� ��� �� ��������� �� ��� �������������-������������������������ ���� �����������$�

9������� ����M�� ��� )����� &������ ���������DD� 1� ������� ��� � �� 4HHHHH�GG� 1� ������� &�#����� 6Q6HHH�44� 1� ������� � �(� CHHHHH�VV� "%����� ���� ;� ���(� QHHHHH�

9�����)�����������M+�� ;������ �� ��>)��� &����� ,�����

D� A��� DD� 46HHHH� 4NQPDD�G� A���� GG� 4HHHHH� 4PGQG6�4� A�#���� DD� 46HHHH� VQVH6H�6� 1������� 44� GQ6HHH� GPPPDG�Q� 1���� �� GG� GHHHHH� DVG6PV�P� =����� 44� 4HHHHH� 4H6NQ4�

9�����*�������M;������ )��� &��� $������� � ��� +����1DDD� G� D� 6HH� D69DG9GHH4� H�1DDG� 6� 4� DG6H� DQ9DG9GHH4� H�1DD4� Q� 6� GHHH� DQ9DG9GHH4� H�1DDV� Q� 6� Q6H� DC9DG9GHH4� D�1DD6� 6� D� DHHH� DP9DG9GHH4� G�1DDN� 6� Q� DVHH� GH9DG9GHH4� D�6�1DDQ� G� 4� DG6H� GD9DG9GHH4� H�1DDC� 4� G� D6HH� GD9DG9GHH4� 4�1DDP� P� P� GHHH� GG9DG9GHH4� H�

&� ��������� ����� ���������������������������

Lista de las oficinas donde el objetivo de ventas de la oficina supera a la suma de las cuotas de los vendedores individuales SELECT ciudad FROM Oficinas WHERE objetivo > ( SELECT SUM(cuota) FROM Representante WHERE oficina_rep = oficina );

���������� ������������ ��� ���� ������������������ ��������� ������ �� ���������������� �� ������������ ��������������� ���������� ��� ���%����� ������ ����������W�"/"� ���������������������������� ��������������#������ ���%������ ����� ��� �� ��� /�������������-������� ��� �������W�"/"� �� ��� � �������� �� ���������������� �� ��� �������� ����� ���� ��� �%���� ��� ��� �� ��� /������������� "������������� ������� ���>������������������������ ���������������������������������&?������������ ������� ������� ���>�������������(�����#����� ������������������ ��������������������� �����#������ ������� ���������

Page 109: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � -� ���� ��

�����������#���%�������������� ���/�����������������(���������� ������������ ������� ��� ���#����������� �� ��� �� ���>�������������� ��� ����������� �����(����������������(��������������������������� ��� ���� ��� ���� �������

2���� �������� ������������ ������� ������ ��� ������ �� ���� ����� ����������W�"/"����1<.:3��1��������������� ���� ��������� ������� �� ���� ������������ ��� ��� ��� �����(� �� ��� ���� �������� 1 ���� &?�� ������� ����������������/�����������������������

Test de comparación de subconsulta (=, <>, <, <=, >, >=)

"�� ���� �� ������������ � �������� �� ���� ������ �� ����� �� ��� ���� �������������� ������� ���� � ����� �� ������� ��� ��� ��������� ��������� �������� ���#����� �������%��������������#�������� ��� ����������� ����������� �#���#����������� ��'/2"��� �������������������������"��������������(�������������������#����� �� ��� ��������� ������ ���%����� ���������#�������������� ��� ������ ����� ���������

Listar los representantes cuyas cuotas son iguales o superiores al objetivo de la oficina de venta de Córdoba SELECT * FROM Representante WHERE cuota >= ( SELECT objetivo FROM Oficinas WHERE ciudad = 'Córdoba');

���� ������������������������#���������� ����#�� ��#����� ������������� ����� � ���"��#������������(�����������������������������#�� � ���������������������������������������� ����#���

"�� ���� �� ������������ � �������� ������� �������� ��� ����� ���� ��������������*Z��^Y��^��^Z��Y��YZ+� ����� �������������� ������������������������� ����������������� ������������� � ����� �������������������� �������� ���&�� ��� � �������� ��� ������������� ������ ��� ������������ ��� ������ ���� ����� &?���������� ��������� ������ ���������&������ �������������� �������������� �������#�����:2����������� �������������� �#���#��:2����

Test de pertenencia a conjunto (IN)

"������ �������������������������� ��������*.:+��������������� ����� �� ��� ���� �� ������������ �� ��������� ������� �������� ��������� #����� �� ���� �������� �������� �� #������ ��� ��� �� ���� ���� � �������� �� �#���#�� ��� ������ ��'/2"������#����������� ���������� �����#������ ��������������"��������������(������ ������������������������#����� �������������������� ���%����� ������������������ �� #������ ��� ��� �� ���� ���� � ��������� ����� �� ������� ��� ������������

Lista los vendedores que trabajan en oficinas que superan su cuota SELECT * FROM Representante WHERE Oficina_rep IN (SELECT Oficina FROM Oficinas WHERE ventas > cuota );

Page 110: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ � � ���� ��

Lista los clientes que no tienen factura con importe superior a 100 �. SELECT * FROM Cliente WHERE dni NOT IN ( SELECT DISTINCT dni FROM Factura WHERE importe > 100 );

"�� �� �� ���� �� ���� ��������� ��� � �������� ��� ���� ���� �������� ��#�������������������W�"/"� ������������������������������ �������#����� ����������� ����������������������������� ���������� �����#����� ��������������"���������� ������ ������������������.:���������������������%������������������� �������.:���������%���������������������� ��#��������� ��� ����������� ����������������� ������%��!�������������������������������

Test de existencia (EXISTS)

"������ ���%��������*"0.&'&+�������� ��������� ����������� ���������������� �� ������ ���:�� ���� ���� �� ������������ ���������� ��������� ��� ���� ���%�������8�����������������(������� ���������-�����������

Listas los clientes que tienen al menos una factura con importe superior a 100 �. SELECT * FROM Cliente WHERE EXIST ( SELECT * FROM Factura WHERE Factura.dni = Cliente.dni AND importe > 100 );

�����������������&?������������� �������� ��������� �� ��� �� ��������������������� ������ ��������������� ��������������� ����������� �������������������� ��������� ��� ���� �� ���� �������� ���������� �������� ��� ��������������� ��������������������DHH�n��&������������� ���������������*�� ���������� ��������������� ������ ������ �+�� ��� ���� "0.&'&� �#���#�� '/2"�� &�� ��� � �������� ������ �����������������"0.&'&���,1�&"��"������"0.&'&������� ����� ��������#�����:2����

&����� ����#���������������� �������"0.&'&������(�� �����������:>'�"0.&'&��"�������������� ������'/2"��� ���� �������������� ������������,1�&"�������������������> ��#������ ��� ��� ������ �� ���� ��"0.&'&���������(�� ���������� ��������� �� �� ��� � ��������� &����������� ������� �� �� ��� � �������� ��� ���������������� ���

Test cuantificados (ANY y ALL)

���#������� �������� �������.:�������� �������#����� �� ��������������������#���������������� ����������� �� ������� ���������&?�������������� ������������������� 1:[� �� 1�������� �%���� ��� ���� ������� �� ����� ����� ���� ��������������� �������������������� *Y+������������� *^+��1� ������������������#����� �� ������������������� ��#��������� ��� ����������� ���������

"�� ���� 1:[� �� �����(�� �������������� ���� ���� �� ��� ��� ����� ���� ��������������&?��*Z��^Y��^��^Z��Y��YZ+������������������������#����� ���������������������� ��#��������� ��� ����������� ���������-���������������������&?�������(���������� ��� ����������������������� �������������������#����� ����������

Page 111: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ $ � ���� ��

�� ��#����� �� ������������������������� ��#�(��&��������� �������������������� �#� �������� �������������� ��'/2"���������1:[�� �#���#����������� ��'/2"��-�����������

Lista los Representantes que han hecho algún pedido cuyo importe supere el 10% de su cuota. SELECT * FROM Representante WHERE ( cuota * 0.1 ) > ANY ( SELECT importe FROM Pedidos WHERE rep = dni );

����������������������%�������� ������� ������� ���/�������������������������� � �������� ���������� �� �� ��� �� � �� ������ ���� ��� #�� � ��� ������� �� �#���#�������������������������������������� ������� � �������������W�"/"� ������������������������������������������ ��(������������ ����������� ���#�� � ���������� �� ��� �����(�� ����� #����� �� ����� ������� ���� ���� �� �� ��� �������� ���� � ����� ��� ���������� ���������&�������������������������%�� �����#����� ������ ������� ������ ����^�1:[� �#���#��'/2"��� ��� #�� � ������ �� ������ �� ��� ��������� �� ���������������

��� ���� ��� ���#�� &>="� �� ���� ���������#�� ����� 1:[� ��������� �� ���� ������ ���&?��1:&.9.&>������������� �� ��� ������ ������#����� ����������(� ����������������������������&3;�����������������

"������1������ �����������(����������������������� ������������� ���� �������������&?��*Z��^Y��^��^Z��Y��YZ+������������������������#����� ���������� ���� �������� �� #������ �� ���� ��� ��� �� ���� ���� � ��������� -���������������������&?�������(���������� ��� ����������������������� ������������������� #����� �� ���� ���� �� �� �� �� �� ���� �� ��� #������ �� ���� �� ��� ��������� &���� �� ��� ������������� �� �#� ����� ��� ����� ��� ������ �� '/2"�� ��� ���� 1��� �#���#����������� ��'/2"������������������� �#���#��,1�&"��-�����������

Listar las oficinas y sus objetivos donde todos los vendedores tienen ventas que superan el 50% del objetivo de la oficina SELECT oficina, ciudad, objetivo FROM Oficinas WHERE (0.5 * objetivo) < ALL ( SELECT ventas FROM Represenante WHERE oficina_Rep = oficina )

���������������������������������������%�������� ������� ������� ���>����������� �� ����� ��� � �������� ���������� �� �� ��� #�� � ���� ���� ��� ����� ��� �����������p������p��� �#���#������������������������������#������������� ���������� ��#�� � ��������������W�"/"� ������������������������������������������6Hk� ��� � ����#�� �� ��� �������� �� ��� �����(�� ����� #����� �� #����� ��� ��� �� ���� ���� ���������&�� �� �� ���#������ ��#������%�� ������#����� ��� ����������� ����������^�1��� �#���#��'/2"������������������������������������ �� ��������������&������������������������������������������ �� ��������������

Subconsultas anidadas

'� ������������� ����������������������������!��������� ���������� �� ����#����� ������� �������� ������������������ �� ���� � ������������������

Page 112: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ �� ���� ��

�� �� ��� �� ��� �� �����(��� ���� � �������� ������ �� ���� �������� ����������� ����� �������(�������� �������� ������ �������� ���������-�����������

Listar los pedidos cuyos representantes están asignados a oficinas de la región de Andalucía SELECT * FROM Pedidos WHERE rep IN ( SELECT dni FROM Representante WHERE oficina_rep IN ( SELECT oficina FROM Oficinas WHERE region = 'Andalucía' ) );

"�� ���� �������� ��� � �������� �� �������� ��� ���� ���� �������� ������������� ��� ������� �� �������� �� ��� �������� ��� ��� ������� 1� ����!��� ���� �������������������� ����������������������������������� �����#�� � �������� ��� ����� ��� ���� �� ��� �������� ��������� ��� ,����������� ��� �������� ���%������ ���������� ��� �������� ����� #�� � ���� ������� ���� �� ��� ������� �������� ����������� ���

���������������������(� ����������������� ��������#������� �������(��������� ��������� �������� ����������� ������#����� "�� ��� ��� &?��1:&.9.&>�������������� ��� ������� �%���� �� ��#���� �� ��� ������� ����� ��� ��� �������� �������������������������������������� ������������������������� ����#�������� �������� ��� ���� ������� ������ �� ��!���� �� ������ ������� ��� �� ������������� ������������� �������� ����#���� ��� ���������

Subconsultas en la cláusula HAVING

1������ ��� � �������� ������ ����������� � ��� �� �� ��� ��� �������W�"/"����� ������� ��������(������������������1<.:3� ������������������� ������ � �������� �������� ��� ��� ������� �1<.:3�� ��������� ����� ������ �� ������������ �������� �������������� �����������������1<.:3��-�����������

Listar los representantes cuyo tamaño de pedido medio es superior al tamaño de pedido medio global SELECT rep, AVG(importe) FROM Pedidos GROUP BY rep HAVING AVG(importe) > ( SELECT AVG(importe) FROM Pedidos );

��� � �������� �������� ��� ����)�� �� �� � �� �� ��� ��� ���� �� �� �� ����� � ������������������������ �������� ��� �� ���-� � ��������� ���� �� ����� � �������� ���� ���� �������������� ��� ������� �1<.:3� ������� �� �������� �� �������� ������������#������������)�� ���� � ���� ��� ��������������������������������� ���� ������� � ���������� ������������������&�����!����������� ��������������� �8���������������� ��������� ������ ���,���������� ����������&"�"�'���� �������������������������� ��������������� �������� ��� ���#�� � ������������)���� ��� ���� � ��������� �������

Page 113: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ (� ���� ��

������� ������� �� �

"�� ��� ��� ���� ����� �������� ��������� �� �� ��� ���� ���� ��������������� ��� ���� ���� �� ���� -���g� o�� �� ���� ������� �� ���� ����� �� �� �������� ��l� "� ��� ��� ������ �������� ���� ��������� �� �� ���� �� ��� ������ �� ����������,/>=����������������������������������������������������� ���������<��������������������������

SELECT numero, Factura.dni, Cliente.dni, nombre, importe FROM Factura, Cliente;

&������� ������������������������� ���$�

9����� � �����M;������ +�� $������� � ��� +����1DDD� D� 6H� D69DG9GHH4� H�1DDG� G� DG6� DQ9DG9GHH4� H�1DD4� 6� GHH� DQ9DG9GHH4� H�1DDV� 6� Q6� DC9DG9GHH4� D�1DD6� D� DHH� DP9DG9GHH4� G�

9�����&������M+�� ;������ /��������� +��� ��� *���� ��� &*�

D� A��� 3���(�����(� �9�=������D� ��� � �� DVHHG�G� A���� =���!��(�&���(��� 1#��-���DH� A���� G4HH4�6� 1������� ��������;����� �9�,��������C� � �(� DDHHV�

"��������������������������������������������������

;������ +�� +�� ;������ $�������/���� �� �� N���� 6F�1DDD� D� G� A���� 6H�1DDD� D� 6� 1������� 6H�1DDG� G� D� A��� DG6�/��!� !� !� N��� �!6�1DDG� G� 6� 1������� DG6�1DD4� 6� D� A��� GHH�1DD4� 6� G� A���� GHH�/��"� 6� 6� /����� !FF�1DDV� 6� D� A��� Q6�1DDV� 6� G� A���� Q6�/��5� 6� 6� /����� C6�1DD6� D� D� A��� DHH�1DD6� D� G� A���� DHH�/��6� �� 6� /����� �FF�

-� ���� #������� ��� ������ �� �� ��� ��� ����� ���������� �� ���� �� ��� ��������� �� ������ ������ �� �� ������ ������������ ��� �� ��� �� ���,1�'2/1����� ����� �����.":'"��-������������ � ��������������������������������������� �������������� ����� ���� ��� ���������� ��� �������� �� �� �� ��������� �� ������ ���� �� ���������� ���������� ���� �� �������� �������� ������ �� ��� �� ��� ��.":'"�� ��������������������������� ������������������ ������������������� ������������������������ ��������������������&������?���Z�������?������ ����� ��������� ������������������������������������������� ���

Page 114: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ *� ���� ��

"������� ��������� �������������������������������������������� ����������������������������&"�"�'������������������������� ���$�

SELECT numero, Factura.dni, Cliente.dni, nombre, importe FROM Factura, Cliente WHERE Factura.dni = Cliente.dni;

,!���� ���� ���� �� �� ������ �������� �� ��������� �� ���� ����� ���������������������� �������������������������������������� ��� ������� ������������������������"�������� ���������$�

;������ +�� +�� ;������ $�������1DDD� D� D� A��� 6H�1DDG� G� G� A���� DG6�1DD4� 6� 6� 1������� GHH�1DDV� 6� 6� 1������� Q6�1DD6� D� D� A��� DHH�

������������������� �� ��� �� ��������� ����� ��� ����� �� ���� �� ������������������������� �������������� � �������������#�� �������� �����������#���%������ �� ��� ������ ��� ��� ������� ������ ��� W�"/"����� ��#��� ����� ������ ������������������ ����� ���������N�$;�*�������������+��

Consultas multitabla con criterios de selección de fila

��� ��� ������ �� ���� ������ ���������� ��� �������� �� ������������������������������������� ������ ����� ������ ���� ����� ��� ������� �� ���� ��������������������������������� �� ����������� ���&��������������� �������������������������������������������� �����������������������������������������������DHH�n��

SELECT numero, Factura.dni, Cliente.dni, nombre, importe FROM Factura, Cliente WHERE Factura.dni = Cliente.dni AND importe > 100;

���� ��� ��� ������ �� ���� �� � ��������� ��� ����� ���� ��������� ��� ��������� �� ���� ������ �������� ��� "�� ������� ���� *&������?���=� ������?��+����������� ��������� ��� ����� �� �����&�������������������� ������� ��� � ���� ������������� ��9����8���� ���� ����������������� ������������������������������ ���������� �� ��������������������������� ���� ����#���

Múltiples columnas de emparejamiento

&��������� ���� �����������������������������

9���������*������M*������ M�%��� )���� ��� 8������� *�� ��� +���

9���������/������M/������ M�%��� )���� ��� 8������� *�� ��� +��� *������ ����*�

"�� ��� �� ��� �!���� �� 1� ���� ���� ���� ���#�� �%������ ����� �� ���� ���������� *������ �����+� ���� ����������� �� �!���� �� -� � ��� -���� ��������� ����� ��� �� ���������� ���������� � ����������������� ������� �� �������� �����������������������������������������������$�

Listar las líneas de albarán y las líneas de pedido para aquellas líneas donde unidades pedidas son superiores a 10.

Page 115: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ 0� ���� ��

SELECT LineaAlbaran.*, LineaPedido.* FROM LineaAlbaran, LineaPedido WHERE LineaAlbaran.pedido = LineaPedido.pedido AND LineaAlbaran.nlineap = LineaPedido.nlinea AND LineaPedido.unidades > 10;

������ ������ �� ���� ����� ����������� ������&?������ �������� �� �������������� �� ��� ��� �� ��� �����1� ����� �� �����-� � �� ��� �������� ��� ��� ������ ������� ���������������� �����������������������#�������

Consultas de tres o más tablas

&?�� ��� �� ��� ����� ���� �� ���� �� �� �� ��� �����(�� �� ��� ������������� ���� �����(� �� ����� ��� �������� �� �� �� ���� &��������� ���� �������� ����������� �����������$�

9���������*������M*������ M�%��� )���� ��� 8������� *�� ��� +���

9���������/������M/������ M�%��� )���� ��� 8������� *�� ��� +��� *������ ����*�9�����/������M;������ � ��� &������ ����>*���� � � � �

,��������������������������������

Listar el número de albaran, fecha, forma de pago, línea de albarán, referencia del artículo en el albarán, unidades vendidas en el albarán y unidades pedidas. SELECT numero, fecha, forma_pago, LineaAlbaran.linea, LineaAlbaran.referencia, LineaAlbaran.unidades, LineaPedido.unidades FROM Albaran, LineaAlbaran, LineaPedido WHERE Albaran.numero = LineaAlbaran.albaran AND LineaAlbaran.pedido = LineaPedido.pedido AND LineaAlbaran.lineap = LineaPedido.linea;

"�������������� �����#���%�������������� ��������1� ������������������������� �� ���� ���#�� �%������ ����� ��� �� ��� 1� ������ ���� ����(�� �� �� �!���� ���� ������������������ �������� ����� ��� �������������� ������ ��������������#�� �%������ �� ��� �� ��� �����-� � ��� ���� ����(�� �� �� ������ �� �� ���� ���� ���������� �������!���� ���� � ���

Join externo

"%����������������������� ������� ����������������� �� ��$���������������"��������� ������ �����#������ ���������������(� ������������ ������� ����������������#�����:2����1�������(������������������������������(� �������������� #����� :2���� ��� �������� ��� ��� ��������������� �%���� ��� ��� ���� ������� ������������������������� �����:2�������������#����������������

&������������� ��� �� ��������(� �� ��� �������� ���������������� ������������������� ���$�

9����� � �����M;������ +�� $������� � ��� +����

Page 116: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ �� ���� ��

1DDD� D� 6H� D69DG9GHH4� H�1DDG� :���� DG6� DQ9DG9GHH4� H�1DD4� D� GHH� DQ9DG9GHH4� H�1DDV� :���� Q6� DC9DG9GHH4� D�1DD6� Q� DHH� DP9DG9GHH4� G�

9�����&������M+�� ;������ /��������� +��� ��� *���� ��� &*�

D� A��� 3���(�����(� �9�=������D� ��� � �� DVHHG�G� A���� =���!��(�&���(��� 1#��-���DH� A���� G4HH4�6� 1������� ��������;����� �9�,��������C� � �(� DDHHV�

&�������(��������������������*������������������ ���������� ���������+����� ���������� ��� �������� E1DDGF� �� E1DDVF�� ��� ���� �� ������ ��� ��������� ���:2����������#������������ ������ �������*WHERE Factura.dni = Cliente.dni), ������#�����������#�� � �����

1 ���� �������� ��������� ��� �������� E1DD6F�� ������� ��� �������� EQF� ����%������� ��� �� ��� �� ���������&��� �� ��������� �� ����������������������������������������� ����� ��� �� ������� ���� ����������� ����������������%����������������������:2����

-��������� � ���������(�����������������*������%�����+�����������A>.:�������� ���� �� ���� �������� ���� ����� �������� �������� ���� �� �������� �����%�������� �� ������ ����� ��� �� �� ��� ����� ������ �� ��� ���� �������������������������������� �� ��������������%�������������� ��������%�����$�

• A�����%���������������5�>2'"/�A>.:��&���� ����������������� �� � ������������������������������� ������ ������������ ���� ���*������������+������������������ ������� ��������������� ����������������� � ����������������������� ���� ���������������������� ������� ��������� ���� ����������������� � ����������������������������� ����

• A�����%������ �(����� ��5��",'�A>.:��&�� �� ����������� ������ �� � ������������������������������� ������ ������������ ���� ���*������������+������������������ ������� ��������������� ���*������(����� �+��������������� � ����������������������� ���� ����

• A�����%������ �������5�/.3'��A>.:��&���� ����������� ������ �� � ������������������������������� ������ ������������ ���� ���*������������+������������������ ������� ��������� ���� ���*����� ������+��������������� � ����������������������������� ����

<���������������� ���� �������"�����������%��������������� �����������������������!�$�

SELECT numero, Factura.dni, Cliente.dni, nombre FROM Factura OUTER JOIN Cliente ON Factura.dni = Cliente.dni;

����������� ����!�$�

;������ +�� +�� ;������1DDD� D� D� A���1DD4� D� D� A���

Page 117: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ 8� ���� ��

1DD6� Q� :���� :����1DDG� :���� :���� :����1DDV� :���� :���� :����:���� :���� G� A����:���� :���� 6� 1�������

���������� ��� ��#���� ��� ���������� �������������� �� ����� �������� ���� ����&����� ��������������������������� ������� ���,������������������ � ����� ���������������������� ������� ��������������������������#������ ����������������� �����:�������� �������������� ��������� ���������� ��������� ���� ������������������ � �� ��� ����������������� �� ������������������ ������ ���#������ �������������������������������������������:�����

&�� ���������� ������ ��� ����� �%������ ���� ��� �(����� ��� �� ������ ���� ��������� �� ������ �� �� ������ ��� ��� ��������� �� ��� �� �� ��� �� � ��� �������� ������� ���,�������������������� � ����������������������������������!�$��

SELECT numero, Factura.dni, Cliente.dni, nombre FROM Factura LEFT JOIN Cliente ON Factura.dni = Cliente.dni;

����������� ����!�$�

;������ +�� +�� ;������1DDD� D� D� A���1DD4� D� D� A���1DD6� Q� :���� :����1DDG� :���� :���� :����1DDV� :���� :���� :����

"�� ������ �� �� ������� ��� ���������� �%������ ������� ��� �� ������� ���������������������)� �������������������� ������� ��� ������(����� ���

��������������������������������������������%���������� ��� ���������� ������������������� ���������� �������� ������ ��������� ����� ���� ������ ��� ��� ����� �� ��� �� ������������������������ � �������������� ��� �����������������!�$�

SELECT numero, Factura.dni, Cliente.dni, nombre FROM Factura RIGHT JOIN Cliente ON Factura.dni = Cliente.dni;

����������� ����!�$�

;������ +�� +�� ;������1DDD� D� D� A���1DD4� D� D� A���:���� :���� G� A����:���� :���� 6� 1�������

���������� ��� ��#���� ��� ���������� �������������� �� ����� �������� ���� ����� ��� ����������������� ����� ����� ������� �����������* ������+����� ��� �� ���� �� � �� ��� ����� ���� �������� �� ��� �� ��� ,������� �� ���� ��� ����������� �������� ����������������#������������

Page 118: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ � ���� ��

-��� �������� �� ����� ���� ���� �������� &?�� ���� ��� ����� �������� ��� �������(���������(�� ����������%�������������� ���������%������������������������������� �� �� ��� �� ��� ������� ,/>=� �� �������� ��� ���� ������� .::"/� A>.:�� ������ ������ ������������������� �� ����������W�"/"������)� ��!���������������>:���

��������� ����������������������� ��!���!$�

SELECT numero, Factura.dni, Cliente.dni, nombre FROM Factura INNER JOIN Cliente ON Factura.dni = Cliente.dni;

��� �� ���������� ����

&?�� �� ��� ��������� ��������� ��������������� �� �������� �� �����(�� ��������������������������������� ����������� ����������������(������ ���� ����� ��� �� ����� ������� �� ���� ��� �������� � � �� ��� ��������� &"�"�'�� �������������������������&?���������������&?�������� ����������������� �� ����� ��� �� ��������%����� ����������������&����� ���������&3;�� � ��������������������� � � ����� ������������ �� ������������� ���������� ������������� ����� �(���� ����#�� �������� ��� ��� �� �����������(������������������������� ��� ���� �� ������ ��� ������� "�� &3;�� � �� ���� ����� ��� ���� ����������(�������������������������� ������������������������� ����������������� �� �� �� ����������� ��� ������������ ���� ���� ������ -���� �� ������� ���������� �� ������ ��� �� ��������������������$�

• .:&"/'�������)� �����#������� �� ������������ ����

• �"�"'"������������������� �� ���� �������� ����

• 2-�1'"�������� ������ �����%������������� ��� �� �����

Añadir filas. Sentencia INSERT

������ � � �� �����������)��������� ���)� ���������� ��� �� ������������������������ �������� ����"��������������&3;�� �� �����&?������������������������� ���)� ������#������� �� ���������� ��� �� ���$�

• 2��� ��������� .:&"/'� �� ���� ����� �)� �� ���������� ���#�� ����� �� ���� �� ���� �� ����&�������(���� ����������� ��������������� �������������������������������� ������� �� �� �����

• 2������������ .:&"/'������������%����� ����� �� ���� �� ����������� ����� ���������)� ���������� ����

• 2�������� � � �����������#���)� �� ���� ������ �� ��� � �� ����������� �%������ �� ��� ��� �� ����� &�� �����(�� �� ����������� ������������ ������������� ��� ��� �� ���� �� ����� ����������� ������������ �� � �������������������������

��� ��������� .:&"/'� �� ���� ����� �)� �� ���� ���#�� ����� �� ���� �� ���� ���������� .:'>� ���������� ��� �� ������� ���� �� ��� ���#�� ����� *��� �� ��� �����<�� �� ����������<1�2"��������������#������ �� ��������������#������������� ����������� ������������ ��������#�����#���������������� ��������#��������

INSERT INTO tabla [( lista de columnas )] VALUES( lista de valores );

Page 119: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ $ -� ���� ��

������ ��� ������������� ���� ������ ��� ���� ������������������������������������� ���� ����������� ������� ���������� �������������&��������������� ����� ���������������������� ������������������������� ������������ �� #������ ��� ��� ���������� ������������ ��� �� ���� ��� ����� �� ���� � ��������� ���������� ���������� � ������� ����

&����� �������(���������������.:&"/'�����&?�����������#��������)� �������������� �� ��� ���� ������ ���� ����������� ����� ���� �������� ��� �� ��� >�������� "�� ����������������� ������ ��� ����������������������#�����������������#���� � ����������#������������������������������)� � �������� ��� �� ������ ������������������ ������� ��������� �������������������� ���������� �� �� ����������������������������� ������������� ������� ������#�� ����� �� ���������(�� ��&?�����������#������������ �������� ������������������.:&"/'������������

"����������� ���������� �������������������������.:&"/'��������������5��� ��� ��� #������ �� ���� ��� ��� ������� <1�2"&� ���� ��� ������������ #��� ������ ������ ��� ����� �� #������ �� ��� ����� �� �������� � ��� ��������� ��� ������������ ���������������������� �� ���� ���� ��#����� � ������������ ��������������� �� ���� �� ��� �������� �������� ������� �� ��� ���� ���������� �� ��� ���������������"����� ���1:&.9.&>��%������� ��� ����������������������������������� ����������� ����� ������ ���������������� ��������� ��� ��� ��������� ���:������������������ ���%������� ��J� � ����������������� ��� ������������������ � ����������������� ������������ ������� ��� �������-�����������

INSERT INTO Factura (numero, dni, importe, fecha ) VALUES( ‘A111’, 1, 155, ‘22/12/2003’ );

�������������������� ��������������� .:'>���� ��������(��������:2����*���������� ����� ��#��������� ������+� &����� �����������%��!������������������ ���#����� :2��� �������� �� ��� �������� ��� ��� ����� �� ���������� �� ��� ���� ��� ���#��:2���������#�������"������������.:&"/'��������%�����������������������������������������

INSERT INTO Factura (numero, dni, importe, fecha, dto ) VALUES( ‘A111’, 1, 155, ‘22/12/2003’, NULL );

������� �������� ��������������.:&"/'��)� ���������������� �� ���������� ��� �������"������������ ������������.:&"/'�� ���#������ �� ������������ ���#�� ����� ��� ��� ��������� �� �%��!���������� ������ ��� ��%��� �� �������������"��������������������� ��������#��������������������� �� ��� �� �������������� ������������������

INSERT INTO tabla [( lista de columnas )] SELECT . . .

��� � ������ �� ����� ����� #������ ���#������ �� ��� ������� ��� �� ������� �� �������� �%���)�� ��� ����������� ����� �� ���� ����� ��� ������� �������������������� -��� ��������� ���������������������� ������������� �� ��� ����� ��&�������;IIJ�������� ������������� ����)��GHHV���������������������!�������$�

INSERT INTO Facturas2004 SELECT * FROM Facturas WHERE YEAR(fecha) = 2004;

"�� ��� ��� &?��1:&.9.&>� ���������� #����� ������������ � ��� ��� �������������������� ������ ��������������.:&"/'����������$�

Page 120: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ �� � ���� ��

• ��� �������� ��� ��� �� ��������� ���� ������� >/�"/� ;[��:�� ��������� �������������� �� ������������� ����������� ����������#�������� ������ �� ��� ���� �� ��� ���� ��� ����� �� �� ��� �� ���� ��� ��� ���

• ��� �������� ��� ��� �� ��� ��� 2:.>:� �� #����� ��������� &"�"�'� ����������&������� ���������������������������������&"�"�'��

• ��� �� ��� ������ �� ��� ��������� .:&"/'� ��� ��� �� ��������� ��� ���������� ,/>=� �� ��� �������� �� �� �������� � �������� ���� ��������������"�������� ���������������� �������� ������!�������

1 ������������� �� ������������� � ��������������������������� �������������� ��� ����� ���������� �� ��� ��������� .:&"/'� *�� �� ��� �� ��� �������������� �� �� ��� ����� �� ��� ����� �� �������+�� �� ��� ����� �� ���� � ��� ���������� �����������������������

��� �������� ������� �� �)� ��� ����� �� ��� �� ��� �� ���� ��� �� ���� ���� ������ ������������� ��� ������������� ��� ���� �� �������� ��� ���� ��� �� ���� ��� ���� ����������� �%���! �� ������� ������ ������������� ��������� �� ������������������������ �������������#�������������-�������������� ������������� ���� �� �� �!�� ���� ��� ��� ��������� ���� ��� ��������� ������� �� �� �������� ��������#���������(����������������.:&"/'� �����������������)� ������������������ ����&����� ������ ��� �������� �� ������ ���� ��� �;=&� �������� ������ ������� ���������.:&"/'� ������ �������� ����� �������������&�� �������� �������� ����� ��� ���� ������� ����������������� ���������!������������������ ����������� � �������������� �����������������������������#���-����������� ����������� ������������������������ ������� ���������������������� ���������6H�HHH������ �� ���� ������#�(��"�������������������� ����� ������������!���� �����������

-���������(������ �������� ������;=&�������������������������������5 � � �� ������ ���#�� ���� ������ ��� ���� � �� ��� �����#�� �� ���� �� ��� �� �����#����� � �� "�� ��� ��� &?�� 1:&.9.&>� ��� ���� ���� ���� ��������� �� ����� ����������� ������������������� ������� � ������������������� ��������������� ������������ &?��� ��� ����� � ����� �� �� #�� � ��� ��������� ������ �� ��� ��������������������� ��������� ����������!������������������� �����

Supresión de datos. Sentencia DELETE

��� ��� � ��� �����)�� �� �������� ��� �� ��� ���� �� �� ���� ��� �� ����������������������������������������������"�"'"����������������������� �� �� ���� �� ���� ������ �� ���� ��� ������� ,/>=� ���������� ��� �� ��� ������ ������������� �������������������W�"/"����������� ������ ��������������������� ����� �� ��� �� ������� #��� �� ��� ������ ��� "� ����#������� ��� &"�"�'������� ��� #�(� ����������������������������������� �������������������&������%���$�

DELETE [FROM] tabla [WHERE condición];

-����������$�

DELETE FROM Cliente WHERE dni = 1;

���������W�"/"� ��������������� ���������������������� ������� ���������������� &?�� �������� �� ��� �� ���� ��� ������� W�"/"� ������ ��� ������� ���������� ��

Page 121: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ �$ � ���� ��

�%���������� ��� ����� ������� W�"/"� ���� �� ����������!�� ��� ���� ���������&"�"�'���������������� ������������� ������� ���������� ������� �� ���� ��������� ����������������������������W�"/"� ���������������"�"'"������������ ����� ��� ��� ��� �������W�"/"� �� ��� ��������� &"�"�'�� ������� ��� �������������������

/����� ������ ��� ��� ������� �� ���� �� ��� ��� �������W�"/"� �� ������������� &"�"�'���� ��� ����������� ���� ���� ����� �� ��� ��������� ������� �� ������ ���� ��� �� �� ��� ��� ������ �� ���� �� ����!������ �������� �� ������ ��� �� ���������� W�"/"� ��� ���� ��������� �"�"'"�� &���������� ���� ��������� ���� ���������� ������ �� �� ��� �� � �� ��� ��������D��������!� ��� ��������� �� ������������������������� � �� ������� ���-� � �$�

DELETE FROM Pedidos WHERE cli = 1;

"���������������������W�"/"�����������#���������� ������� ���-� � �����&?������������ ������������������� �� ������� ���������������������&?�������������������W�"/"����� ������ ���������� ������� ���-� � ����������� ��������������� ��������������� ������ �� ���� ����� ������������� ��'/2"����������� ���������� ����� ��� ������ ��� ��� ������ �� ���� �� ��� ���� ��� ������ ��,1�&"� ��:2����>������������

Eliminar todos los pedidos anteriores al 20/8/2004 DELETE FROM Pedidos WHERE fecha < '20/8/2004';

&��������������������W�"/"��� ��������� ���������� ������� ����-����������$�

DELETE FROM Pedidos;

1������ ���� ��������� �"�"'"� ��� ���� ���� �� ��� #��!��� ��� ����� ��� �� ���-� � �� �� ��� ��� �� ����� ��� ���������� �� ��� �� ��� -� � �� �� �� �������������� ���� �� �������� �� ��� ��� ��� �� ����� ��� �� ��� ���� �%����� �� ���#������� ��� ��� ��� ������ �� ��� ��� �� ��� -� � �� � ���� ��� ��������� .:&"/'�� -������������� ��� ���������� �� ����� ��� �� ��� ��� �� ����� � �������(���� �������������/>-�'1;�"�* ��������������������+��

�� � ����� �)������������������� ����� �������������������"�"'"����������������������������������������������������� ������ �� ���� ������������� � �� ������ �� ����������� ���������� ��� ��������� �� ������ ���� �� �� �����(�� &?�����������#��� �� ����� � ��� �����(��� �������� ��� ������� W�"/"� ��� ���� ���������&"�"�'� ����� #�����(��� ��� ����� ��������� ��� ��������� �� ���� ��� ��� �������������� �� ���� ��������� �� ���� �������� �����(��� ��� ������ W�"/"� ��� ��������������"�"'"��

��� ����������"�"'"�������� ������� �� ���� �������������� ��� ����������������������������������� ��� ��������������� �� ���������������������������������� �� �����������1�#����������������� ���������� � ��������������� ����� ����������� ������������ ����-��������������������������� �������������� ������� � �� ����������������K�.��&���� ����������������� ��� ���������� ��� �� � �� �������� �� ����������� ��� �� ��� -� � ��� "�� �� �� ���������� ��� ��������� �� ���� ���� �� ��� ��� ������� �� ���� �� ����������?�������!�����������#�� �� ���������������"�"'"����������(�������������$�

DELETE FROM Pedidos WHERE Rep = ( SELECT dni

Page 122: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ ��� ���� ��

FROM Representante WHERE nombre = 'José' );

��� �������� ������ ��� ��� ��� ������������� K�.�� �� ��� ������� W�"/"������������������������ � ���������#������������� �������������������������������� ��� � �������� ��� ��� ������ ��� ������ ����������� ��� ��� ����������"�"'"�������������������������� �������� ����� ������������������� ������������ ���� ��� ���!� ����� �������� �� ��������� �"�"'"� ���� �����(�� ��� ������ �� ���� ��� �������$�

Borrar los pedidos de la oficina de Córdoba DELETE FROM Pedidos WHERE rep IN ( SELECT dni FROM Representante WHERE oficina_rep = ( SELECT oficina FROM Oficinas WHERE ciudad = 'Córdoba' ) );

���� ���������������������W�"/"���� ������ �������������������� !����� ��� ������� W�"/"� �� ��� ��������� &"�"�'�� '�� ���� ��� ��� ���������������������%������������� ��� ������ ���������������"�"'"��1������������������������,/>=� �� ��� ����������"�"'"� ��������� ���������� ��� �������,/>=� �� ������������&"�"�'��������!������������ ��������������� ���������������������������� ����������������������������%�����$�

Borrar los clientes que no han hecho pedido desde el 10 de septiembre. DELETE FROM Clientes WHERE NOT EXISTS ( SELECT * FROM Pedidos WHERE dni = cli AND fecha > '10/9/2004' );

����������������� ���� ��������� �"�"'"� ������ ��������� �� ��� �� ��������������������������������� �� �������� ������ �� ���� ���-������ ��������������� ������������������ ����� � ����������������������� ����� �� ��� ������ ���������������������������������������������� ��������������������������%��������� ��� �� �������� ��� ��� ����� �� ��� �� ��� �������� ���� ������������ ��� ��� �������� � �������������������"�"'"��

Modificación de datos. Sentencia UPDATE

��� ��� � ��� �����)�� �� �������� ��� �� �� �������� ��� ���� ��� �� ���������������� �������� �� ���������� ������ ��� ���������2-�1'"��� ������ ���#������ ��������������������� ��� �������������� �� ������ �� ����������&������%���$�

UPDATE tabla SET campo = valor, campo = valor, . . . [WHERE condición];

��� �� ��� ������ �� �������(��� �� �� ���� ��� ��� ���������� �� �� ��������� ������� ���������������������(��� ����� ���� ��� ���� ������ �������������

Page 123: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ �(� ���� ��

�� �#� ��������� ������ ����� ��� ��� �������W�"/"� ���������� ��� ����� �� ����� ��� ���� �������� ��� ������� &"'��������������� �������� �� #��� �� �������(��� ���������� ��� ���#�� #������� ��� ���!� ��� �������� ���� �� ������ ��� �������� �� ��� �������� ������������� ������������������D������'��;;L:;L;II@��

UPDATE Factura SET importe = 1000, dto = 1.5 WHERE dni = 1 AND fecha = ‘22/12/2003’;

��� ������� W�"/"� �� �%���������� ��� ����� ���� �� �����(��!�� ��� ������������� �"�"'"� �� &"�"�'������ � ���������� ��� ������ ��� ������� ��� ��� ������� �� ���� ������ ��� ��� ��������� ��� ��� �������W�"/"� �� ���� ��������� 2-�1'"���� �%���������� ��� ����� ���� ��� ����� ��� ��� ��� ��������� &"�"�'� ���"�"'"��

1�� ������ ���� ��� ��������� �"�"'"�� ��� ��������� 2-�1'"� ��� �� �������(���#����� ����� �� ���� #�(� ���� ��� ��� ������ �� ���� �� � ���� ��� ����� ��� �����������$�

Aumentar en un 5% el descuento de los pedidos del representante con dni 2 UPDATE Pedidos SET dto = dto + 0.5 WHERE rep = 2;

"���������������������W�"/"�����������#���������� ������� ���-� � �������� #����� �� ��� �������� ��� �� �� ������ ��� �� �� ������ ����������������� &?��������� ��� ��������� 2-�1'"� ��� ��������� ��� �� ��� -� � �� ����� �� ������ �������(�� ����������������������������������� ������ �� ���� ����� ������������� ��'/2"���������� ������������������������ ������ ������ �� ���� ����� ������������� ��,1�&"���:2����

��� ������� &"'� ��� ��� ��������� 2-�1'"� �� ���� ����� �� ���������������� �������������� ������������� ��������������������� ���������������(��������������� ����� ��������� ��� ���#�� #����� ����� ��� �������� ������� �� �� �������� ������ � ��!�� ��������� ��������� ���� #�(� ��� ��� ����8� ��� � ��!�� �� ��� ������������� ����� ��� ����� �������� ������� ��� �������������� 1:&.9.&>� �%������� ��� ��� ���������������� ��� �������� ������� ����� ������� ����������������&?�� ��������� ��� ��������������� �� ��� ��� �� �������� ��������� ���:�� ��� ���%����� �� ��J� � ����������� ��� ��� ��� �� ��������� ������� � ��� ������������������� ������� ��� �������

��� �%������� ��� �� �� ���������� ��� �� ��� ���������� �%������� &?�� ��������������#����� �������� �� ����������� ������� ����������� �����������%������� � ������������ ��� �� ��������#������ ��������������������������������(�������������� ��� �������:����� ��������������������� �������������� ���������

&�������%������������������ ����������������������������� ������������� �� ����� ��� ����������#����������(� ���������������� ����%������������#����� ������������������������������������� �������������������������������(����������������������� ����� �������������� ������������������� �������� ����������W�"/"��-���������������� �������������������2-�1'"�

Page 124: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ �*� ���� ��

UPDATE Representante SET cuota = 400000, ventas = cuota WHERE cuota < 400000;

1���� �� ��� �������(���������� ������������ A��� ���!�����#����� ������� ��46H�HHH�n������#����� ��������� ��4NQ�PDD�n�������� ������������(�������������������� ��� #����� �� ������� �� 46H�HHH� n�� !� �� �� VHH�HHH� n�� "�� �� ��� �� ���������������������������&"'�����������8� ����������������� ������������������������������ ����

��� ������� W�"/"� ��� ��� ��������� 2-�1'"� �� ���������� &�� �� ������ ����������W�"/"�������������������(���������������� ������� ��� ���������������������������

UPDATE Representante SET cuota = cuota + 50000;

1� ���������� ���������������"�"'"����� �� ������������W�"/"������������� ������� ��� ��������� 2-�1'"� ��� ���� �������W�"/"� �����(�� ���� ��������������;����������������������������(���������#�� ���� ������� ��������� �����������������������������

1�� ������ ���� ���� ��� ��������� �"�"'"�� ��� � �������� ��� ��� ������ ��������� ����������� ��� ��� ��������� 2-�1'"� ��� ���� ��������� ����������� ����� ���������(������ ������������������������ ������������ ����������!�#������������� �����������2-�1'"����������(���� �������$�

Actualiza la tabla Representante añadiendo 50000 � a su cuota, para los representantes que han hecho pedidos en el mes de septiembre UPDATE Representante SET cuota = cuota + 50000 WHERE dni IN ( SELECT rep FROM Pedidos WHERE MONTH(fecha) = 9 ); Aumentar en 10000 la cuota de los representantes si el total de los pedidos de cada uno de ellos supera su cuota. UPDATE Representante SET cuota = cuota + 10000 WHERE cuota > ( SELECT SUM(importe) FROM Pedidos WHERE rep = dni ); Aumentar un 10% la cuota de los representantes que tengan más de tres pedidos en los seis primeros meses del año UPDATE Representante SET objetivo = objetivo + objetivo * 0.1 WHERE 3 < ( SELECT COUNT(*) FROM Pedidos WHERE rep = dni ); Actualiza la tabla Representantes añadiendo a sus ventas los importes de los pedidos UPDATE Representantes SET ventas = ( SELECT SUM(importe)

Page 125: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ �0� ���� ��

FROM Pedidos WHERE rep = dni );

��������������������&"�"�'������ ���������������������W�"/"� ��������������2-�1'"���� ������ ������ ������������#���� ����� ������������ �������5���� �%������ �� ��� �� ��� ������ �� ��� ��������� 2-�1'"�� ��� �������� ��� ��� ���� �������� ��������������������������������������%�����8�������������������������������������� ������� ���/������������������������������ � ������������������2-�1'"��

��� ����� ����������� ���� �� ������ �� �� ��� ��������� �"�"'"� �� ������ ������!$� ��� �� ��� ������ ��� ��� �� ��������� ��� ��� ������� ,/>=� �� ��������� �������� �� ������� ��#��� �� ��� ������� "��� ���� �� ���� ��� � �������������������� ��� �� ��� ������ *������� �� ����� ����� ��� ��� ��� �� ��� � ���������(� �+�������������� ������������� ��� �� ��� ������ ��� ��� � �������� ������� ������ ����������� �%������ �� ��� ����� �� ��� �� ��� ���������� ������������ ������ �������� � ����������������W�"/"� ��������������2-�1'"��

����� ����������������� ���#�����

"�� ���� *����� ����������� ��������+� �� ��� ��������� �� ������������� ���������� ������������������� �������������������������� ��� �������� ��� �� �����

"������������ ������������%����� ������ ��&?���!���������#������������������������������ ���������������������

Creación de tablas. Sentencia Create Table

����������� ������ ��� �� ������������%�� �����$�

CREATE TABLE nombre_tabla( definición de columna1, definición de columna2, … definición de columnaN [definición de constraint1,] [definición de constraint2,] … [definición de constraintM] );

���������� ���������� �����������$�

nombre_columna tipo_datos [NOT NULL|NULL] [DEFAULT valor predeterminado] [PRIMARY KEY] [CHECK expresión lógica] …

�� �� �������� ���#�� � ��������������� �� ����� �� ����� ����:>'�:2��� ���#������������������������#�����������������",12�'������������������������������ ��#�(�������������������������������� ��������#����������������������������������������������� �������-/.=1/[�X"[����� ������������������������������� ��������#������������������"�X��2��������� ������� ����������� ������������� �������������#����� �������������������������#�� ���

Page 126: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ ��� ���� ��

���������� ���������� �������������$�

[PRIMARY KEY (columnas clave primaria)] [INDEX nombre índice (columnas índice)] [UNIQUE [INDEX] nombre índice (columnas índice)] [CONSTRAINT nombre FOREIGN KEY [nombre índice] (columnas índice) [referencia]

���������������������$�

REFERENCES nombre tabla [ (columnas índice) ] [ON DELETE {CASCADE | SET NULL | ... } ]

-/.=1/[�X"[���������������������������������� ���������������������#��� ���� ��� ��� ������ �� �� ��#��� �� ��������� ����� ��� ���������� �� ��� ������� ��� �������������.:�"0�����������!� �������������� ��������������������������� �������2:.?2"�������������������������������������������������������#���������������� #������������� ���� ��� �����������,>/".3:�X"[� �� ����� ���� ���#�� �%������������������������� ����������������� ������� ����������#���%���������������� ������� ����������� ��� ��� �������� �� ���#�� �%������ >:� �"�"'"� �� ����� �������������� ���� �� �����(��� � ��� ��� �� ��� ���������� �� ���� �� �� �����(�� �������������� �� ���� ��*�"�"'"+��������� ����"%�����������������>:�2-�1'"����������������������������������� ���������(������*2-�1'"+��"������������������������������ ����������� ���1:&.5&?���������������>/1��"�������!�=�&?���

�������%�����������������/"1'"�'1;�"������������������������������ ��������!�� �� ��� &3;�� ��������� ���� �� �� #��� ��� ���!����� ���������� ������������������ ��������� �������������������!������

������������ ������� ���,1�'2/1� ����� ������������������!�����������������>�����$�

CREATE TABLE FACTURA( numero VARCHAR2(10) NOT NULL PRIMARY KEY, dni INTEGER, importe NUMBER(9,2), fecha DATE, dto NUMBER(5,2), CONSTRAINT FK_CLIENTE(dni) REFERENCES Cliente(dni) ON DELETE CASCADE;

�������������#����� ������������� ��������#��������������� ������������:>'�:2����������������������� ����������������������(���� ��#������1 ����������������#������������� ������#���%������������������������������.":'"�*�������� ������ ��� ��� ������ �� �� ���#�� ������+�� ���� ��� ������� >:� �"�"'"��1&�1�"� ����������� �� �� ����� ��� ��������� �� ������ ��������������� �� ������������������������������������������������������#���%�������������� �������� ���,1�'2/1����� �������������� ���������������������� �����.":'"��

Creación de índices. Sentencia Create Index

��������!� ����� ��������� ��� �� ��� �� ������������%�� �����$�

CREATE [UNIQUE] INDEX nombre_índice ON tabla( columnas_indexadas )

��� ������� 2:.?2"� ������ ����� �� ��� ������ �� �%� �� ������ ���#�������������� ��������������������������������� ���������� �%� ������������������� ����-������� ��� ������������������������������������ � � ��������������

Page 127: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ �8� ���� ��

������ ������� �� ��� �� ��� ���#�� ���������� "�� ���� ���� �� ��������� ������ ���!� ���������������������������������� ���

-��� ��������� ��� �� ��� ���� ��� ������� �� ��� ,1�'2/1� ��� ���� �������������������������������� ���������������������

"���������������������&"�"�'���������(�����!�������������$�

SELECT * FROM Factura WHERE dni = 1 AND numero = ‘A111’;

"������������������� ��� ������� ���,1�'2/1����������� ���������������#�����������*������/���������+��&����������� ������������������� ���������������������������!� �����������������$�

CREATE INDEX ind_factura_cliente ON FACTURA( dni )

:���� ��������������������2:.?2"������������������� �!�������������� ���������������������������

Creación de vistas. Sentencia Create View

2���#����*��H+���������������&"�"�'��������� ����� ��� �� ��������������������� ����&?�������������� �������������� �� ����������������������������� ���� �� ��� ����� ��� ��� ��� �� ����� "� ���� �� ��� #������� ����� ������� ������ ����� �������������������&����������������������������$�

SELECT Factura.dni, nombre, SUM( importe ) FROM Factura, Cliente WHERE Factura.dni = Cliente.dni GROUP BY Factura.dni, nombre ;

&�� ���� �������� �� ������� �� ��������� ������ #����� �������� �� �������� ��� ���� ���������� ��� ��� �� ���� ���� ��� ��� ��� *������ ���� #���+�� �� ����������������������� ������#�����

CREATE VIEW TOTAL_FACTURA_CLIENTE AS SELECT Factura.dni, nombre, SUM( importe ) FROM Factura, Cliente WHERE Factura.dni = Cliente.dni;

[� ����������������������� ������#���$�

SELECT * FROM TOTAL_FACTURA_CLIENTE;

�������%�� ����������� ��#�����$�

CREATE VIEW nombre_vista [(lista_columnas)] AS Subconsulta;

������������������������ ��������#������������������������������� ���������#�����-�������������#���������%������������������������������������ ������� �������� ������������� ������������������

�������������/"1'"�<."W���� ����������������������������� ������� ���������� ��� ��� #���� ������� ���� ��� &�� �� ���������� ���� ����� �� ��� ��� ��

Page 128: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ � � ���� ��

��������� � ����������������������� ������������������������� ������������� ��� ������������������&����������������������������� ��� ���������������������� �� ��������������� �������������������!����� ���� ������������ � ����� ����� ���������� �� ��� �������� ��� ��� �� ��� �������� &�� ��� ����� �� ��� ��� ������������������ ���������������/"1'"�<."W���� ���������� �����#����� �������� ��� ��� �� ��� �������� �������� ������ �� ��� ��������� ��� ����� ����� ��� ���������� � �� ��� ��������� �� �� ��� �������� �������� �������� ������� �� �� ����� ���� ����������������� ���� ��������

&������#������������������������������������������������ ��������������������� ������� �����������������������'�0������-������������������������#������������ ��������������� ��� ������ ������������������ ����

CREATE VIEW Cli_Ord AS SELECT * FROM Cliente ORDER BY nombre;

&�� ���#��������������������������������������� �������� �������������� ����������������������-������������������������#�������������������������������� ����������������������������������� ���������������#����� �����������������

CREATE VIEW Cli_Fac AS SELECT dni, nombre (nif, razon_social) FROM Cliente WHERE dni IN ( SELECT DISTINCT dni FROM Factura );

&����������������������&"�"�'� ������#�������� �!��������������������������� ��� ������������� ����� ������������������������� �����������

SELECT nif, razon_social FROM Cli_Fac;

���� �� ������������&"�"�'� �� ���#���� �������������������3/>2-�;[��� �������� ����� � �������� -��� ��������� ������ ���� #���� ���� ��� ��� ��� ������������ ������������������� �������������

CREATE VIEW Cli_Fac AS (dni, nombre, total) SELECT dni, nombre, SUM(importe) FROM Cliente INNER JOIN Factura ON Cliente.dni = Factura.dni GROUP BY dni, nombre;

���� �� ��� #���� �������� ���� ��������� &"�"�'� ���� �� �� �� �� ���� �� �����������������������

2��� #���� ��� �� ��� �������(� ���� �� ������ �� ��� ��� �����(��� �����������.:&"/'�� 2-�1'"� �� �"�"'"�� -���� ������� #���� ���� ����������� ��� ��� ������ ��� ��� #�������������������������#����������������� ����� ���������� ����� #����� ����� �� ��� #���� �������� �� ���� �� ��� ������� �� ��������� ���� ��������������� ��������������(� ������ ���������������"���������������������������#������(,�������������������������������������������� ��������������������� �!�������������.:&"/'������#����

INSERT INTO Cli_Ord VALUES( 10, ‘Ernesto’, ‘Martínez Segura’, ‘c/ Mayor, 111’, ‘Madrid’, 28010);

Page 129: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ �-� ���� ��

&����� ���������#������(&������������������������������ �������������������� ���� �������� ������ �� ��� #����� �� ��� �������� ���� ��� #����� ��� ��� ��������������� ������� ���������������������� ��������������������(������ �� �����

-���� ���� ���� #���� ��� ���� ��� �� ��� �������(� ��� �� ��������� ���� �� �������#������ ������������ ���������� ������������������������������ ������ �� ��� � �� �� ��� � ������ #������:2���� ������� �� ��� ���������� ��� ������ ���.:&"/'�� ������#��������������� �������������� ����� �������������� �����#���� *�� ����������������� � ��� ��� �������� � �������+�� ����� ��� � ����������� �� ��� �� ��� ����������� ��� �� ������ ��������� �� ��� ��� ���������� �� ���#������

1 ������ ������������������������&"�"�'� �����#��������������W�"/"������ ���������� �������#������� ��� ������������������� ��������������������������� ���� &"�"�'� �� ��� #����� ���� ���� ���#�� ��� ����������� -��� ����������������������#������������������� ����� � ���

CREATE VIEW Cli_Cor AS SELECT * FROM Cliente WHERE población = ‘Córdoba’;

&�� ������� ��� .:&"/'� ���� ��� �������� �� �� ��� �������� �������� �� ������������#�����M�����N�����#������������������������������������������� ������������� ���#�� ��������� ����� ��� ������ ��� &"�"�'� � ��� ��� #����� ���� ���#�� �������� ���������������������������������� �������-�����#�������������#����������� ����������� ������� ��� ��� ������ �� �� ��������� &"�"�'������ �� �� ��� �� ������� ���� ����������W.'����"�X�>-'.>:�����#��������������� ������!���!�

CREATE VIEW Cli_Cor AS SELECT * FROM Cliente WHERE población = ‘Córdoba’ WITH CHECK OPTION;

&�� ������ �������� �� ������ ���� �������(������ � ��� ��� #���� �� ��� �������#������������������� �������&?�������(����������������

Borrado de tablas, índices y vistas

-���� ������������ ����������(���������������/>-�'1;�"���������%����

DROP TABLE nombre_tabla;

���� ����������������� ��� ����� ��� �� ������� �������������� ����������� �������� ����:������������� ��������������� ������� � ������������������������ � �������(����������������� � ���

-���� ���������!� �����������(���������������/>-�.:�"0��&������%����

DROP INDEX nombre_indice;

"��!� ���������� ��������� �������� ��������������������������

-���� ��������� ���������� ������#��������������������������/>-�<."W��&������%���$�

DROP VIEW nombre_vista;

Page 130: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ (� � ���� ��

/���� ���� ���� ���� #���� �� ���� ��������� &"�"�'� ���� ��� ���� ���� ���������������������� ������� ���������� �����#����������� ����� ���������

:����������������������������� �������������������������� ��� ��������������� ����� ������ ��� �� �����

Modificación de una definición de tabla. Sentencia ALTER TABLE

���������������� ������� �������(� �� ������������������������������������� ��� �������� ����� ���������� ������������ � �������� ���� �������� �� ������� � ����������� ���������� �����

�� ������ ��������� ���������������������� �����������(� ������ ������������1�'"/�'1;�"����������������� ���� ������� ������������� ���������� ������� ����������������1�'"/�'1;�"���� �$�

• 1)� ������� ���������� ������������������ ����

• ���������������#���������������������� ����

• ���������������#�����#�������������������� ����

• "���������������#���������������������%������������������ ����

�� ��&3;������������������������������������������������!����� ������� ��������������������%���� ����������������

ALTER TABLE tabla | ADD [COLUMN] declaración_columna | ADD INDEX nombre_índice (columnas índice) | ADD PRIMARY KEY (columnas_índice) | ADD UNIQUE nombre_índice (columnas_índice) | DROP [COLUMN] nombre_columna | DROP INDEX nombre_índice (lista_columnas) | DROP PRIMARY KEY | MODIFY [COLUMN] declaración_columna | RENAME [AS] nombre_tabla_nueva | ADD [CONSTRAINT [nombre_restricción]] PRIMARY KEY (columnas_índice) | ADD [CONSTRAINT [nombre_restricción]] UNIQUE (columnas_indice) | ADD [CONSTRAINT [nombre_restricción]] FOREIGN KEY (columnas_indice) [referencia]

"�� ����� ������ �� ��� ��������� 1�'"/�'1;�"� ���)� ��� ���� �������������� �� ��� �%�������� ��� ������� �� ���������� �� �������� ��� ��� ��������� 1�'"/�'1;�"���#������������� ������������ ���������������/"1'"�'1;�"������������� ���������� ���������#�������������)� ����������� ����� ����������� ���������� ������� ������������������������������������� �����������������������������&������� ������������ ��� #�����:2��� ����� ��� �������� ������� �)� � �� ��� �� �� ���������%������� ������� ����-�����������

ALTER TABLE Cliente ADD COLUMN persona_contacto VARCHAR(50);

&�� ��� �������� �� ������� ����� :>'� :2���� �������� �� ����������������� � ��������� ���������#��������� �������������� �������������������� ���

Page 131: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ ($ � ���� ��

�������&3;������������)� �������#����� ��������#��������������� �������������#��������� ������������������ ��������� �� �����

&�����������)� ������!� ����������� ��������������������������������

ALTER TABLE Cliente ADD INDEX (nombre);

-���� ����������������������� ������� ���&��������

ALTER TABLE Factura DROP COLUMN importe;

&�������#��������� ���������������������������� ����������������� ���&��������� �!���)� ������!�

ALTER TABLE Factura ADD CONSTRAINT fk_factura FOREIGN KEY (dni) REFERENCES Cliente(dni) ON DELETE RESTRICT ON UPDATE CASCADE;

&��������������� ���������� ���������� ����������

ALTER TABLE Cliente RENAME AS Cli;

������ ��� ��

"��������� ������� � �������� ��� �� ������ ������ �����������������������$�

D� ��� ������� ��� ������� �� ��� ��� �� ����� �� �� #�(����� ��� &3;�������(�� ���� ���������� ��� ��� ��� �� ����� ��� ����� �� ������� �� �����������"��&3;������������������ ���������������� ���� ��� �� ������������������������� ���������������

G� ���� ����� ����� ��� �� ����������������������������������� ���������� ��� ����������� �� ����� � � &?��� ��� ����� � � �� �������������������� �� �� ��� �� #����� ��� �����!�� �� ��� ������� ��� ��������������������(��� �������� ����� �� ��� ��� �� ���������� ��� �������� � �������� ��������

4� ������#���������� �������������������������������������� ������������������� �������� ��� ����� ����� ��� �� �����2������������ ��������������� ����� &"�"�'� �� .:&"/'� � ��� ����� ��� ���� �� ��� �������� ������������������������ ���������� ���������������"�"'"���2-�1'"������ �� ��� �� ����2��������� ������������ �� ������ ��� ��������� ��������� �����#��������

-������� ���������������� ������� � �������� ��� �� ������������(�������������� 3/1:'� ����� ����������� ���� ������� ������� ���� ���#������� � ��� ����� ����� ����� ��� �� �����2���#�(������ � �����#���������� ����������� � ������ ������������������/"<>X"��

Asignar privilegios. Sentencia GRANT

������������3/1:'��������(������������ ������#������� ������� � �� ���� ����� ����� ��� �� �����������������!������&������%���$�

GRANT privilegio [(lista_col)] [, privilegio [(lista_col)]]… ON tabla TO usuario [, usuario]…

Page 132: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ (�� ���� ��

[WITH GRANT OPTION]

����� �� �� ���� ��� ��� ����%�� ��� ��������� 3/1:'� �������� ���� ����� �����#������� ����� �� ���� ����� � ��� ���� ������ �� �� ���� ����� ���������� ������#������� ���� ��� ���� �� ���� ��� ��� ��� 1:&.9.&>� &?�� ��$� &"�"�'��.:&"/'�� 2-�1'"� �� �"�"'"�� �� �� &3;�� ������ �� ������� ����� �� ���#��������� ��� �������

-��� ��������� �� �� ����� �� ��� ������� ����� ��� ���#������� �� &"�"�'� ��2-�1'"�� �������� ����������������� ��!����������������!�

GRANT SELECT, UPDATE ON Cliente TO rafa;

&���������������� ������#������� �� ���� ���������������������������������� ���&��������

GRANT DELETE ON Facturas TO maria, rafa

&�� �� �����(�� ��� �������W.'��3/1:'�>-'.>:� �� ��� ��� ��� � � ��� ������� ������� �� ��� ����� �� ��� ���#������� �� ����� ����� �� �� #�(� �� ����� �������� -������������������� ��������#������� ��.:&"/'����������������� �������� ������������������������������� ������#�(������� ��������������������

GRANT INSERT ON Cliente TO rafa WITH GRANT OPTION;

-���� ��� ���������� 2-�1'"�� ���� ��� �� �����(���� �� ��#��� �� �������� ����� �� ����������� ���#������� �� �������(������ ����� �������� ����!����� �� ������ ������ �!����������������������������������� ���������������������������������������� �����#������� ���������(�������-���������������������� ������#�������2-�1'"����������������� �������� ���&���������������������������������� ��!��������������

GRANT UPDATE (importe) ON Facturas TO rafa;

Revocación de privilegios. Sentencia REVOKE

������#������������ � ������������������3/1:'���� ������������ ������������������/"<>X"��&������%���$�

REVOKE privilegio [, privilegio ]… ON tabla FROM usuario [, usuario]…

-�������������������������������#������� ��������������������(������� �������� �������������������������

REVOKE SELECT, UPDATE ON Cliente FROM rafa;

"��������� ��������������������#���������������������� � ����������������W.'��3/1:'�>-'.>:������������������������������� �������������������������������� ��� ������ ��� �������!���-�������������� ���������������#������� �� ������������������������ � ��� ��� �� ��� ������� �� ��� ������������ ����� ��� ���� ���#������� ������������������������������������ ����������������������#���������������

REVOKE INSERT ON Cliente FROM rafa;

Page 133: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ ((� ���� ��

��������� ������� ����

��� ��������� &?�� ��������� ������� �������� ������� �� ������ ������������=��*&"�"�'��.:&"/'���"�"'"���2-�1'"+��

Funciones de tratamiento numérico

� ��� +�� ��� ���1;&*���+� /����������#������ ������ ��������������".�*���+� /����������������������� �������������,�>>/*���+� /����������������������� �������������=>�*�����+� /��������������� ����� �#������9��->W"/*�����+� /����������

/>2:�*��M��O�+� /������������ �� �� ������ ���������&��������������H��&.3:*���+� /�������D������������#���5D���������#����H�����H��'/2:�*��M��O�+� '�������������������� ���������&��������������H��

Funciones de tratamiento alfanumérico

� ��� +�� ��� �����/*���+� /������� ��� �������� ����#������� ��� �� ���� �� ��� ��� �� ��� ��

��������� �����������������(� ��*1&�..��2:.�>�"���+��>:�1'*�D��G�+� ���������� ���� ���� �������������"���#��������������� ���

mm�.:.'�1-*��+� -�������������������������������� ���� ������ ����>W"/*��+� -���������������� ������� ���� �������������-1�*�����+� /������������������������������ ������� ������/-1�*�����+� /����������������������������� ������� �������'/.=*�DM��GO�+� "��������� ���������������� ��G����D���������(����� ���&����

������G�������������������������/'/.=*�DM��GO�+� "��������� ���������������� ��G����D�������� ��������&����

������G�������������������������/"-�1�"*� D�� G��4�+�

/�������D������� ������������� ��G��������(� ������4��

&2;&'/*��������+� /���������������������� ��� � ����������������2--"/*��+� -���������������� ������� ���� �������������":3'�*��+� /����������������� �*������������+� ������� ������� ���

Funciones de tratamiento de fechas

� ��� +�� ��� ���1��@=>:'�&*� ����+� &������� ������� *�����#�� �� ������#�+� ��������

������������1&'@�1[*� �+� /����������������� !�� ����� �������������� ���=>:'�&@;"'W"":*� D�� G�+� /���������� ����������������������� ���������/>2:�*� ���+� /� �� ������������ ������������������� ��� �������

*e+�'/2:�*� ���+� '������ ��� ������ � ����� ��� �������� �� ��� �� ��� ��

*e+�

Formatos para ROUND y TRUNC para fechas:

������� +�� ��� ���h=>:'�b��h=>:b��h==b� -��������� �����h�1[b��h�[b��h�b� -��������� ��������

Page 134: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ (*� ���� ��

h["1/b��h[[[[b��h[b� -��������� ���)��

Funciones de conversión

� ��� +�� ��� �����1/'>/>W.�*��+� ���#������������ ������������ �� ����/>W.���/>W.�'>��1/*���7� �+� ���#������ ��� ����� �� ���� />W.�� ��� �� ���� ��

�����������'>@��1/*�eM��O�+� ���#�������������� �� ����e������ ���� �������������&��

e� �� ���� ������� �� �� �� �����(��� ��� �� ���� � ������������� �����#�������

'>@�1'"*�DM��GO�+� ���#������ ��� �� ���� D� ��� ������� ��������� ��� �������� �����#�����G��

'>@:2=;"/*��+� ���#������������ ���� ���������������#���������������

Otras funciones

� ��� +�� ��� ����2=-*���������+� /������� ������������ �� ���������������

������������������ ��� ���3/"1'"&'*��%��D���%��G�������%��:�+� /�����������%���������������"1&'*��%��D���%��G�������%��:�+� /�����������%��������������:<�*��%��D���%��G�+� /������� �%��G� �� �%��D� �� :2���� ����

���������%��D��2&"/"<:*��+� /������� �������� �� �������� �� ��� �����

����#������#��������������� �����$�� h.&�;1b$� /������� h'/2"b� �� ��� �������

����#����������������;1��� h�1:3213"b$�. ���������#���� h'"/=.:1�b$�:�� ��� ����������� �� ��

�������(��������������� h&"&&.>:.�b$�:������ �����������#����

�"�>�"*� �%��@�#�� ���@D�� ���@D�����@G�� ���@G�� ���� ���@:�� ���@:�����@����+�

-������� ����� ���� �#��������� �� #������ �������� "� ������� �� �������������switch ���9�II���case of ��-������"������$�

DECODE( COLOR, ‘R’, ‘Rojo’, ‘V’, ‘Verde’, ‘A’, ‘Azul’, ‘Color desconocido’ )

��������� �������� ��

���������������� ������=�&?����������������$�

Funciones de cadena

� ��� +�� ��� ���1&�..*�� ���+� ��#���#������� ����1&�..� �������������������(����� ��

������� �������1/*�+� ��#���#�������������������� ����1&�..��������1/*����g+� ��#���#�� �� ���������� ��� ���������� �� �� ����1&�..�

������O�

Page 135: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ (0� ���� ��

;.:*�+� ��#���#������������� ���������>1�"&�"*�%�D�� �%�G��g+�

��#���#�� ��� ������� ��������� ��� ����� �� ���� ����� ���%���������

�>:�1'*�� D���� G�g+� ��������������� ���� � ���"�'*����� D���� G��g+� ��#���#������� ����������� �����������,."��*�� �� �� D�� �� G��g+�

;��������� ������������������� ���� ������ �#���#������������� ���������������������

�>:<*��� ��D�� ��G+� ���#������������������ ������:�������;?�,>/=1'*�� +� ,�������� ��� ��������� ��� ���� �� ���� ���� ���������

�������������������?������"0*�+� ��������������������%� ��������>�'*�+� �������������������������.:&"/'*�� ����� ������������� �� ���+�

&�� ������� �������� �� ������� �� ��� ������ � ��� ����������������������� ����������������

��1&"*�� ���+����>W"/*�� ���+�

���#����������� ����������������

2�1&"*�� ���+���2--"/*�� ���+�

���#����������� ����������������

�",'*�� ������+� ��������������������������(����� �� �������������/.3�'*�� ������+� ������������������������� ������� ��������������>�1'"*� �� ������� ������+�

�������������� ������������������������ ��������������������������������(�� ���� �������������� ��������������� ��� ����������� &�� �� ��� �� ����������� �� �����(�� �� ��������������������������� ������� �����

�":3�'*�� ���+� ��#���#������������ ������������ ��������������-1�*�� ���������� ���D+� 1)� ��������:��� ��� �(����� �� ���� ���� ���#��������

��� ��������� ����� ���� ��� �� ���� ���������� ������ �������������

�'/.=*�� ���+� ��#���#�� ���������� ����� ��������� ��� ������� ��� ������ ������(����� ���

=.�*�� ���������������+� ��� ��� � �� ���� �� ��� ������� ���� ������(�� ��� ����������� � ������������������������� � ���������������

->&.'.>:*� �� ������� ���+�

�������������� ������������������������ ��������������������������������(�� ���� �������������� ��������������������� �� ��� �������� "� ����#������� ��$,��)�9����������������<��

/"-"1'*�� ������+� /����������� ������#�����/"-�1�"*�� D�� �� G���� 4+�

/������(������ ��� �������� �� ���� �� �� ��� ����������� ��������� ���� �������������������� �����

/"<"/&"*�� ���+� ��#���#������� ������#���� ���/-1�*�� �������� ���D+� 1)� ��������:� �� ��� ������� ��������� ��� #��������

��� ��������� ����� ���� ��� �� ���� ���������� ������ �������������

/'/.=*�� ���+� ��#���#�� ���������� �� ���������� ����� �� ���������� ��������������� ����������� ��������

&>2:�"0*�� ���+� ��#���#�� ����� ���������&>2:�"0�������#���� ���������� � ��* �������� ��������� �������������+��

&-1�"*�+� ��#���#�������� ���� ������������ ������������ ����#�����

&2;&'/.:3*�� ������+� ��#���#����������� ������� ��������#�� � �����������������������������

&2;'/.:3*�� ���������+� ��#���#�������������� ������� ������������� ��������������

Page 136: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ (�� ���� ��

Funciones numéricas

� ��� +�� ��� ���1;&*�+� <������ ������ �����1&.:*�+� 1�������� ����*����� ����+��1�>&*�+� 1���������� ����*����� ����+��1'1:*�+� 1������������� ����*����� ����+��1'1:G*�+� a������*����� ����+����������������������� ������ � ��

������������".�.:3*�+� "�������������)������������������������>&*�+� ������ ����*����� ����+���>'*�+� ����������� ����*����� ����+���"3/""&*�+� -�������� ������ ������"0-*�+� :�����������#� ������%�����������,�>>/*�+� =����������������������������������>3*�+� �������������������� ������>3DH*�+� ���������� ������� �����-.*+� <����� ����������π��->W"/*�� +���->W*�� +� �����������#� �������/1�.1:&*�+� -������� ���������� ���/1:�*+� ��#���#����������������������������H�H���D��/1:�*������+� ��#���#�� ��� ������� ���������� ������ H�H� �� D� ���� ���

������� � ���/>2:�*�+� /� �� ��������������������%�����/>2:�*�� +� /� �� ��� �� ���� ��������� �� *���� �� ���������

�������+��&.3:*�+� <����D������������#�������������5D�������������#���&.:*�+� &���� �����&?/'*�+� /�!(���� �� �� �����'1:*�+� '�������� �����'/2:�1'"*�� +� ��#���#�� �� ���� �� ������ ������� ������ �� �� ��

��������� ���������&��������������������� ����������������� �������������� &�� �� �� ������ ���� ��� ������� �� �������� ��� ��� ��� ������ ������������� �� �������� ���������������������� � �����������

Funciones de fecha y hora

� ��� +�� ��� ����1[:1="*�����+� ��#���#�������� ����������� !�� �����������������#����

������'����1[>,=>:'�*�����+� ��#���#������������������D���4D�������#����� !�� ������

�����������'����1[>,["1/*�����+� ��#���#�� ��� ������� ������ D� �� 4NN� ������#�� ��� !�� ���

�)�������������'����1[>,W""X*�����+� ��#���#�� ��� ������� ������ D� �� Q� ������#�� ��� !�� �� ���

�����������������'����>2/*����+� ��#���#�� ��� ������� ������ H� �� G4� ���� ���������� ���

������������� �����'������������ ���=.:2'"*����+� ��#���#�� ��� ������� ������ H� �� 6P� ���� ���������� ���

������� �����'������������ ���&"�>:�*����+� ��#���#�� ��� ������� ������ H� �� 6P� ���� ���������� ���

���� �� �����'������������ ���=>:'�*�����+� ��#���#������������������D���DG���������������������

��������'�� � ���=>:'�:1="*�����+� ��#���#�������� �������������� ��� ������ ��������'��

Page 137: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ (8� ���� ��

��������� ���?21/'"/*�����+� ��#���#�� ��� ������� ������ D� �� V� ���� ���������� ���

��������� ����������� � ���W""X*�����+� ��#���#�� ��� ������� ������ H� �� 6G� ���� ���������� ���

������ �� ��� ���'�� � �� *��� ������ �����(��� ��� ������+��

W""X*��������+� ��#���#�� ��� ������� ������ H� �� 6G� ���� ���������� ��������� �� ��� ���'�� � �� *��� ������ �����(��� ��� ����������ZH��������(��������������ZD+��

W""X�1[*�����+� ��#���#������������������H�*����+���N�* ������+������������������ !�� ����������� ��������'�� � ���

["1/*�����+� ��#���#������������������DHHH���PPPP�������������������)�� ��������'�� � ���

'>@�1[&*�����+� ��#���#���������������� ������������ �� !������������)��H������������ � ���

:>W*+���&[&�1'"*+� ��������� ���������������������������������������������1111==��������

�2/�1'"*+����2//":'@�1'"*+�

��� ���� �� ���� ���� ��� ������ ������� ��� �������� 11115==5���

�2/'.="*+����2//":'@'.="*+�

��#���#�� ���� �� ���� ���� ��� ����� ������� ��� ��������������

�1'"@,>/=1'*��������������+�

��#���#�� ��� ���'�� ��� ��� ������ � ��� ��� ����������� ��� ���k&��k��k���k���k���k.��kS��k���k'��k���k��� kW�� k���k ��k��� k��� k7�� k��� k2��k���k=��k���k ��k���k���k[��kk��

,/>=@�1[&*�+� ��#���#�� ��� ������ ������#�������������� *������� �� !�� � ������)��H+��

'>@�1[*�����+� ��#���#����� ��������� *������� �� !�� � ����� �)��H+��������� ��������������'���

�1'"@1��*�������.:'"/<1����������+���1���1'"*�������.:'"/<1����������+�

1)� �� �� ��� � �� �� ������� �� ��� ���'�� � ��� ������ ��� #������ �� ����� ��$� &"�>:��� =.:2'"���>2/�� �1[�� =>:'��� ["1/�� =.:2'"@&"�>:����>2/@=.:2'"�� �>2/@&"�>:��� �1[@�>2/���1[@=.:2'"���1[@&"�>:���["1/@=>:'���

�1'"@&2;*�������.:'"/<1����������+���&2;�1'"*�������.:'"/<1����������+�

/���� �� ��� � �� �� ������� �� ��� ���'�� � ��� ������ ���#������ �����������������������

"0'/1�'*������� ,/>=����������+�

������������ ��������'��'������������ ����������������� ���#������ ������������������������

-"/.>�@1��*����� ����+� 1)� �����������#�����������-"/.>�@�.,,*����� �D������� �G+�

��������� ���������� ����� ������� ���

&"�@'>@'.="*���� �+� ��#���#����������������#������������ ���� ����� � ���'.="@'>@&"�*����+� ��#���#�� ��� ������� �� ���� �� ������#�� �� ��� '���

� ���'.="@,>/=1'*�������������+�

��#���#�� ��� '��� ��� ��� �������� ����� ��� ����������� ������������������������1'"@,>/=1'��

Funciones de comparación

� ��� +�� ��� ���3/"1'"&'*�%�D�� �%�G��g+�

��#���#��������������� ��������#����� ���������������

�"1&'*�%�D���%�G��g�+� ��#���#��������������������� ���������������.,*�%�D���%G���%�4+� ��#���#���2�;����2�:���#�� � ������ ���2�@����2�:�

Page 138: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��8�R��< & � � � � � ���$ ( � ���� ��

��������.,:2��*�%�D���%�G+� ��#���#�� �2�;� �� �2�:� �� :2��� �� �� �2�:� ��� ����

�����������.:'"/<1�*����D���G��g+� ������������^��:����������^��;����!�����#��������

���5D�������:2����.&:2��*�%�+� ��#���#��D����2����:2����� ��H�������������������&'/�=-*�� ���D���� ���G+�

��#���#�� D� �� ������:� Z� ������;�� �� H� �� ��� �����������:2��������������������������:2����

Miscelánea de funciones

� ��� +�� ��� ���;":��=1/X*����%�+� "#������2��������#���������#�����1������������� ��

H�� ��� ����������� �� ��� ���������������� �������� ��� ���������� �!���� �� ��� ��� �� �� ���� �� ��� ������� ������������ ��������������

�1'1;1&"*+� ��������� ��� ����� ��� �� ������������":�>�"*�� ���������)�+�

�� ���������������� ������������������5���

�"�>�"*�� ���������)�+�

���� ������ ��� �� ���� ���� ��� ���� �� ��� �� ����� �����#������������������)���

":�/.-'*�� +� "������������� �������� ���� ������#��� ����3"'@�>�X*�� ��������+� /����(����� �����������#��� ����� �������� ����������

������������ �� �����%������������� ���/"1�"1&"@�>�X*�� +� �� ������� ��� ������ ���� �#��� �� ��� ��� ��� �� ����

������1&@.:&"/'@.�*+� ��� ��� #����� 12'>@.:�/"=":'� ���� �� ������� ��

�������������� ������������������������#� ������������1&'@.:&"/'@.�*�%�+� 2����(� �� ���� ��� ��������� 2-�1'"�� ����� �2�� ����� ���

#����� 12'>@.:�/"=":'� �� �������������� ����� �����������������#� �����������

�>1�@,.�"*�������+� ���� ��� �������� ��������� �� �� �#���#�� �� ������� ������������� �����

= 6*�� +� �������� ������� ���������� �� ����� �������� �� �������� ���������� =�6� /&1�� ��#���#�� ���� �� ���� �� 4G� !�������%� ���������

-1&&W>/�*�� +� �� ����������� ������������������ ��� �����#������� ��=�&?�� ���� ������#��� ����

2&"/*+��&"&&.>:@2&"/*+���&[&'"=@2&"/*+�

��������� ��� ����������������� ����� ��� �� �����

<"/&.>:*+� ������#������������� �����#� ���=�&?���

Page 139: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ (-� ���� ��

,� � � + � �

�����������

=�&?�� �� ��� ������������ �� ��� �� ���� ����������������� � ���������� ������� ��� � � ���� -�-�� -����� �� �� �'=��� �� ��������� �#��(� �� ��� ��������������������(������ �� ��� �� ������������������������������ ��������.�������������������� � ��W� ����������� �������������������������������� ���� �� ���#�� �� .��������� "��� ������ ������ �� ��� �� ���� �������������� � �� �� ������ ������� ��� ��#����� �� �������������� �� ����������� �� ��������������� ��������������������� ���

&����� �� ���������=�&?�����������������������#� ��� ��� ������������ �� ��� �� ���� ������������ ��)� �� ����� ��� ��� ���� ������ ��� ��� �������������#��W�� �7��������� ��� ������2:.09�.:20��1 ���� �������� ����������� ��=�&?�� ��� ��� ��� �� � � �� ��� �� ���� -�-� ���'=������� ��)���������������W� � ������������������������������������� ������� ��� ��=�&?����������W� ��1�������=�&?���� ������� ��� ������� ���7�������������� �� ��)��W� ������������7��#���=0��

"�� ���� ������� �� �������� ��� ������ ������ �� �� ��� ��� �� ����=�&?�������#����������������&��������(��#��� ���������������� ��������������������� ������� ������ ���������� ��������������� ��=�&?������� ���������������� ��� �� ���� ����������� �� ���#�� �� &?��� ���� �� ������ ������ �������� &�� ���� ��������������� ��� ��� ��� �� &?�� ����� ����������� ��������� ���������� �������� ���� ���������� �� ��� �� ���� ������������� 1������� �� ���������� �� �������%�����#�� �� �� ��� ������ ������#�� �� ��� � ������������ �� ��� ��� �� ������������� �� ��� � ������������ �� ��#� ����� ��� � ������������ �� ��� ����� � �� ��� ���������������������������� �� �����

��� � ���������� �����$���$��

-�����������������#� ��� ��=�&?��������������������W�� �7�:'9GHHH90-������������������������������$�

D� ��������� �� ��� ������ 7� � �� =�&?�� ��� #������ �� ������� ��=�&?���������5��#� ��������W�� �7���

G� �������������������������(��� ������ ���

4� "�������������������������%��

V� ������������ ������ �����%�2������������ ������������ ���������#���������������������������������������������� ��������������

6� "��������������������)!�����*�!����+���������*��������(� �+�� �� ���� ����������������������� �������������������������������%�2���

N� "�� ������� �� ����������� ������� ��� �������� ��� ��� �����������BP�!�����

Page 140: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ *� � ���� ��

2���#�(������������ ����������������������������#���!?�������� �����������BPH��H����������������������(������������������O�'�.7�/�����0������������������ ��� �BP�!���P���� 1�� ����������� ������� ���� ��� �%���� ��� �����#���BPH��H�P�!?����������������������������������$�

Figura 1. Ventana de usuario para WinMySQLAdmin

����� �� ��� �� � ��#���� ���� ���� ����� ����� ��� ��� ��� �� ������� �� ����������)�� ���� �� ����������� ����� �������� �� �������������� ��� ��� �����#���!?���"���������� � ��������������� ����������#� ����������� ������������������������ �����(��� ��� ������� >�;�� ���� �� ����� ��������������� ������� ��������������������������)���

1 ��������������������#������������������������������#������������������������������� ��� ���������#� ���=�&?����������#���������� ��������� ���

Comprobación de la instalación

-� ���������� ����� ��� ��������������� ������������������� ����� ���������!����'H?�2�� ���� ��� ��� ��� ���������� �BP�!���P���� 1�� �������� ������ ���������������������������� ��� �� ���������������������������������=�&?������ ������������ �� ��� �� ���$��!������������

1 ���� �� � ��#���� ��� ��� ��� �� ��������� #������ ��� ������ �� ���������������W��=�&?�1 �����&������������������#�� ������������������ ��������������� &�� ��� ������� ��� ��� ����� ������������� ��� ��#� ��� ������� �� �� ��������������� ����� ������

"�� ������ ���������� ��� ���� ��#�� ����� ������ ��� ��#� ���� ������� ��������������� W��=�&?�1 ����� ������ ��� ��#������ ����������� ���������� �� ������� ��������#���!?���������

&����������������������������������������)����������� ���������$�

D� &��7����5�=����������������������

Page 141: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ *$ � ���� ��

G� W��:��5����� ����������� ����������� ��#������ ��������� ������������� ��W��=�&?�1 ��������������� ��#������&����� ��#���������%��������������������������������������#������

&���������������������'H�����������������������������������������$�

Figura 2. Ventana WinMySQLAdmin

���������������������� ������������(��������� �� �����#� �������������� �� � ��#��� �������� ������������ ������#�� ��� ������ �� �� ���!� �%���� ������ ��� � � �� � ����� ��� �����#���!?��� #��� ��� ���������� �� ��� ��� �� �����%�������������� ������#����� �����#���� ��� ��������������g�

-������ ������������������������������������������������ ����������������� ��� ���� �� ���� �� ����� � �� ���!����� ����� ��� ������ ������� ��� ��� ������������� -���� ����� ��������� ��� ��� ����)�� ���!?�� ������ �� ������ ��� ��� �������������'��������������������

Interfaz en línea de comandos

1������ �%����� ������������ 32.� ����� ����� ����� ����� �� &?�� �� ���������� �� ��� ��#� ���� ��� ����������� �� =�&?�� ��������� ��������� ��������������� ����� ��������� ��� ��� �� ���� ���� ������� ��� ��� ����������� ����� ���� *������ �� ��� ������ ����� �� =&5�>&+� �� �� ��� ������� ��� ������� ����� ����� �� �� �������� ��� ������ �� ���� ���� �������(� ��%����� ��������� ����

-������������� ��� �������(���� �!���� �� ����� ����������� ���� ���� #�������=&5�>&��������������� �����������BP�!���P��������������������P������������ ���������� B�� ����� ��� ������ ���� ��� ������� ���� �� �������� �� ��� ������ '����� ���������������������������������� �������������&����� ��� ��#����������������� �����

Page 142: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ *�� ���� ��

�������(�����!�������!���8����������������� �����������&?�������������������������������� ����� ��� �� ���������������������#� �����

Figura 3. Interfaz en línea de comandos SQL

���������� ��� ��#�����������%���������#� ������������� ������������������ ��� ������� �� �������)��� "��� �� ������� ������������� ��� ������� �� ����� ����������)��������������� ������� ��� ������������������������������

2��� #�(� ������ �� =�&?��� ��� �������� ���������� ���� ���� ���� ������ ����� ������ ��� �������)�� ��� ������� ������ "��� ������� �� ��� � ������� ��� ���������������� �����#� ��� �� ��� �� ��������� ����� ������� ��� �� �����������������������(����������� ����������"����������������������������������� ������� ��� ��������� ��� ��#� ��� �� ��� ����� ��� �������)��� -���� ��� ������ ����������)���������������������������� �$�

��������Q����H�����Q���1R ������-�S2T�

:������������� ���� ���� �������� ������-�� ���� ��� �������)�� ������������ ������� 1� ������� �� �������� ���������� ����%���� ���� �� ����� ���� ������������������ ���������������������������)����� ���� ���&����������� ������������(���� �!���� ������� ��������������� ���0�������������#��#����������������� ����� ���� �������� ���� ������ P�� ����� P�� �� ����� �� ����� ����� ����������)������������������������� ������� ����� ��������������#� ����

��� � ���������� ����������

Instalación de una distribución binaria

-����2:.09����%��%����� ��������������������������� ���� ������ ��������2������������������������������������������������#����������� ���"������������������������#���� ����������!���!�G$#�����#3� �+,%?@QR?��������������#� ������!�G$#�����#3� �+,%?@QR?���� ����� ��� ��������� "�� ��� ���� �� ���� ��� �����#�����������!���#�����(���������?���? 0��

"����������������������������������� � � ������������� ��������������

Page 143: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ *(� ���� ��

rpm –i nombre_paquete

&�� ��� �� ��� ��� ��� ��� ��#� ��� �� ��� ��� �� ���� �� ���� ��� ������������#���������������������������(���������� ������ ���� �����#�������/-=������������L���L��L�!�����'�� ������������������ ��������� �����L���L��?���������������������#� �������������������

"�� ���� �� ����� �� ����������� �� ����� �� ���������� ��� ���� �� �����������������������������������������������$�

D� 1 ���� ���� #������� �� ��������� ����� ��� �� ��� ���� ��� ����������L���L������1��!���� �� �����������=�&?���

G� ����������������!���������������� �� ��������!�����

4� �����������������!����������������� ����������# ��!�����!����

V� �������������������!���#�����(���������?���? 0���� ����������L���L�����

6� ���������������� �������� ������� ������ �� ��0��A�L���L����L�!���#�����(���������?���? 0�S�����2���#�

N� 1�� ������������ �� �� �� ���� �� ��� ���������� ���� �������� ��� �������������������������� ����%����������? 0��-��������������������������� ���������������#�������������������������� ���������������� ����!�����-�������������������������� �����5�L���L����L��!���#�����(�����������!����

Q� ��� ����������� ����������������������� ������!�����

C� 1����� ���� ���� ��������� ��� ������ ���� ����� ��� �� ��� �� ��������������"����� �������������������������� ������#������� ����������"����������������� ��������L�!���(������(���##����=�!���?�

P� 1�������� ������������������� ���� ����������#�� ��� �����������������������������?�"���������������� ���'H��# �����

DH� ��� ������������������� ���� ����������#�� ��� ���������� �� ��������������������!�����"���������������� ���'H��# ��!���������

DD� ��� ���� ��� ������ �� �� �� ��� �����#�� ��� ���������� ������� ��� ��������!�����"���������������� ���' ���# ��!�����

DG� .������� ��� ��������� ��� ��#� ��� =�&?�� �������� �� ��� ��������� ��������L�!����(�����##����=�!����T�

D4� -���� �������� ��� ��#� ��� ���� ����� �� ��� ��� ��������� ������� ��� �����#��������#����L�!���?����������L���L��?��

DV� -������� ����������������)�� ���������������?L��L�!��������U���������H���M�����(�������5�N��

&���� ������ �� ������������������� ��=�&?������������ ���

Comprobación de la instalación en UNIX/Linux

&�� ������� ��� ����������� �� �������� �������������� ��� ������������L�!���(�����(��� ��� �� �� ����� ��� &��� �� ������ �� ���� �����(��� ������������� ����� ���������� �� ���� ��� ��#� ��� =�&?�� ��� ��������������������� ����������� ��� �����

Page 144: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ **� ���� ��

2����(��� ��L�!�������� ������ �� ��L�!�������� ��������� ����� #������������������#� ������������� ����

������ �� ���� ������� ��� ��#� ��� �������� �� ��L�!�������� U�� ����'���H������������������#��#���������������������������������� ���������� �������#�������������� ����L����(�!�����U� �T��������#��#�����������(��������������� ����� #��������� ���� ��� ��#� ��� ��� ��� ���� �� ������������� ����� ������������ ��L�!����'H� ����� #��� ��� ��� �� ���� ���� ���� ������������ ����L�!����'H��!���������#�������� ��� ����������������

&����������� �� ���� ������ ����������������������������������� ��=�&?���������� ���

��� ���������������������� ��

2���#�(� ��� ����������� ��=�&?����� ������� ��� ��������� ��������� ����� ����� ���� ��� ������� ��� ��������� ��� ��#� ��� ��� �� ��������� ��� �������������� �� �� ��� �� ����*��������� �������������� ��� ������� ����� ����������� ��� ��+��1���� ���� �������������������������������� ��� �� ����������������������-����������������(��������������&?���/"1'"�'1;�"���������%���$�

CREATE DATABASE nombre_BD;

<���� �� ������ ��� ��� �� ���� ���� �� �������� ��� ��� �������� �����!����������������&�������� ������ ��� �� ���� ��1���������,����������� ������������������������-�������������� ����������������=�&?���������������������������� ��� �� ��������������������

CREATE DATABASE Almacen;

&���������� ������� ��� ������ ���������������������������������������,F�� 1����� �� ��� �� ��� ����� ���� ��� ��� �� ����� &��� �� ������ ������� ������������ ��� ��#� ��� ������� ��������� ��� �� ����� ��� ������� ������������ �������������� ���#�(������������ ����� ���� ������ ��� �� ������������������������ ��������� -���� �� ����� ��� ��#� ��� ���� ���� ��� �� ���� ��������� ���� ��� ���� ���� �� ������� ���� ��� �� ��� 2&"� ����� ��� ������ &�� ����������� ������������ ��� �� ���������������������� ������ ����

USE Almacen;

��� �������� �� ��

��� �� ��� ��� ��� ���������� �� ���� ���� ��� ���������� ��� �� ���������������� 2��� �� ��� �� ���� ���������� ������(� �� �� �������� *����+�� �� �� ��������������������� ����*���������������+������������� ������� ��� ���� ���������������� ��������������������������� ��������� � � ������� ��� ���� ������ ���� ���� ��� #�� �� ������ �� ��� ������ ��� ��������� &?�� ����� ��������� ���� ������=�&?�����/"1'"�'1;�"���������������������������� ���$�

CREATE [TEMPORARY] TABLE [IF NO EXISTS] nombre_tabla ( definición de columna 1, definición de columna 2, … definición de columna N ) [opciones de tabla] [[IGNORE | REPLACE] sentencia de selección]

Page 145: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ *0� ���� ��

��������� ������������������������������������������������������%�$�

nombre_columna tipo_de_datos [NOT NULL | NULL] [DEFAULT valor predeterminado] [AUTO_INCREMENT] [PRIMARY KEY] [referencia] | PRIMARY KEY (columnas índice) | KEY [nombre índice] (columnas índice) | INDEX [nombre índice] (columnas índice) | UNIQUE [INDEX] [nombre índice] (columnas índice) | [CONSTRAINT nombre] FOREIGN KEY [nombre índice] (columnas índice) [referencia] | CHECK (expresión)

��� ������ �� �������� �������������� �� �������������� ������ ��� �������������%�$�

REFERENCES nombre_tabla [(columnas indice)] [ON DELETE {RESTRICT|CASCADE|SET NULL|NO ACTION|SET DEFAULT}] [ON UPDATE {RESTRICT|CASCADE|SET NULL|NO ACTION|SET DEFAULT}] [MATCH FULL | MATCH PARTIAL]

��� ������ �� ������ ��� ������ ��� ��� ��������� �/"1'"� '1;�"� ������ ����������������%�$�

TYPE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM } | AUTO_INCREMENT = número | AVG_ROW_LENGTH = número | CHECKSUM = {0 | 1} | COMMENT = « cadena » | MAX_ROWS = # | MIN_ROWS = # | PACK_KEYS = {0 | 1 | DEFAULT} | PASSWORD = “contraseña” | DELAY_KEY_WRITE = {0 | 1} | ROW_FORMAT= { default | dynamic | fixed | compressed } | RAID_TYPE= {1 | STRIPED | RAID0 } RAID_CHUNKS = número RAID_CHUNKSIZE = número | UNION = (table_name,[table_name...]) | INSERT_METHOD= {NO | FIRST | LAST } | DATA DIRECTORY=”path absoluto al directorio” | INDEX DIRECTORY=”path absoluto al directorio”

����������������� ����������������� ������������$�

[IGNORE | REPLACE] SELECT ... (Una sentencia SELECT)

&�� �� �� ���� '"=->/1/[�� �� ���� ���� ��� �� ��� ���� �� ����� �� ������������������� �%����� ��� ��� ��� �� ���� ����� ��� ����� ������� �� ���� �� �������� ����� ���%������

.,�:>'�"0.&'&���� �������������#����������������������������� �����������%�����:����� ���� ��� ���� ���������������� �������������� ��� �� �����

"����� ����������� ����������������� ����:>'�:2������������������� ��������#�����������:2��������������� �� ����������������� �������������� ����������� ���������������������� ��������#������������

�",12�'��������(��������� ��������#��������� ��������� ��#�(���������������������������

Page 146: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ *�� ���� ��

���� 12'>@.:�/"=":'� ��� �������� ������ ���� ��� �� ����� ��������� �� ���� �������� ��� #������ �� ��������� ��������������� �����(�� �� ���� ���� ����� �������������������

&���� �� ����-/.=1/[�X"[� ��� ���������� ���#���&��������� ���� �� ��� �� ���������������������������������#���

"%���������������������#��� �� ���������� ���������������������������� �������������������� �� ����� ���������������� �������������������!������"�����$�

-/.=1/[�X"[������������������������������������� ����� �������� �������������������!� �����

X"[� �� .:�"0� ��� ��������� &�������(�� ����� ������!� ���� ���� ��� ����������������� ���2:.?2"�������������������!� �������� ���� ��#������������

���� ,>/".3:� X"[� �� �������� ���#�� �%������� =� � ������� ��� ����������������������������������������������������#���%�������

���� ��"�X�������� �� �� ���� ���� ��������������� ������ ���� �������� ����������� ������� ����������������� ��������������������(��������������#�� ����

����'[-"�Z�������� ���� ������������������ ����-��� ���������=�.&1=��

����12'>@.:�/"=":'�Z��/������ ����������������������������������������������������� ������������������

����� �����������������)���%���� ��V�3 ������ ��������)����������������� ��� ������ 1<3@/>W@�":3'��Z� �/���� ��=10@/>W&�Z� �/���������������#���������%��� �� ������������ ��� ��� ���� ��������������������%���� ��������&������������������ ��������������� ������� ������������)�� ����������#���� ����

��"�X&2=� ��� ���� �� �� D� �� ���� ���� ����� ��������� ���� ���� �������� ������ ����� �� �� ��� ������ &��������� ��� �� ��� =�.&1=� ��������� �� ��� ���� �� ���� �������������

&�� ��� ����� -1�X@X"[&���D���������������!� �����������)�� ������������ �������� �� �����)�� �� �������(������� �� ���� ��� &��������� ���������� �������!� ���� ������������1/���<1/��1/��

"�� ������ �������������)������-1&&W>/���������������� ���������� ������� ��������� ��� �� �����

�����"�1[@X"[@W/.'"���D���������������������(������� ��������#�� ���� ����������������������

&�� ��� ������ �� ��� ��������� �� ��������� �� ��� �� ��� �� �����(�� ���� ���������&"�"�'� ��� ������ �� �� ���� �� �����(�� ����� ��������� ��� �� ��� ���#�� ���� ���:����������������� �������� �������������������� ������������� ������� ������#������ ��� ���� ��������� ��� ��� ��������� &"�"�'�� &�� �� ��� .3:>/"� ��� �������� ������ �� �� �������� �� �� �� ��� /"-�1�"� ��� �������� ��� ���#�� �������� ���� ��������%�������������������#����� �����#��������������

Page 147: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ *8� ���� ��

Tipos de tablas en MySQL

=�&?�� ������� ��������� ����� �� �� ���� ����� ��� �� ��� ��� �������� �������������������������������������� ������������� ������������ ���������������������%�������$�

• '�$./'�5�"������ ������� ���������������� ������ �����������������2����(��������������������(������������������ �%� �������������������������������!� ������ �%� ������������#�������������������������� �����:��������������������� �����#���%�������

• '�)4��5� "� ���� ���������� �� �� ���=�.&1=� � ����������� ��� ������ �� �� ����� ���� ����� ��������� &"�"�'�� �"�"'"� �� 2-�1'"������� ��� ��������� ���� ��������������������������������������� ������������������������ �����#���:������������#���%�������

• $./'�5�"����������� ���� ���������������������=�.&1=������������������������������(�������

• A�/*�5� =�������� ��� !� ���� �� ��� �� ��� ��� ���� �����#�� ���� �����������"�������#������������������ ��������=�&?��������� ������ ����� ��� #������� ��������� ����� ���!� ���� ����������� ��� ������������� !�����

• $�+3�5� "��� ����� �� ���� �������������� ��������� �� =�&?�� ������������������������� �����#���%������������������������ ���������������������������#�� ��DH�= � ���������������� ����%��� ������� ������ ��C�= ����� �������(��������)���%�����

• 3+3�13��U����+���3���2�5�'�� ����������� ������������ �����#���%������ �� ������������� =� ��������� �� ���� �� #�������� ����������

���������� ��� ��#����������������������������� ��� �� ���������������(� ���������������������������������������������������������������������� ���� �� ��� ��� � � �� ������������� ��� ������������� �� ��������� �����(��� �� ������� �������� �� �� ��������!������ "�� ���� ���� �����(������ ��� �� ���$�+3�������������������������������� ���������

-��� ��������=�&?�� ����� ��� �� ��� �� �����=�.&1=��&�� �� ���������������������������������� ��������������������� ���� ���)7-��Z�����-�����������������������������������������/"1'"�'1;�"������(����������������)7-��=�+������������ ���������������� ���.����;��

"�������������������������������������������������� ����� ��� �� �������������(������ ��� ��� ��������� <���� �� ������ �� ������������� ��� ��������� ����������� ��� ��� �� ���������������������������� ����� ����������#���%���������������������������������������������� ���������������������������������������

Page 148: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ * � ���� ��

Figura 4. Modelo Relacional de la base de datos Almacen

ALBARÁN

CLIENTE

nif

razón_social

dirección

población

provincia

telefono

PEDIDO

npedido

fecha

forma_envio forma_pago

cliente

representante

L_PEDIDO

npedido

nlinea

referencia

unidades

precio

dto

und_pend

und_serv

nalbaran

fecha

forma_envio forma_pago

cliente

total_albarán

� " - � " � " . & � . & " �

nif

nombre

dirección

teléfono

PED-REP

npedido

L_ALBARÁN

nalbaran

nlinea

referencia

unidades

precio

dto

npedido

nlinea

ARTICULO

descripción

precio_venta

precio_compra

referencia

forma_pago

descripción

FORMA_PAGO

familia

descripción

FAMILIA

familia

FACTURA

nfactura

fecha

cliente

nalbaran

nfactura

ALBFAC

recibos

cadencia

dias_1

und_comprada

und_vendidas

existencias

ventas

ventas

observaciones total_pedido

EFECTOS

nefecto

fecha

fecha_vto

nfactura

cc

entidad

sucursal

dc

Page 149: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ *-� ���� ��

CREATE TABLE Cliente ( nif VARCHAR(10) BINARY NOT NULL PRIMARY KEY, razon_social VARCHAR(40) NOT NULL, direccion VARCHAR(40) BINARY, poblacion VARCHAR(20) BINARY, provincia VARCHAR(10) BINARY, telefono INTEGER(9), ventas DECIMAL(7,2) DEFAULT 0 )TYPE = InnoDB;

���������� ��� ��#��� ����� ���� ������������������ ������ �������<1/��1/�;.:1/[��"����� � � ������������ ������������������������ ���� ������� =�&?�� ��� ��� ��� ��� �� ��������� �� ���������� "�� ���� ���� �� ��������;.:1/[� ����(�� �� ���� ��� �� ���� �� ���������� ���� ��� �� ��� 1&�..� �� �� �� ����������� ������������ �� �������������1 ������ � ����������� ������ ����� ��� �������+������������#������������������������ ������������#���%�������

��� �� ��� ���������������� �� ���������� � �� �����!������� ��� �������������������

CREATE TABLE Representante ( dni VARCHAR(10) BINARY PRIMARY KEY, nombre VARCHAR(40) BINARY NOT NULL, direccion VARCHAR(40) BINARY, telefono INTEGER(9), ventas DECIMAL(7,2) ) TYPE = InnoDB; CREATE TABLE Forma_Pago ( forma_pago INTEGER(2) NOT NULL PRIMARY KEY, descripcion VARCHAR(40) BINARY NOT NULL, recibos INTEGER(3) NOT NULL DEFAULT 1, cadencia INTEGER(3) DEFAULT 0, dias_1 INTEGER(3) DEFAULT 0 )TYPE = InnoDB;

"�����������������������(� ��������� ���� �����������",12�'�������� �������� #����� ���� ������� ���� �� �� ������� ���� ����� �� ��� �� ��� ��� �� ��� �� #������%��!����������� ��� �� ��� �� ������� �� ���!����� �� �����!�� ���� ��� �������������������

CREATE TABLE Familia ( familia VARCHAR(5) BINARY PRIMARY KEY, descripcion VARCHAR(50) BINARY ) TYPE = InnoDB;

1����������������#��������������� ������*������"����� �������������������#���%�������������������

CREATE TABLE Articulo ( referencia VARCHAR(15) BINARY PRIMARY KEY, descripcion VARCHAR(50) BINARY NOT NULL, precio_venta DECIMAL(6,2) NOT NULL, precio_compra DECIMAL(6,2), und_compradas DECIMAL(5,2), und_vendidas DECIMAL(5,2), existencias DECIMAL(5,2), familia VARCHAR(5) BINARY, INDEX art_fam(familia), CHECK (precio_venta > precio_compra), CONSTRAINT fk_familia FOREIGN KEY ( familia ) REFERENCES Familia(familia) ON DELETE RESTRICT ON UPDATE CASCADE

Page 150: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ 0� � ���� ��

)TYPE = InnoDB;

����������� ��� ��� ���������� �� ��� ���#�� �%������� "��=�&?��� ���� �� ������������ �������� ��������#���%����������������� �%�����������!�����������.:�"0����(���9�����<� ���� ��� ���� �� ����� ��� !� ���� ���(���� ���� ��� �������� �������-������������� �� �����(�� ��� ������� �>:&'/1.:'� ����� �������� ��� ����������� �����#���%������������� ��������� ������#��,>/".3:�X"[����� ������������������������#���%������������/","/":�"&� ����� ����� �������������������"����������������!� ���� ��� �������� �� ��� ���� ������������ ������� �� �� ������ ������ ���� ��� ���#���%����������� ����������>:��"�"'"��� ����������������������(������ ���� ������*�"�"'"+��������� ������������� ����������������%������������� ������� ���������������������������������������������� ��� � ����������������$�

• /"&'/.�'�5�>���������� ��������.� ��������������������� �� ���� ���� � ������ ����� �#����� ���� �������� ��� ��� �� ��� ������� ��� ����������������#��������������� � � �����������������

• �1&�1�"�5�.� ����������� ������������������������� ������������� ����� �� ��� �������� �� ��� �� ��� ������� ����� #����� �� ���#�� �%������������ �� ���� ��� #����� �� ���#�� ��������� ��� �������� ���� ��� �� �������� &�� ��������!�� ��� �������� ��� ��� �� ��� ���������� �� �� �� ���������������������� ���������� �����������

• &"'� :2���5� .� ���� ���� ��� ������� ��� �������� ��� ��� �� ������������� ��� ��� #������ �� ���#�� �%������ ��� ��� �� ��� ������� ����� ��������#�����:2����

• &"'� �",12�'�5� .� ���� ���� ��� ������� ��� �������� ��� ��� �� ������������� ��� ��� #������ �� ���#�� �%������ ��� ��� �� ��� ������� ����� ������ ��� #����� ���� ������� �� �� �� ����� ����� �� ��� ������ ����� ����

• :>� 1�'.>:�5� .� ���� ���� ��� ������� ��� �������� ��� ��� �� ������������� ����������������������������� �������� �����������

��� ������� �� ������� ���� ��� �� ��� �������������� ��� ��� ������ "�� ��������!�� ��������������/"&'/.�'����1&�1�"��

��� ������ �������� >:� 2-�1'"� �� ���� ��� �������� �� ������ ���� �� ��� ����� ������������� ����������������������������������������������� ������� ����������������������������� ���������(������*2-�1'"+��-�������������������������������������������>:��"�"'"��

"�� ����� �� ��� �� ��� �� ��� ��� �� ���� �� �����!��� ���� ��� �������������������

CREATE TABLE Pedido ( npedido INTEGER (5) NOT NULL PRIMARY KEY, cliente VARCHAR(10) BINARY NOT NULL, fecha TIMESTAMP, forma_envio VARCHAR(25) BINARY, forma_pago INTEGER(2) NOT NULL, observaciones TEXT, total_pedido DECIMAL(7,2) DEFAULT 0, INDEX ped_cli (cliente), INDEX ped_fp(forma_pago), CONSTRAINT fk_cli FOREIGN KEY (cliente) REFERENCES Cliente(nif) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fk_fp FOREIGN KEY(forma_pago) REFERENCES Forma_Pago(forma_pago) ON DELETE RESTRICT ON UPDATE CASCADE

Page 151: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ 0$ � ���� ��

) TYPE = InnoDB; CREATE TABLE LineaPedido ( npedido INTEGER(5) NOT NULL, nlinea INTEGER(4) NOT NULL, referencia VARCHAR(15) BINARY NOT NULL, unidades DECIMAL(4,2) NOT NULL, precio DECIMAL(4,2) NOT NULL, dto DECIMAL(2,2), und_pend DECIMAL(4,2), und_serv DECIMAL(4,2) , PRIMARY KEY (npedido, nlinea), INDEX ped_lpe( npedido ), INDEX ped_art( referencia), CHECK ( precio > 0 ), CHECK ( dto BETWEEN 0 AND 1 ), CONSTRAINT fk_ped FOREIGN KEY (npedido) REFERENCES Pedido(npedido) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fk_art FOREIGN KEY (referencia) REFERENCES Articulo(referencia) ON DELETE RESTRICT ON UPDATE CASCADE ) TYPE = InnoDB; CREATE TABLE Ped_Rep ( npedido INTEGER(5) PRIMARY KEY, dni VARCHAR(10) BINARY NOT NULL, INDEX ped( npedido ), INDEX rep_rep( dni ), CONSTRAINT fk_pere FOREIGN KEY (npedido) REFERENCES Pedido(npedido) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fk_rep FOREIGN KEY (dni) REFERENCES Representante(dni) ON DELETE CASCADE ON UPDATE CASCADE ) TYPE = InnoDB; CREATE TABLE Albaran ( nalbaran INTEGER(5) NOT NULL PRIMARY KEY, cliente VARCHAR(10) BINARY NOT NULL, fecha DATE NOT NULL, forma_envio VARCHAR(25) BINARY, forma_pago INTEGER(2), total_albaran DECIMAL(7,2), INDEX alb_cli (cliente), INDEX alb_fp (forma_pago), CONSTRAINT fk_clialb FOREIGN KEY (cliente) REFERENCES Cliente (nif) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT fk_fpalb FOREIGN KEY (forma_pago) REFERENCES Forma_pago (forma_pago) ON DELETE SET NULL ON UPDATE CASCADE ) TYPE = InnoDB; CREATE TABLE LineaAlbaran ( nalbaran INTEGER(5) NOT NULL, nlinea INTEGER(4) NOT NULL, referencia VARCHAR(15) BINARY NOT NULL, unidades DECIMAL(4,2) NOT NULL, precio DECIMAL(4,2) NOT NULL, dto DECIMAL(2,2), npedido INTEGER(5), nlineap INTEGER(4), INDEX lin_alb(nalbaran), INDEX alb_art(referencia), INDEX lin_ped(npedido, nlineap), PRIMARY KEY (nalbaran, nlinea), CONSTRAINT fk_alb FOREIGN KEY (nalbaran) REFERENCES Albaran(nalbaran) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT fk_artalb FOREIGN KEY (referencia) REFERENCES Articulo(referencia) ON DELETE RESTRICT ON UPDATE CASCADE,

Page 152: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ 0�� ���� ��

CONSTRAINT fk_albped FOREIGN KEY (npedido, nlineap) REFERENCES LineaPedido (npedido, nlinea) ON DELETE SET NULL ON UPDATE CASCADE, CHECK ( precio > 0 ), CHECK ( dto BETWEEN 0 AND 1 ) ) TYPE = InnoDB; CREATE TABLE Factura ( nfactura INTEGER(5) NOT NULL PRIMARY KEY, fecha DATE NOT NULL, cliente VARCHAR(10) BINARY NOT NULL, INDEX faccli (cliente), CONSTRAINT fk_clifac FOREIGN KEY (cliente) REFERENCES Cliente(nif) ON DELETE RESTRICT ON UPDATE CASCADE ) Type = InnoDB; CREATE TABLE AlbFac ( nalbaran INTEGER(5) NOT NULL PRIMARY KEY, nfactura INTEGER(5) NOT NULL, INDEX alb (nalbaran), INDEX fac (nfactura), CONSTRAINT fk_albfac FOREIGN KEY (nalbaran) REFERENCES Albaran (nalbaran) ON DELETE RESTRICT ON UPDATE CASCADE, CONSTRAINT fk_fac FOREIGN KEY (nfactura) REFERENCES Factura (nfactura) ON DELETE RESTRICT ON UPDATE CASCADE ) Type = InnoDB; CREATE TABLE Efectos ( nfactura INTEGER(5) NOT NULL, nefecto INTEGER(3) NOT NULL, fecha DATE NOT NULL, fecha_vto DATE NOT NULL, entidad INTEGER(4), sucursal INTEGER(4), dc INTEGER(2), cc INTEGER(10), INDEX FacEfe (nfactura), PRIMARY KEY (nfactura, nefecto), CONSTRAINT fk_fact FOREIGN KEY (nfactura) REFERENCES Factura(nfactura) ON DELETE CASCADE ON UPDATE RESTRICT, CHECK( fecha_vto >= fecha ) ) Type = InnoDB;

Añadir registros con SQL directamente en el entorno de MySQL

���� ��� �� ��� ��� ���� ��� �� ��� ��� �������� �������� ��� ��� �������� ������������������.:&"/'��&������%���$�

INSERT [LOW_PRIORITY | DELAYED] [IGNORE][INTO] tabla [(lista_columnas)] VALUES (valores_de_datos);

���� ��� ������� �>W@-/.>/.'[� �� ������� ��� ��������� ����� ���� ������������������������ �� ������� �����"�1["�����������������#�������������������������� ����� ���������� ��������������� .3:>/"� �#�������� �� ��������� #������ �����#�� ������ ��� ������� ��� �������� ��� ����� ����������� ���� ����� �� ��������������#��������������������������� ������������������������ ���������������������������

INSERT INTO Cliente VALUES (‘30000001ª’, ‘Supermercado María’, ‘San Jacinto, 3’, ‘Córdoba’, ‘Córdoba’, 957000000, null ); INSERT INTO Cliente

Page 153: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ 0(� ���� ��

VALUES (‘30000002ª’, ‘Comestibles Javier’, ‘San Juan, 2’, ‘Córdoba’, ‘Córdoba’, 957000001, null ); INSERT INTO Familia VALUES (‘CONF’, ‘Confiteria’); INSERT INTO Articulo VALUES (‘CONF0001’, ‘Magdalenas la Bella Easo’, 1.5, 0.60, 300, 15, 500, ‘CONF’); INSERT INTO Articulo VALUES (‘CONF0002’, ‘Magdalenas con chocolate’, 2.5, 1.60, 300, 15, 500, ‘CONF’); INSERT INTO Articulo VALUES (‘CONF0003’, ‘Palmeritas con crema’, 1.25, 0.40, 300, 15, 500, ‘CONF’); INSERT INTO Pedido ( cliente, fecha, forma_envio, forma_pago ) VALUES ( ‘30000001ª’, ‘1-ENE-04’, ‘Agencia SEUR’, 1 ); INSERT INTO LineaPedido VALUES (last_insert_id(), 1, ‘CONF0001’, 40, 1.15, 0.2, 40, 0 ); INSERT INTO LineaPedido VALUES (last_insert_id(), 2, ‘CONF0002’, 10, 2.5, 0.2, 10, 0 ); INSERT INTO LineaPedido VALUES (last_insert_id(), 3, ‘CONF0003’, 25, 1.25, 0.2, 25, 0 ); INSERT INTO LineaPedido VALUES (last_insert_id(), 4, ‘CONF0004’, 21, 1.75, 0.2, 21, 0 ); INSERT INTO LineaPedido VALUES (last_insert_id(), 5, ‘CONF0005’, 5, 2.75, 0.2, 5, 0 );

���������� ��� ��#������������ ������� ���������� ������������������������ �� �� ����� � ��� �� �� ���� �� ��� #������� �� ������������ �� ����� ����� ������ ���=�&?������������������������������������������������������

2��� ���������������������� ������� �� ������������&?�������� ��������������� ��� ���� ���� .:&"/'�� ��� ��� �������� �� ��%��� ���� �%������� ����� ����������������������������������������������������������������� ���������������

-��� ��������� �� ������� ��� ��������������?���� ���� ��������� ������ ���������� ������������� �������������������������������������������������� ���� ��������������������� ������������(�����!���� ������� �������������� ���������2���-�������������� � �����#������� ������� �� ��=&5�>&����� ��������������$�

�!����U�����U����������A�������?����

"������������ �������(�����!���� ������� ���������������������������� ���������)�� �� �������� �� ������������ �� ��� ��� �� ���� ��������� ������ ������� ���������������)�����������������������������&?�� ��������#��������?�������������������

"������� ������� �� �������� �� ���� �� ������ ��� �������� �� �������(� ����!���� ������� �������������������� ������ �� �����������

Page 154: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ 0*� ���� ��

Incorporar datos externos a tablas MySQL con LOAD DATA

"%��������������� ������������� �������#�������������� ��� ������ ��� �� ����� ���� �����(� �� ��� ����������� �� ���� �� #�������� �� �������������������� ��� �����(��� ��� ��������� &?�� �>1���1'1�� ��� ����� ���� ��� �������� �� ��������#�� ��%��� �� ��� ������ ����� ���#�������������� �� ����"��� ��������� ������� ������.:&"/'��&������%�����������������������$�

LOAD DATA [LOW_PRIORITY] [LOCAL] INFILE ‘nombre archivo’ [IGNORE | REPLACE] INTO TABLE nombre_tabla opciones de importación [IGNORE n LINES] [(lista_columnas)]

�>W@-/.>/.'[� ������� ��� ��������� ������������������������ ���� ����� �� ������� �����>�1����������������������������������#������������ ���������������#!����������� ����������� ������#� ����.3:>/"����#�������������������� ��������#��������� ��� !� ���� ������ ���� ������ ��� �������� ���� /"-�1�"� ���#���� ���� �����������(� ������%��������

����������� ����������������� �������������������������%�$�

[FIELDS [TERMINATED BY ‘cadena’] [OPTIONALLY] ENCLOSE BY ‘carácter’] [ESCAPED BY ‘carácter’]] [LINES TERMINATED BY ‘cadena’]

&�������,."��&��������������������'"/=.:1'"��;[�* ���� ����������������������������� ���������#������ ������ ����������+��":��>&"��;[�*��������������������� ������������ �� ���� �� ������ ��� ������ ��� ������ �� #������ �� �� ���>-'.>:1��[+� �� "&�1-"�� ;[� *���������� ��� �������� �� ������ �� ��� ������������������+��,."��&�������� � ������� ������.:"&��

�.:"&�'"/=.:1'"��;[��������������������������������������������������������� ������!�����&���������������������,."��&�����.:"&�����#���������� ���������� ��������������� �������������� �� ��������������������$�

FIELDS TERMINATED BY ‘\t’ ENCLOSED BY “ ESCAPED BY ‘\\’ LINES TERMINATED BY ‘\n’

�������%����������� �� ������������ ������� ��������� ������ ������ �!�������� ������� �������� ���������������������� �������������� ���������� ��� �������#���� ��������������� �������� ���!������P���

"����������� ��������������������� ��������(����������������$�

&��� ���� .���� ����

`H� 1&�..�H�

` � /��������

`�� �!�������#��

`�� /������� ��������

Page 155: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ 00� ���� ��

`� "������

`�� '� ��� ���

`b� ��������������

`F� �������� � ���

``� ;�������#���� ��

��� ����%�� .3:>/"��� �.:"&� �� �������� �� �������� ��� ���������� �!���� ��������#�� ������� �� �� �����

&���������������������(�������������!���� ������� �������� ������#����������������� ������� ��� �� �����&����������������������� ������������� ��� �� ������������� ������ ������ ��� �!���� ������� �� � ��!��� �� ������������#����������� ���������� ����� �������� ��������#��������� �������� ������������������������ ��������������

<��������� �������������������� ����� ����������������#��������������� ��� ������������$������������-���������������������������������������?�2��������������������������������!$�

‘30000001ª’,’2005-01-01’,’Agencia SEUR’,’1’,’0.00’

���#������������������������ �������������������� ������������������������ ��� �� ��� �������� �������� ���'��� ����(����� ����(�� � ������(�������?����������������������� �� �����12'>@.:�/"=":'���!���������������� �������������� =�&?�� ��� �������� ���������������� &�� �%������� ������� ������������� ����� #����� ��� ���������� ��� ��� �������� �� ��������!�� ���� �� #����� ���� �������������#�����:2����

-���� ����� ����� �� �� ���� �������� �� �!�� ���� ���� ��� ��� ������������������&?�$�

LOAD DATA INFILE ‘albaran.txt’ INTO TABLE albaran FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSE BY ‘\” LINES TERMINATED BY ‘\r\n’ (cliente, fecha, forma_envio, forma_pago, total_albaran);

-������������������������ ������������������������ ��������������$�

LOAD DATA INFILE ‘lineaalbaran.txt’ INTO TABLE lineaalbaran FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘\” LINES TERMINATED BY ‘\r\n’

�������� ���%����� ��%����%����&�� ������������&�� �����

"%���� ��� ������ �� ��������� ��� =�&?�� ���� �� �����(��� ����� ������(����� ���������������� �������� �������������������������

��� ��������� >-'.=.\"� '1;�"� ������(�� ��� ������� ����� �� �� ���� �� ����������� �������������� �������� ������������)�������������&������%���������������$�

Page 156: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ 0�� ���� ��

OPTIMIZE TABLE nombre_tabla

������������/"-�1�"���������������.:&"/'�����������#� � � ���������������������������������������#�������������!� ����2:.?2"���������� ����������#������������������������������������ �������#��������������� ���������� ������������#���� ������� *������ .3:>/"� ��� ������ ���� �� ���!+�� &�� ����%�� ��������� �� �����������$�

REPLACE [LOW_PRIORITY | DELAYED] [INTO] nombre_tabla [(listas_columnas)] VALUES (valores_de_datos);

�����������������������������������(��(���������������������������������������� ������������ ����"����������������(������������������������ ����������� �������� ��� ������������������� ��������(������������������������������ ����� ������� �� ���������� ����� &�� ��� �� ���������� ����(����������� �� ��� �������� �� ��� �� ��� �� #���� ���� ��� ����� ���� �� ����(�������� ������������� ������������� ������� �����#�����������������#����� ��:2���*�����#����� ��� �������� �� �� �� ��� ����� �� ������� ����� ��� �������+� ��� ���������������� ���� ��� �� ������ ������� �� ��� ��� ������ '� �� ��� �������� ������������ ������������� ���������� � ������������#������:2��������������#�������� �������� �� ����� ��� ��� ������(��(����� �������� �� � ����������� ���������������� �����������"��������� ��#������ �� ���� � ��������������������������� ��������������� ����� �� ���������������������� ���� ��#����� �� ���� � �������� ���������� ��������������������� �������&��������������������������������� ����� ������� ����

1�� ������ ���� ��� ��� ��������� .:&"/'�� ������ �����(���� �� ������������� ��/"-�1�"� ������������>W@-/.>/.'[� *���#�������� ��� ��������������������� ����������������������������������� ������� ��+����"�1["��*�������������������������������������������������������+��

��� ��������� &"'� �� �����(�� ����� ����������� ������� ��������� &�� ����%���$�

SET opciones;

��� �������� #��� ����� �� ���� ������ 1������ �� ��� �������� ��� ������ ����������� ������������)�� ����������

SET PASSWORD FOR usuario = PASSWORD(“contraseña”)

"����������%���� ������������ �#��#����������������������&"�"�'�

SET SQL_BIG_TABLES = n

�������������>�X�'1;�"�*���>�X�'1;�"&+� ������������������ ��� �� ����� ��� ���&������%���������������$�

LOCK TABLES tabla1 [AS alias] {READ | [LOW_PRIORITY] WRITE}, tabla2 …

/"1�� �� ������� ������� ������ ������������������������������������ ������� ��� ��� ��� �� ��� ����� !� �������� W/.'"� �� ���� ��� ������� �� ��������� ��������� ��� ��� ������ �� �������� �� ��������� �� ��� �������� �� �>W@-/.>/.'[� �� ��������� �� ����� �������� ����� ����� ��� �� ��� ���� �� ��� ������� ��� ��� ����� ���������������

��� ��������� 2:�>�X� '1;�"� *�� 2:�>�X� '1;�"&+� �� ���� ���� �� ��� ������ ���&������%���������������$�

Page 157: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� �� �R+ / �< & � � � � � ���$ 08� ���� ��

UNLOCK TABLES tabla1, tabla2, …

��� �� ���� ��� � �� � �� �� ��� �� � � ��� ��� � ���#� ���$%��������������� ��

������������&�>W���� ������#������������������������������������������ �� ��� ��� �� ����� �� ��������������!� ������!������� ��� ��� ���������� �����#� ���� 1������ �� ���� ������ ���#������� ������� ���������,/>=������(����������������������������� ��� �� ���� ����������� ����� ������������������*������ ������� ��� ��� ��������� �� ���� ��� ��� �� ���� ��� �������� �+�� �����������.X"��������������������� �������#����������������������������*�� ���� ��#������k���@+���������%���$�

SHOW COLUMNS FROM nombre_tbla [FROM nombre_bd] [LIKE patrón] SHOW DATABASES [LIKE patrón] SHOW GRANTS FOR nombre_usuario SHOW INDEX FROM nombre_tabla [FROM nombre_bd] SHOW PROCESSLIST SHOW STATUS SHOW TABLE STATUS [FROM nombre_bd] [LIKE patrón] SHOW TABLES [FROM nombre_bd] [LIKE patrón] SHOW VARIABLES [LIKE patrón]

"��� #�������� �� &�>W��������� �������#������� ��� �������� �� ������ ���� ��� ��� �� ���� ��� ��� ���� ��� ��#� ���� ��� ������� ���� ��� ���#����������� �� �� ���� ��� ��������� 3/1:'�� ��� !� ���� �� ���� �� ���� ��� ����� ���� ����������� ��� ��� ��#� ���� ��� #���� ��� �� ��� �� ��� ��#� ��� �� �� #������������������� �������#��������� �� ��� �� ���������� ��� �� ���� *��� ���� ��������������� ������� �� ������ ����� �� ���������� ����+�� ����� �� �� ��� ������ ��� �� ����*������� ����� ����������������������������������+��� ��� ����� ��#���� ��� �����#� �������#�������

��� ��������� �"&�/.;"� ������������ ��� ����� ������������ ���� &�>W��>�2=:&��&������%���������������$�

{DESCRIBE | DES} nombre_tabla {nombre_columna | patrón}

������������"0-�1.:�����#������&�>W��>�2=:&�,/>=��&������%���$�

EXPLAIN nombre_tabla

1� �������������� �� �������� #����� ��������!����� �� ��� ��� �� �������� �����������������

SHOW TABLES; SHOW COLUMNS FROM Cliente; SHOW COLUMNS FROM Albaran; SHOW INDEX FROM LineaAlbaran; SHOW DATABASES;

Page 158: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 0 � ���� ��

/� � + � �� � � � + � ��� � ) � 0 �� �� � �� � � � �� � �� �� �� � ���

�����������

������� ��� ��������� &?�� *�����������G���!� $�� �� �+�����=�&?�� �����(������� ������� ��� ������������� ������ ���������� #����� �������!�� �� ��������� *������� �+��"�� ��������� �� �������� �� �����?��9�����G���!�$�� �� �<��������� ���������� ������ ���� ���� ������������������������������������������������������������������&"�"�'��&�������� ��������������� �������������!��������������������������� �� �������� ���������� ������� ���&?���

"%����� ����� �������!�� �� ��������� &?�� ����� ��� ��������� ��=� ���������� ��������=��9�������������$�� �� �<������������������������ ��� �������������� ��������������� �� ���� ��� ������� �� ��� �� ���� ����%�������� ����� �������� ��������!����� ������� ��� ��������� .:&"/'��2-�1'"���"�"'"����/>-��

>�����������!�� �����������&?����������������� ������������� ����������� 9����� ������� $�� �� �<� !� ��������� �� �������� �� ����� ���� 9�������������� ����<�������������� ������������ �� ���������� �� �����������(������������������������� ������� ����� �� ��� �� ����������������� ���������������������������������������������!�������������������������/"1'"��1�'"/����/>-�������������� ������������ ���������� �� �����������(����������������� �� ������ �� ���� ��� ��� ��� �� ����� ����� �������� ��������!�������������������� ��3/1:'���/"<>X"��"�����������������!�� ������������������ �������������(��������������!����� ��� ������������ ����� ��� �� �����

"�� ���� ���!����� �� ������� ��� ��������� ��� ��������� �� �� ���������� �� �������������!�������������������������������������������!���

� �������� ��������

"�� ��� ���!����� V� �� ����� ���� ���� #������ �������� �� ��� ����%�� �� ������������&"�"�'��;��������� ���������%����� �������������������$�

SELECT [DISTINCT | ALL | Otras opciones ] lista_selección [INTO OUTFILE ‘nombre_ fichero’ opciones exportación] [FROM tabla origen [,tabla_ origen] ... ] [WHERE condición de búsqueda] [LIMIT m, n] [GROUP BY expresión_ de agrupamiento] [HAVING condición de_ búsqueda] [ORDER BY expresión_order_by [ASC|des]]

��� ��������� &"�"�'� ��������� ����� �� �������� *��� ��������� �� ��� ����(���������<� ���������� �� ��� ��������� ����� ����������,/>=����������������� ��� ������� �� ���� �� ��������� �� ��� W�"/"�� ������ �� ����� ����%������� ��������������� ��3/>2-�;[���������� �������� ������� �� ���� �� ���1<.:3����� ��� ������������������� �����>/�"/�;[��1������������������

Page 159: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 0-� ���� ��

�#��#������ ����������������������������� ������� ��W�"/"�*�����#��������� ������+����.&'.:�'�������������� �������� ������ �������� �#��#��������#�(���.&'.:�'����������� ���.&'.:�'/>W��

������������&"�"�'�� ����������� �� ��� ��� �� �������������������(��� ������������ ��������#�������������������� ��������#������� �����������%����������� �� ��� ����������� &"�"�'� �� ���������� &�� ������� ����������� �������(���������������������������

Cláusula SELECT

����������&"�"�'����������� ��� ������������#���� �#��#��� ��� ���������"�� ������� �� ��� �������� �� ���� ������� ��� � ���� ���� 1��� ���������� ������� ��� ��������� ����� ������ �� ��� ��� ��������� �� ������ �� *#�������� �������� �+� �� ���� �.&'.:�'� ���������� ���� ���� ��� ��� ��������� ������%����#����������������� �������� ������#������:2��������� ��������������������� �� ��� ���� ��� ���#�� �.&'.:�'�� -�� ��� ����� ����� �������� ���������������� ����� �.3@-/.>/.'[� ���� �� �� ��� ����������� &"�"�'� ���� ������������ � �� ����������������������.:&"/'���2-�1'"�������� ����������� �������(� �� ���� ������ ����� �������� � ��� �������� �� ���� >���� ������� ��� ��� ��&'/1.3�'@A>.:����������(��������� ������������ ������������������ ������� ���������������,/>=��>���� ����������������������������&?�@;.3@/"&2�'���&?�@&=1��@/"&2�'� ���� ����������� ���� ��� ������ �� � ���� �� ��� ��� ���������&"�"�'� �� ��������� �� �� �� �� �%����� *���� �� �����������+� �� ������� ����������#��������

"�� ��� ������� &"�"�'���� ������������� �� ��� ��������� �� ����� ��� ����� ��������������� �������� ��� ������������ �� #��� �� ����������� ����� ��� ��������� �������� ������� ����������������� ��������������������� �������������� �������������� ���%������������� ����������� �� ���� ���%���������� �������� ��� ��� �� ��������� ���������� ��������� �� ���� ��� �������� �� ��� ��� �������������������������������������� ���� ����������� �����

��� ����� �������������� ������� ����� ����%�������(��������� �� ��������� ����� ��������� ���������� ������� ��� ���������� ������� ������ �������� )�'������ ����������������������������(����� ����������� ����������� �������� )�'(��������������������� ���������������������������������� ��� ������� ������ ���� ��� �0������� �����5� ��� ���� ���� ������� ����������� �� e� �� ��� �� ��� ��������� ��� 1�� ����������� ��� �������� ��� ��� ����� ����������� �� ���#�������� ������ ��� ��� ��� �� ��� �� ��� ����� �� ��� �� ����������� ����� �� ���� ��� ������ *���������+� ����� �#����� �����(��� ���� ������������� ���������������������� �� ���� ��� ������������,/>=���������������� ��� ���������� ����

-��������������������� �������������� ������� ����������������� ��� ��������������%���� �������������������?������������?�

����� ��� ��� ��� �� ���������� �������� �� ��� ����� �� ��������� ��� ���������������������� ������������� �������������������1&������������?��������%���������������������� ������������#��������������(��������� ��� �� �������������������������� �������� �� ������������������������� �����������(�������� ����������� ��� ��� ����� ��� ������ �� �� �%��������� ��� ����%�� ������������ ��� �� �����(���� ��� ���� ������� >/�"/� ;[��3/>2-� ;[� �� �1<.:38� ����� ������������ �������(������������������W�"/"��

1�����������������%����������������������

Page 160: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �� � ���� ��

Listar todos las columnas de la tabla Cliente SELECT * FROM Cliente; SELECT Cliente.* FROM Cliente; Listar el dni de todos los clientes que han hecho pedido SELECT DISTINCT cliente FROM Pedido; Listar el número de pedido, fecha y total SELECT npedido, fecha, total_pedido FROM Pedido; Listar la referencia, descripción y precio venta de los artículos SELECT referencia, descripción, precio_venta FROM Articulo; Listar el número de factura y fecha de todas las facturas SELECT nfactura, fecha FROM Factura;

Cláusula INTO

��� ������� .:'>� >2',.�"� �������� ���� ��� ��� ������ �� �� ��� �����������&"�"�'������������#����������'��?��������%���$�

"�� ��� ��� ��� �����#�� *���� ��� � �� �%����� ���#�������+� �� �������������� ���������������������������������� ��������������#�������������������>1���1'1�#�������������!���������������"�� ��������� ���������%�� ������������������ �2�������� �� ������ ���� ����� ��� ������� ������ ��������� �� �������������>1���1'1�#�������������!���������������

"�� �������#��� ��� ��������� .:'>� >2',.�"� �������� �������� ��� ��������� ��������� ���� ������������ �� ��������������-����������$�

Listar la razón social, dirección, población y provincia de los clientes y almacenarlo en un fichero, llamado Clientes.txt. SELECT razon_social, direccion, poblacion, provincia INTO OUTFILE ‘Clientes.txt’ FROM Cliente; Igual que antes, pero los campos separados por comas y sus valores encerrados entre comillas dobles. SELECT razon_social, direccion, poblacion, provincia INTO OUTFILE ‘Clientes.txt’ FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘\”’ FROM Cliente;

Page 161: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �$ � ���� ��

Cláusula FROM

"��� ������� ���������� ��� �� ��� �� �� �� �� #��� �� � ������ ��� ������ ���������� ,/>=� �� ��������� �%������ ���� �� ��� ����� �� ��������� ���� ������������������� #���� ���� �%�������� ����������� *��� ��� ��� �� �������+� ���%�������� ��������e��

&������%�� �����������������$�MFROM lista tablas]

����� ����������������������������#�������� ��� ���� �������� ������������ ��� ����� ���� &"�"�'� �#���#�� �� �� ��� ��� ��������� ��� ��� �� ����� � �� ������� ����

-���������������� ������(����������� ������������� ������������� �������� *��� #�(� �� ���� ����+�� "��� ������� ��� ��� ��� A>.:�� �/>&&� A>.:��.::"/�A>.:��&'/1.3�'�A>.:����",'�A>.:��"������������A>.:��� ������������� ������������ �����,/>=� � ������ �������'�� ������� ��������������(��� ������������ ���������� ���������1����������%���������������� ������ ��������������������� �!����������������� �������������$�

nombre_ tabla [CROSS] JOIN nombre_ tabla nombre_ tabla INNER JOIN nombre_ tabla nombre_ tabla STRAIGHT_JOIN nombre tabla nombre tabla LEFT [OUTER]JOIN nombre tabla ON expresión_ condicional nombre tabla LEFT [OUTER]JOIN nombre tabla USIGN (lista_ columnas) nombre tabla NATURAL LEFT [OUTER]JOIN nombre_tabla nombre tabla [CROSS] JOIN nombre tabla

�",'�A>.:��������������� � ���� ������ ��������� ������������������������������ ��������������� ����(����� �����������������������#��������������� ��� ������������ �� ��� ������ �������� ��� �������� �� ��� �� ��� ������� �� �#���#��� �����#������ :2���� ��� ����� �������� �� ��� ��� ����������� �� ����� �� ���� ������ ������ ��������� �� ��� ��� ������� >:� �2������� �������� � 2&.3:�9������������<?� ��� �%������� ��� �������� �� ���� �%������� ���� �� ��� �� ���� ��� ����������W�"/"��� ��� ����� �� �������������������� ��� ��������������� ��������������� � ������������������ ���� ������ ���

�",'�>2'"/�A>.:�����#�������",'�A>.:����:1'2/1���",'�A>.:�����#�������",'�A>.:�2&.:3�9����(��������<�� �� �������� ��� ���������� ������������������������� ���� ����

�/>&&� A>.:����������� ��� ��� ����� ���������� �� �� �� ���� ��#���#�� �������������� �#��#��!����� ��� �� ������������ ������� �� ���������� ����������,/>=�������������������������������W�"/"��

.::"/�A>.:����������������� �#���#����� ���������� ������������� ������� ������������������������ ����� ����� ���� ����"��������#��������������� ������������������������������� ����� ���������

&'/1.3�'�A>.:�����(�����������(� ��������������� ����������� �������������������

"���������#������� ��&?���������",'��/.3�'���,2���������������������� ������� �(����� ��� ������� �� ��������� �� ��� �� ��� ��������� ��� �",'�

Page 162: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ ��� ���� ��

M>2'"/O����������������� ���������� ������� ��� ������(����� ����������������������� ��������������� ���� ������������������������ �� ������ ���� ��� ���� ����� ����� ���� �#���#�� ��� ��� �������� ��������� ��� �������� �� ��� �� �� ����(����� ������� ��������:2����/.3�'�M>2'"/O����������������� ���������� ������� ��� �� ��� ������� ���� ��� �������� ��� ��� ������ ��������� �� �� ��������� ��� ������������ �������� ���� ��� ��������� �#���#�������� �������������������� ����� �� ������� ��� ����� ������������ ��������:2����,2���M>2'"/O��������������� �� ���� ����� �� ��� �� ��� �� ��� �(����� �� �� �� ��� ������� ��� ������ �� ���� ������������ ��������������������������������������������� �������� ��������������� �������� �������������� ��������������� �������� ��(���������:2����&�������� ������� ���������� �������������������������� �#���#�������� �����������������

"��������!�������������������������������� ���� ��� ���������%����������%��� �������������

Cláusula WHERE

"���������������� ������ �� ���� ������� ���������� ��� �����������#����� �#��#����&������%���������������$�

[WHERE <condición_búsqueda> | <nombre_columna {*= | *= } nombre_columna>]

"�����������������������/���������������������� �#��������������������� �������� ���� ������������ ����� ��� ���:�������!������������������ ������������� ��������������������� ������ �� ���� ���"�������������������V�W=�S�=�W�X������(������� ���������� ���� ��� �������� �%������ ���� ��� ����%�� ������������!����� &?�� &��#��� �� ��� ������� W�"/"�� &�� �����(�� ��� ����� ��� H� ��������� �� ��� ��� ����� ��� �0����� �#�������� �� ��� ��������� H� ���������������� ���� ��� �������� �%������ �������� "�� ��������� �� ������ �� ��� ������������� �������1<.:3����.=.'��

1�����������������%����������������������

Listar todos los clientes de la provincia de Córdoba SELECT * FROM Cliente WHERE provincia = ‘Córdoba’; Listar todos los albaranes de fecha 2 de enero del 2005 SELECT * FROM Albaran WHERE fecha = “2005-01-02”; Listar todos los pedidos cuyo número sea superior a 5 y la forma de pago inferior a 3 SELECT * FROM Pedido WHERE npedido > 5 AND forma_pago < 3; Listar todos los artículos pedidos (sin duplicados) con precio superior a 1 � o tengan un descuento del 10% SELECT DISTINCT referencia FROM lineapedido WHERE precio > 1 OR dto = 0.1;

Page 163: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �(� ���� ��

Listar todos la referencia, unidades precio, descuento e importe de venta de los artículos vendidos con importe superior a 5� o no tengan descuento. SELECT referencia, unidades, precio, dto, unidades * (precio - precio * dto) AS importe FROM lineaalbaran WHERE unidades * (precio - precio * dto) > 5 OR dto = 0;

Cláusula GROUP BY

"������������������������������#����������(�������������� ����� ������������ �� ����������������� �������� ��������>2:'���=10���� ����������&"�"�'������(��������������������� #����� ��������� ���� ������������� ��������������3/>2-�;[���� �����������������������������%������� �������� �� ���������� ������������� � �� �������� ��� ��� ����� ��3/>2-�;[��� ��� �%�������3/>2-�;[� � �������� ����%������������������%������� ���������� ������������&������%���$�

[GROUP BY expresión de agrupamiento]

����%������� �����������������������������%������������������������(������������������ �� �������� �� ������������� �� ��� �� ��� ���� �������� �� �����%������� ��������������� �������� �������������������������������������:������� �� �����(��� ��� ����� �� �������� ��� ��� ����� �� ��������� ����� ����������� ������������ ����������������

&�� ��� �� ���������� ��� ������� >/�"/� ;[�� ��� ������ �#������ ���� ����������3/>2-�;[������������������ ���������������&���������� �������������������������������>/�"/�;[�����3/>2-�;[���������������������� ��� �������� �� ����� �����1��������������#��������������������$�

Listar la referencia y el total de unidades vendidas por artículo SELECT referencia, SUM(unidades) FROM lineaalbaran GROUP BY referencia; Listar la referencia y el precio medio por artículo pedido. SELECT referencia, AVG(precio) FROM lineapedido GROUP BY referencia; Listar el precio máximo y el mínimo de un artículo por pedido SELECT npedido, MAX(precio), MIN(precio) FROM lineapedido GROUP BY npedido;

Cláusula HAVING

"��������� ���� ��� ������ �� ���� �� �� ��� ������ �� ������ �� ���������������������(����������������3/>2-�;[������ ������������(��3/>2-�;[���1<.:3���������������������������W�"/"��&������%���������������$�

[HAVING condición búsqueda]

Page 164: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �*� ���� ��

"�� ����������������� �/������� ���������� ��� ��� ������ �� ���� �� ����������� ��������� �������� � �����������

�1<.:3� ���������� ���� �%������� ���� ��������� �� ��� ����� �������� ����� ����� �� ���� ���� ������ ��������� ��� ��� ������� ���� �� ��� ��� �������W�"/"�� ��� ��������� ��� ��������� ��� ��� �������1<.:3� ���� �����(� �� ��� ��������� �� ��������������

�1<.:3�����������������%����������������������������� ��������������� ��� ��� ��� ��� �%����� �� ���� ��� �������W�"/"�� ��� �� �� ������� �� ������� ������ �� ���� �� �� ������ ������ ��� ��� �������W�"/"� ����� ��� ��� ��������1<.:3����������� ����������������������������������!�������������������� ����������������������(� ����

Listar el número de pedido, importe total del pedido que superen 700 �. SELECT npedido, SUM( unidades * (precio - precio * dto) ) AS importe FROM lineapedido GROUP BY npedido HAVING importe > 700; Listar el número de albaran, media de las unidades vendidas por albarán que sean inferior a 30 unidades. SELECT nalbaran, AVG(unidades) AS Unidad_Media FROM lineaalbaran GROUP BY nalbaran HAVING Unidad_Media < 30; Listar la referencia de artículo, unidades mínimas pedidas de cada uno, si son superiores a 10; SELECT referencia, MIN(unidades) AS Unidad_Minima FROM lineapedido GROUP BY referencia HAVING Unidad_Minima > 10; Listar la referencia de artículo, precio máximo vendido de cada uno, si es igual a 1.5 SELECT referencia, MAX(precio) AS Precio_Maximo FROM lineaalbaran GROUP BY referencia HAVING Precio_Maximo = 1.5;

Cláusula ORDER BY

���� ���� ������� �� ���������� ��� �� ��� ��� ��������� �� ������ ��� ����������>/�"/�;[������#�� �����#����� ������������ �!������� ��� ���#� ������ �����������#���������������������� ����'>-��&������%���������������$�

�ORDER BY { expresion order by [ASC|DESC] }[ , ...n] ��

"�� ��������� �2������� ����� �! ���������� ��� �������� ����� ��� ���� �������(������� ���������&����� ������������������������� ���� �������������� ���������� ����������*������� ��������������� ������������ ��� ������ �� ��+�������%�������������������#������� ��&?���������������������#�������������������

Page 165: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �0� ���� ��

�������� ������ ������������%������������������ ������������'�� ��������� �������������� #����� �������� �� �� ���� ��� ��������� �� �������� �� �� ��� ��� ���������� >/�"/� ;[� ������ ��� ���������� ��� ��������� �� ��� �� �� ������ ��� ���������� >/�"/� ;[� ��� �� �������� ��������� ���� ��� ��������� ��� ��� ����� ������������ &��� �� ������ �� �� ���������� &"�"�'� �.&'.:�'�� �� �� ��� �����������&"�"�'������������������ ���2:.>:��������������� ��� �� � ������������������ ����� ������������1 �������� �� ��� �����������&"�"�'������������������ ���2:.>:�� ������ ����� �������� ������������� � ������ ������������ ����� ���������������� ������������

"�� ���������� 1&�� �� ���� ���� ��� #������ �� ��� �������� ��������� �� �� � ����� ����� ������������� �����*�� ������� ������+�� � �����#������� ���������������"�������������"&���� �����������#������ ���������������������� ���� � ��� �� ����� ��������� ���� ������ � �� ��� #������� ����� ��� #������� ��������#������:2��������������������#�������� ������� ����:�������!�������������������� �������������������������>/�"/�;[��

Listar los clientes ordenados por razón social SELECT * FROM Cliente ORDER BY 2; Listar las líneas de albaran ordenadas por número de albarán y precio SELECT * FROM lineaalbaran ORDER BY nalbaran, precio; Listar las líneas de pedido ordenadas descendentemente por número de pedido y ascendentemente por precio. SELECT * FROM lineapedido ORDER BY npedido DESC, precio; Listar los pedidos ordenados por fecha descendentemente SELECT * FROM Pedido ORDER BY fecha DESC;

Cláusula LIMIT

������������.=.'��������(����������������������������� ������� ������������ �������� ���&������%��� �������� ������������������$�

[LIMIT n] [LIMIT m, n]

������������������ ������%�� �#���#�� ������������� ����� �� �������������������� ��������� ������%�� �#���#���� ������������ �� ��� ������?�-�����.=.'������������������������(�� ���������H������������D��

Listar los primeros 10 clientes SELECT * FROM Cliente LIMIT 10; Listar los 5 pedidos con importe más alto.

Page 166: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ ��� ���� ��

SELECT npedido, SUM( unidades * (precio - precio * dto) ) AS Importe FROM lineapedido GROUP BY npedido ORDER BY Importe DESC LIMIT 5 Listar los 20 artículos más baratos SELECT * FROM Articulo ORDER BY precio_venta LIMIT 20; Listar los pedidos del décimo al trigésimo SELECT * FROM Pedido ORDER BY npedido LIMIT 10,20;

Renombrar columnas. Cláusula AS

&?����� �������(������������ ����� ��� ���������� ��������� ��������������������1&������ �������������� ���������� ��� �������������� ������������ �������� ���������������������� ������������������������ ������� ���� ������������������ ������������ �������� ���� ����������������������� ����������� �������� �����#����������� ��� ������������� ������������ �������� ���������������������� ��� �� ������������� �������������� ����������������� ����������1&������ ������������������������ ��� ����������������������������� ������������ �������� ���"�������� ��������������������� ���������������-��������������� ����������� ��������� �� ��� ������ �� ��� �����+������ ����� ��� ���� �� ���� ��������������� ��� &�� �� ���� ��� ������� 1&� ��� �� ��������� ����������� �������� ���������������� � �������������������������� ��������������1!���� ���������� ����������������������� ���������������������

SELECT npedido, SUM( unidades * (precio - precio * dto) ) “Importe” FROM lineapedido GROUP BY npedido ORDER BY 2 DESC LIMIT 5

1�������������������� �������(��������������������������������������� ���� ������������������������������������� �����������

������� ��������������������'� ��� �

&?�� �������� �����(��� ������������ ������������������ ��� �/������� ���� ��������������� ��������������������������������������� ����� ����������������� ������ ���������������� �������� ������������������������������������ ������� ��� ��� ������� �� ���� �� ������ ��������� ��� ���������� �������������*������������#����� �������%��������������#����� ������+������������������ � *�%������� �� ��� #����� �� �����%������� ���� ������ �� ��� ������ � �+��������������������������������������*������� �������#����� �������%����������������� �� ��� ��������� � �+�� ���������� ��� ������������� ��� �������

Page 167: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �8� ���� ��

*������� ��� �� ��� ���� �������� ��� ������� � �+� ������������ ��� ����� ����*������� ������%�����#������������������������+��

'� �� ��� �������� ��� �/������� ���� ���� ������������� ������ �� ����������W�"/"� ��������������&"�"�'��

Test de comparación

=� ������������� ���������������&?�����������������������#������ �� ���%��������&?��������� ������� �� ���������(�� ���������� ���� �������������� ��&?��*Z��^Y��^��^Z��Y��YZ+��-�����������

Listar todas las facturas con fecha posterior al 1/1/2004 SELECT * FROM Factura WHERE fecha > "2004/1/1"; Listar la referencia, descripción y precio de venta de los artículos cuyo precio de venta es inferior a los 2 �. SELECT referencia, descripcion, precio_venta FROM Articulo WHERE precio_venta < 2; Listar los articulos que no sean de la familia ‘CONF’ SELECT * FROM Articulo WHERE familia <> ‘CONF’; Listar los datos del cliente con nif 30000001A SELECT * FROM Cliente WHERE nif = ‘30000001A'

Test de rango: Cláusula BETWEEN … AND

"����������� ���������������� �������#����������������������� ��#������ � ���-�����������

Listar la referencia, unidades, precio y dto de los artículos pedidos que tienen las unidades entre 5 y 10 SELECT referencia, unidades, precio, dto FROM LineaPedido WHERE unidades BETWEEN 5 AND 10; Listar la referencia y descripción de los articulos con precio de venta entre 0.5 � y 3 � SELECT referencia, descripción FROM Articulo WHERE precio_venta BETWEEN 0.5 AND 3; Listar los articulos cuya descripción comienza por la palabra Bolsa SELECT * FROM Articulo

Page 168: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ � � ���� ��

WHERE descripcion BETWEEN ‘Bolsa’ AND ‘Bolsaz’;

Test de pertenencia a conjunto: Cláusula IN

"�������� ����������������� �������#����� � �������� ���������� ����������� ��#��������������� ���-�����������

Listar el número de pedido, referencia y unidades de los articulos que se han pedido con unidades 5, 10 o 15 SELECT npedido, referencia, unidades FROM LineaPedido WHERE unidades IN (5, 10, 15); Listar la referencia, descripcion y precio de venta de los articulos que pertenecen a la familia ‘CONF’ y ‘PESC’ SELECT referencia, descripcion, precio FROM Articulo WHERE familia IN (‘CONF’,’PESC’); Listar el número y fecha de los albaranes con forma de pago 1, 2 o 3 SELECT nalbaran, fecha FROM Albaran WHERE forma_pago IN (1,2,3); Listar los efectos de las facturas 1 y 5 SELECT * FROM Efectos WHERE nfactura IN (1,5);

Test de correspondencia con patro: Cláusula LIKE

����������� ���������� ������������������������������������������������������ �� �� ���� �������� �� ��%��� �� �������� �� ���� ��� ��%��� � ��� �� ������������� ��������#����� ������������������������������������������� ���"����������� �� ��������� � � ������ ��� ����������Y� ��� ��� �"�� ����� �����6��� -�����������

Listar la referencia, descripcion y precio_compra de los artículos cuya descripción comience por ‘Zu’ SELECT referencia, descripcion, precio_compra FROM Articulo WHERE descripcion LIKE ‘Zu%’;

������� �� ��� ������� �.X"� ������ ��� ������ ����������� ��� �6��� ����������� ����� ���� ���������� �%���������� ���� �������� �� ��������� ��� ���������� ������ ��� !� ���� k� �� ��� !� ���� � ���� �� ���� �� ����������#��� "��������� ����������!� ����k�������������������������� ���������������������������� � ���� �� ���� �������� ���� ����� "�� ���� �� ������� ��� !� ���� � ���� ��������� ��������� ���� �����(��� ��� ��������� �������� ���� ��� ��� !� ���� k� ������ ������������������� ����������������������� �����������-�����������

Listar el nif, razón social y direccion de los clientes que sean en cuya razón social aparece la letra ‘m’ en sexto lugar y la letra ‘a’ en décimo lugar

Page 169: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �-� ���� ��

SELECT nif, razon_social, direccion FROM Cliente WHERE razon_social LIKE ‘_____m___a%’;

Test de valor nulo: Cláusula IS NULL

&����� ������������ ������ ��� ��� #������:2��� �%������� ��� ���� �� ��� �����������������������������-�����������

Listar los efectos que tienen la cuenta corriente nula SELECT * FROM Efectos WHERE cc IS NULL; Listar la referencia, unidades, precio de venta y dto de los artículos que se han vendido y proceden de un pedido. SELECT referencia, unidades, precio, dto FROM LineaAlbaran WHERE npedido IS NOT NULL;

Condiciones compuestas. Operadores AND, OR y NOT

=��� ������ �� ������ �����(���� ��� ������� �� ���� �� ���������������#���#��� ��� ����� ���� 1:��� >/� �� :>'�� 2����(�� �� ��� ������ �� ��� ������� ����� ��� ��� ����� ��� ������� �� ���� �� &?�� ������ ����� ������� ��� �����������������������

Listar la referencia, descripción, precio de venta y precio de compra de los artículos que no sean de la familia ‘BEBI’ y su precio de venta está entre 1 y 2 � SELECT referencia, descripcion, precio_venta, precio_compra FROM Articulo WHERE familia <> ‘BEBI’ AND precio_venta BETWEEN 1 AND 2; Listar los clientes cuya razón social tenga ‘Supermercado’ o sean de la población Córdoba SELECT * FROM Cliente WHERE razon_social LIKE ‘%upermercado%’ OR población = ‘Córdoba’; Listar el número, cliente, fecha y forma de pago de los albaranes hechos el 4/1/2005 y la forma de pago no sea 4 SELECT nalbaran, cliente, fecha, forma_pago FROM Albaran WHERE fecha = “2005/1/4” AND NOT ( forma_pago = 5 );

������� �� ���� � ��

&?���������� �����(������������������������ ������� ��� ���������#�� ����������� �� �������� ���� ������ �������3/>2-� ;[���1<.:3� �� ��� ���������&"�"�'�� ��� ��������� �� �������� ��� ��� ��� �� ��� ������ ��� ��� ���!�����

Page 170: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8� � ���� ��

���������� "��� ��������� �������� ���� �������� ��������� �� ���� �������������������� ������������� ����������� �������������������������������!����� ��� ����������������������� ��������� ������ ����� �� ������������������������������������������

Funciones de agregado en la lista de selección

������������ �������� ��*&2=��1<3��&'����>2:'���>2:'*e+��=10��=.:������+���������#������ ������������������������ �������� �� ��������������2��� �������� �� ������ �� ������� �� �� ��� #������ ��������� �� ��� ���� �������������� ������������� ��������� ������ ��� ��� ��������� �� ������ �� �� ��� ��������������� ���������� �������� ���������� ��������� ������� ������������ �����������������W�"/"�����������#����������� ������� ������� �������� ����������������������� �������� ���������������#������� �#� ���������� ����������� ��������

��� ���� ��� ���#�� ����������.&'.:�'� �� ��� �� ���� ���� &2=�� 1<3�� &'�� ���>2:'��������������� ���#������ ������ ������� ����������� ��(�������������� �� ������ �� *��� #����� ��� �������� ����1��+�� &2=��1<3���&'������� ���������������������������������=.:���=10��������� ���������������� �� ���� ����-�����������

Listar las unidades máximas y mínimas de los artículos pedidos en aquellos pedidos cuyo número está entre 1 al 10 SELECT MAX(unidades) AS Maximo, MIN(unidades) As Minimo FROM LineaPedido WHERE npedido BETWEEN 1 AND 10; Listar el último cliente alfabético por la razón social SELECT MAX(razon_social) FROM Cliente; Listar el importe medio de los artículos vendidos en los albaranes que no preceden de un pedido. SELECT AVG( unidades * ( precio – precio * dto ) ) AS ImpMed FROM LineaAlbaran WHERE npedido IS NULL; Listar el precio de venta del artículo más caro de aquellos que se hayan vendido más de 100 unidades SELECT MAX(precio_venta) FROM Articulo WHERE und_vendidas > 100; Listar el pedido con total más pequeño de aquellos pedidos posteriores al 1 de enero del 2005 SELECT MIN( total_pedido) FROM Pedido WHERE fecha > “2005-01-01”;

"������� �������� ������ �#���#�������������� �������� ����� ������������������������������� ��� ����� ��� ���� ������ �� ��� ������������������� ������� ����� ��������� ��� #����� ��� ������ �� �� ������ ��� -��� ��������� ������������&2=���1<3� �#���#������#������������ ���������� �� ���� ������� �����������?�

Page 171: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8$ � ���� ��

������������ �������� ���������� ���������������������W�"/"��&����� ������ ���� ����������� &"�"�'� ���� ��������� �� ������ �� ��� �� ����� �������������������������� ��������������W�"/"������������������������������������������������� �������� ���

&�� ���� ����������� &"�"�'� �������� ���� ������� W�"/"� *������� ��� �����������3/>2-�;[+�������������� �������� ����� �������#����� �� �#� ��������������������� �� �������������� ������ ��� �������W�"/"��"����� ������� ������ �� ��������� ������� ���������� �������� ��������������������������� ��������� ������� ����� �����������������W�"/"��2����������� ��������������� �������� ��� �������� ����������

Función COUNT

��� �������� �>2:'*� +� �#���#�� ��� ������� �� ��������� �� ���������� ������������� ��� ������� �� #������ �� ���� �� ���� ��������� &�� ����%�� �� �����������$�

COUNT ( { [ ALL | DISTINCT expresión ] | * } )

"������������1��������������������� �������� ������ �����#�������1��������#�������� �������� ���"�������������.&'.:�'����������������>2:'� �#���#������������ �� #������ ������ * ������+� ��� :2��� �� ��� ��������� "�� �����������%������� �� ���� �%������� �� ���������� ����� �%������ ��������� �� ������ �� ��� ��������� "�� ���������� e� �������������� �� ����������� ������� �� �� ��� ���������� �#��#��� ��� ������� ������ �� ����� �� ���� �� ���� �>2:'*e+� ��� ���� ����������� �� ��� �� ��� �� �����(��� ���� �.&'.:�'�� �>2:'*e+� ��� ��������� ������������ �2������� �������� ���� ����������� ��� �����(�� ������������ ������� ���������� �������� ���������� �>2:'*e+� �#���#�� ��� ������� �� ����� �� ���� �� ������������ �� ��� ��������� ��� ������ ��� ������� �� �� ��� ������ ������ �� �����������������#������:2����

"�������������&?������� ��������(��������� ��������#���������������� ��������� �� ���� �������� �� ��������� ���� �������� 1<3*�.&'.:�'� �������+���>2:'*�.&'.:�'� �������+�� &'�*�.&'.:�'� �������+�� &2=*�.&'.:�'� �������+������

�>2:'*e+� �#���#�� ��� ������� �� ��������� �� ��� ������ ������ �� ���#������:2��� �� ������ ��� �>2:'*1��� �2������<� �#����� �2������� ��� �� �� �������� ��� ������ �� �#���#�� ��� ������� �� #������ ��� :2���� �>2:'*�.&'.:�'��2������<��#������2������������ �� ��� ����� ����������� �#���#������������ ��#���������������:2����

Listar el número de representantes que hay SELECT COUNT(*) FROM Representante; Listar el número de clientes que han hecho pedido SELECT COUNT( DISTINCT cliente ) FROM Pedido; Listar el número de clientes que son supermercado SELECT COUNT(*) FROM Clientes WHERE razon_social LIKE ‘%upermercado%’;

Page 172: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8�� ���� ��

Valores NULL en las funciones de agregado

-���� ��� ����� ����#������:2������ ��������� �������� ��� ��� ����������������������������������������������� �����#������ ���������������:2������������������������������#����� ������������� �������� ��������#����������������

1 ���� �� �� �� ��� #������ �� ��� �������� ��� :2���� ��� ��������� ����������&2=��1<3��&'���=.:���=10� �#���#������#�����:2�����������������>2:'� �#���#�����#����� ��������&���������������������� ����������������� �������� �� �#��#�������#�����������

Tratamiento de filas duplicadas con DISTINCT

��� ���� ��� ���#�� �.&'.:�'� �� ��������� ���� &2=�� 1<3�� &'�� �� �>2:'������ �� �� ��� �.&'.:�'�� ��� #������ ������ �� �� ��������� ����� �� ���� ���������� ��� ����� ��� ����� ���� ��� �#������� �!����� �� ��� ���������� &�� �� ����.&'.:�'������%����������� � ��������� ������ ��� ���������������������� ���������������%�������������������

�.&'.:�'�������� �������������� ������#�(�����������������&�������������������������� �������������� ���������������� ����������������������������&�������������� ������� ���������� ����������������� ������������������������������ ������������.&'.:�'�������� �������������� ���������� ��#�(� ������ ������� ���������<�������� ������������������������

Listar cuantas formas de envio se han utilizado en los albaranes SELECT COUNT( forma_envio ) FROM Albaran; Listar cuantas formas de envio diferentes se han utilizado en los albaranes. SELECT COUNT( DISTINCT forma_envio ) FROM Albaran;

Agrupar filas con GROUP BY

����������3/>2-�;[�������������� �����#������ �������� ��������� ������� ��� ��������� �� ������ ��� ���� �� �� ���� ��� ���� �������3/>2-� ;[�� ������������ �� ������ �� ���� �#���#��� ��� #����� �� ������ �� ����� ��� �����������&"�"�'��

Listar el número de pedido y su importe total SELECT npedido, SUM( unidades * (precio – precio * dto ) ) FROM LineaPedido GROUP BY npedido; Listar la media de las unidades de los artículos vendidos que proceden de Pedidos SELECT referencia, AVG(unidades) FROM LineaAlbaran WHERE npedido IS NOT NULL GROUP BY referencia;

Page 173: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8(� ���� ��

Listar la media de total de pedido por cliente de los pedidos con fecha del 1 al 4 de enero del 2005. SELECT cliente, AVG(total_pedido) FROM Pedido WHERE fecha BETWEEN “2005-01-01” AND “2005-01-04” GROUP BY cliente;

1� ������������� �� ��� ���� ��� ���#�� 3/>2-� ;[�� �� ������� ���� ����� ����������������� �� ����� ��� �������� ���������������� ����������3/>2-�;[���������� ��� ����� ��� ��������� �� ������ �8� ���� ���� ���� ����� ���� �� �� #����� ������� �� ��� �������� �� �������� �� �������������� �� �� ����� ��� ��������� �������� �� ��������� ��� ���� �� ������� ��������� �� ���� ��� #����� ����!����� ������������ ����������������

������������������� ��������������������� �������������������� ����� ����������� ���� �� ���� ����������� &"�"�'� ��������� ���� ������� 3/>2-� ;[�� ������������������� �������� ����� ������������������������� �������������������� �%������������ �#���#��� ��� ���� #����� ���� �� �� #����� �� ��� �������� ���������������� ������ ���� ��������� ��� ��������� �� ������ �� ���� ������� ������ ��� �� �������� ����� ���� �� �� ���������� q��� �� �������� ����������� ��#�����������

&?���������� �����(��� �������� ������� �� ������ �� ��� ��� ���V�������� �����������������������-�����������

Listar los unidades totales vendidas agrupadas por pedido y articulo SELECT npedido, referencia, SUM( unidades ) FROM LineaPedido GROUP BY npedido, referencia;

&��� ��� ������������� ����������������� ������������� ��������(�������������>/�"/�;[�������������3/>2-�;[�����������������

����������3/>2-�;[��������������������������������$�

• 2��� �� �� �%�������� ��� ������ ��� :������������ ������ ��������������������������� ��������������

• >��������������������� ������#��1������������������������ �#���#����� �� ��� ������ ������ �� ���� ��� ������� 3/>2-� ;[�� ������� ��������� �� ������������ ������ ��������� �������� ��� ��� ������� �� ���� ���

• :������������ ��� ������� �1<.:3� �� ��� ������ ���� ��� �������3/>2-�;[������������ ��������� ����������������������

-�� �� �������� ���� ���� �%������� ������� ���� ��� �������� ��������� �������� ���"�������������3/>2-�;[�� � ������������������� ��� �������������� ���� �����#�������������� ��� �������������� ������������ �������� ������� �����������������1&��

-�� ���������� ��������OA�)������� ����������� ��������� �������� 4)�8*� 3W�� ��� ����� ���� ��� �������� ��� ��� ������� �� ��� �������W�"/"����������� ������� ���������������������������������

Page 174: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8*� ���� ��

&����� ������ ��� ������������ �������� ������ ;8���� ��� ����� �����#��������������������� ��� ������ ���&�� ����������� ������������������������#�����#������:2�������������������������������� �#� �����

.�� ��� ���� /���� ��� ������ �� �� ��� �������� ��������� �� �� ��� ������������ ����������������3/>2-�;[������������������ ������������������������������������������� ��������&���1�������������������&"�"�'�������������3/>2-�;[����������������������������������������������������� ������������

��� �������A/,$;4�������� ������ ��� ����������� ��������4)�8*�3W� �� ��� ����� ������ ���� W�"/"� ����������� ���� &"�"�'�� =������� ���� ������ ������� �� ���� �� �� W�"/"� �� �������� ����� �� ���� �� ��� �(��� ������������� �� �������������� ��� ��� ������� �� ���� �� �� �1<.:3� �� �������� �������������%�� �� �����������1<.:3������������ ��� ������������W�"/"������ ��� ���������� �� ���� �1<.:3� ��� �� ��������� ��������� �� ������ ��� ���������� �1<.:3� ��� ��� ������ ����������� �� ����������� �� ��� ��������� ������������������������ ������������

Listar el dni del cliente y el importe total de sus pedidos si superan 15000 � SELECT cliente, SUM(total_pedido) FROM Pedido GROUP BY cliente HAVING SUM(total_pedido) > 15000;

�������������� �� ������������������������ ����������������� ����������W�"/"��3/>2-�;[����1<.:3���� ������ ��������������������������������$�

• ����������W�"/"��������(����������������������������������� ������������������������� ���������������,/>=��

• ����������3/>2-�;[���������������������������� �� ������������W�"/"��

• ��� ������� �1<.:3� �� ��� ����� �������� ��� ����� ��� ������ �������� ���

"� �� ���������� ����������� ��� ��� ������� W�"/"� ��� ��� ������� �� ���� �� ���� �� ��� ��� ��� ������ ����� �� ����� �� ��� ���������� ����������������"����� �������������� ���������������������������������

������������ ������� �� ���� �������� � ����������������������������1<.:3� ��� �������� ���� �� � ��� �������� ���� #�(� ���� �� ������ �����(� �� �������������� �������������������� ������1<.:3��� ���������#�������� ������������� ������� ������1:���>/���:>'��-�����������

Listar las formas de pago, su importe medio y su importe total en los albaranes para cada una de ellas, si el importe medio supera los 150 � y el importe total es inferior a 500 � SELECT forma_pago, AVG(total_albaran), SUM(total_albaran) FROM Albaran GROUP BY forma_pago HAVING AVG(total_albaran) > 150 AND SUM(total_albaran) < 500;

'�� ������ ��� ��� ��� ������ ��� ���� ��������1<.:3����� ��� ��������������������������������� �������� ���������������������������� �����������������������������������������

Page 175: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 80� ���� ��

Listar la referencia del artículo y unidades totales vendidas para cada uno, siempre que tengan más de 5 líneas de albarán. SELECT referencia, SUM(unidades) FROM LineaAlbaran GROUP BY referencia HAVING COUNT(*) > 5;

���������� �������� ��

����� ��� #������ V�D�� =�&?�� ��� ������ �� ��� ��������� "��� ���� ��������������� ����������������������� ������� ������������������� � � �������������� ����#������������ ������������ ��=�&?���������������� �� ����������������� ������ ��� �� �����'������������#������������!�������������������� ���������������������������������� ������ �������������W�"/"����1<.:3��<������#������� ����������� ���������������������(� ���� ���������������������

Test de comparación de subconsulta (=, <>, <, <=, <, >=)

&�� �������� ��� #����� �������%�������&?�� ������� #��������� �#���#������� ���������"�� ������������������ ����������� �(�������������#������������� �������������������� ����!������������<������#������������������

Listar la referencia, descripción y precio de venta de los artículos cuyo precio de venta es igual o superior al precio medio de venta de los artículos pedidos con más de 4 unidades. SELECT referencia, descripcion, precio_venta FROM Articulo WHERE precio_venta > (SELECT AVG(precio) FROM LineaPedido WHERE unidades > 4 ); Listar la referencia, unidades y precio de venta de los artículos pedidos cuyas unidades sean superiores o iguales a las unidades mínimas vendidas de ese mismo artículo SELECT referencia, unidades, precio_venta FROM LineaPedido WHERE unidades >= (SELECT MIN(unidades) FROM LineaAlbaran LA WHERE LA.referencia = LP.referencia );

Test de pertenencia a conjunto. Cláusula IN

"�� ���� �� ������������ �� ��������� ��� ���� � �������� �������� ��� ������#��������������������� ��#������������ �� ������� ���������&�����#����������� ���������� �����#������ ������ �������� �#���#��'/2"��-�����������

Listar el nif, razón social y teléfono de los clientes que han hecho pedido en el mes de enero del 2004 SELECT nif, razon_social, telefono FROM Cliente WHERE nif IN ( SELECT cliente FROM Pedido

Page 176: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8�� ���� ��

WHERE fecha BETWEEN “2005/1/1” AND “2005/1/31”); Listar la forma de pago y su descripción de aquellas formas de pago que no se han utilizado en los albaranes. SELECT forma_pago, descripcion FROM Forma_Pago WHERE forma_pago NOT IN (SELECT DISTINCT forma_pago FROM Albaran);

Test de existencia. Cláusula EXISTS

"������ ���%��������������� ��������� ����������� ���������������� ���"�������� ��������������� ������������ ���������-�����������

Listar los clientes que tienen al menos un albaran con forma de pago 3. SELECT * FROM Cliente WHERE EXISTS ( SELECT * FROM Albaran WHERE cliente = nif AND forma_pago = 3 ); Listar el nif y nombre del representante que haya hecho pedidos SELECT nif, nombre, apellidos FROM Representante WHERE EXIST( SELECT * FROM Ped-Rep WHERE representante = nif ); Listar listar los clientes que tienen por lo menos 3 pedidos. SELECT * FROM Cliente WHERE EXISTS( SELECT COUNT(*) AS Pedidos FROM Pedido WHERE cliente = nif HAVING Pedidos > 3 );

Test cuantificado ANY

"������ ������������������������������ ���%��� ������������������������ ��1:[�������������� �������� ������������������ ������������������������� �������������� ��#��������� ��� ����������� ���������-�����������

Lista la referencia y la descripción de los artículos cuyo precio de venta sea diferente a alguno de los precios a los que se ha vendido ese artículo SELECT referencia, descripcion FROM Articulo AS A WHERE precio_venta <> ANY (SELECT DISTINCT precio_venta FROM LineaAlbaran AS LA

Page 177: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 88� ���� ��

WHERE LA.referencia = A.referencia); Listar las facturas cuya fecha sea inferior a alguna de las fechas de vencimiento de sus efectos. SELECT * FROM Facturas AS F WHERE fecha < ANY (SELECT fecha_vto FROM Efectos AS E WHERE E.nfactura = F.nfactura);

�-� ���� #��� ���� �%���� ���� ������� ������� � ������ ��� ������� .:�� �������� ���Z����� ��� �������1:[��� ��� �������"0.&'&��1�������������������������������� �� ������� ��#�������������������������&"�"�'���� ��� ��������������������� ������������� ��������������� ����������

Listar los clientes que han hecho pedido el día 3/1/2005 SELECT * FROM Cliente WHERE nif IN ( SELECT DISTINCT cliente FROM Pedido WHERE DATE(fecha) = “2005-01-03”); SELECT * FROM Cliente WHERE EXISTS ( SELECT * FROM Pedido WHERE cliente = nif AND DATE(fecha) = “2005-01-03”); SELECT * FROM Cliente WHERE nif = ANY ( SELECT DISTINCT cliente FROM Pedido WHERE DATE(fecha) = “2005-01-03”);

Subconsultas anidadas

=�&?�� � ����� ��� ��� � ��������� �� ����� ���� � �������� �� ������������������ �� ����� � ���������:�� �%���� �!����� �� ��� ��������� ����� �� ������� ����������� ������������ ��#���#���������� ���� ��!���� ������� ����1� ����������������������������������������������������������� ����� � ���

Listar el nif y el nombre de los representantes que tienen pedidos hechos el 3 de enero del 2005. SELECT dni, nombre FROM Representante WHERE dni IN (SELECT dni FROM Ped-Rep WHERE npedido IN (SELECT npedido FROM Pedido WHERE Date(fecha) = “2005-01-03”) );

���������� ��#�������������������������� �� ��������������&"�"�'�������������������������� ��� ���� ��� � �������������� �� ���������������� �������� � ��������������������� �� ��� ����������� ��������������� �� ������� ����������������������#��� ����� ���������-�����������

Page 178: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8 � ���� ��

Listar los clientes que han pedido más de 5 unidades de artículos y la forma de pago es ‘Giro 30 días’ SELECT nif, razon_social FROM Cliente WHERE nif IN (SELECT cliente FROM Pedido WHERE npedido IN (SELECT npedido FROM LineaPedido WHERE unidades > 5 ) AND forma_pago = (SELECT forma_pago FROM Forma_Pago WHERE descripcion = ‘Giro 30 días’) );

Subconsultas en cláusula HAVING

1� ������������� �� �%����� ��� �������� �� � �������� ������ �� ��� ���������� �1<.:3�� /���� ���� ���� ��� ���� ������� �� ������ ��� ������� ������������������������������� ���������������������������� �������

Listar la referencia y el precio medio de aquellos artículos vendidos cuyo precio medio supere el precio medio de todos los artículos pedidos. SELECT referencia, AVG(precio) AS precio_medio FROM LineaAlbaran GROUP BY referencia HAVING precio_medio > (SELECT AVG (precio) FROM LineaPedido ); Listar el número de albarán e importe total del albarán para aquellos albaranes que superen a alguno de los importes totales de los pedidos. SELECT nalbaran, SUM( unidades * ( precio – precio * dto ) ) AS Importe FROM LineaAlbaran GROUP BY nalbaran HAVING Importe > ANY ( SELECT SUM( unidades * ( precio – precio * dto) ) FROM LineaPedido GROUP BY npedido );

������� ������� �� ������� ��

��� �������� ������� ��� �� A>.:&�� ��� ���� ������� �� ��� ��������� ���������������������������������� ���� �� ���� �������������������������������������������������� ����������� ���������� � ��!�������(���&?��&��#������ ���� �������� ��������������������������� ��������� ����

2������ ������ ����� ��������*������������+� ������������������������� ���� ���������������������������������$�

"���������� ����������� ���� ���� ������� � ������������ ������ ���������2������ ������ ����� ���������!����������������������#���%������ �������� ����������#���������������� ������������ ����

Page 179: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8-� ���� ��

"������������������ ��������������*Z��^Y������+������������������#������ �������������� ��������������-�����������

Listar el número de pedido, fecha, cliente, razón social y total pedido SELECT npedido, fecha, nif, razon_social, total_pedido FROM Pedido, Cliente WHERE nif = cliente;

"�� ��� �������� ��������� ��� ���� ��� �� ��� -����� �� �������� *���� �������������������������������,/>=+������� ������/����������������'������ ����� �� ��� ��� �� �������� �� ����0��� ������ �����(�� �� ����� ��� ��� �������� ����������� ������� �� ��� �� ��� -����� �� ��� �������� ������� �� ��� �� ��� ���������� �������������� ��������������Z��

���� �� ��� ���� �������� ������ �� ����� ����������� �� ��������� �� ������������ ����������������������������� � ������� ������������������� ��� �������������� ���� ������ �� ��� #����� �� ��� �� ������� �� ����� ����������� ��� ����������� � ������������ � �� ������ ��� ������� ����� ������������-��������������������������� ������� ���-�����������������������-���?�������

���� �������� ��� �������������������� ������ �����#����� ������� ����� �� ��� ��� ��������� ��� ����������� ��� ����� ��� ����������� ����������� ���� ������ ��� �� ��� �� ����1������#��������� �����������&"�"�'��� ������� �� ����� ���������� ��� ���� �� �� ���� �� ����� ���� �� ��� ��� �������� �� �� �� ��������� &����� ������������������������ ����������������� ���������������������������������� ��� ���� ��������������������� ��������������������������� ���� ����

Joins de dos tablas

2�� A>.:� �� �� �� �������������������������� �������� �� ����� ��������� ������ �%����� *�� ����� ����� �� �����������+� �� �� ��������� ���� �� �� ���� ���� "�� A>.:� ������ ������� �� ����� ������ �� ������ ��� ��� ������� �� �� �������������������� ���-�����������

Listar el número de albarán, fecha, referencia de artículo, unidades, precio y dto. SELECT A.nalbaran, A.fecha, LA.referencia, LA.unidades, LA.precio, LA.dto FROM Albaran A, LineaAlbaran LA WHERE A.nalbaran = LA.nalbaran; Listar la referencia de artículo, descrición, unidades y precio de los artículos pedidos SELECT A.referencia, A.descripcion, LP.unidades, LP.precio FROM Articulo A, LineaPedido LP WHERE A.referencia = LP.referencia; Listar el número de factura, fecha de factura, número de efecto, fecha de vencimiento de todos los efectos SELECT F.nfactura, F.fecha, E.nefecto, E.fecha_vto FROM Factura F, Efectos E WHERE F.nfactura = E.nfactura;

Page 180: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ � � ���� ��

����������� �����A>.:� �� ���� ���������������������������������������������� �����(� �� ���� &"�"�'�� ����� �������� �� ��������!����� ��#� ���� "��������� ������� ��� �������,/>=��������� �� �� ��� ����� �� ���� ���� ������ "������ �� ������ ��� ��� ������ �� ���� �� �������� �������� �� �� �� ��� ���������� 1 ���� ����� �� �� ��� ������ �� ���� ��� ��������� ��� ����� ������������� ��� ��� ������ �� �� ��� ��������� �� ������ �� ������ �� ���� ������������������� �� �� �� ���� ��� ��� ������ �� ���� �� ��������� ��� ������� �� �������������������������� ���

-� �!���� ����� ���� ��� �������� ��������� ������� ������ �� ���� ����� �������� ������������������������ ����������*������+��������� ���-����������� ��������� ����������*��+��������� ������������

������������������ ����������������������� ���� ��������������������������� �������� �� ��9������ "�� ��� �������� ���������� �� �� �� � �� *����+� ������ ����������� ����� �� *�� ��+�� �� �� �� �������� *�� ��+� ��� �� ������ ������ �� � ������� ��*����+���������� ���������������������������� �� ������������������� ��������� �� ������� ��9������ "�� �������� �� ���#����������9���#�� �������� ����� ����������������������#����������������������������������������� ������������������� ���#����������� �� ��� �� ���� "�� ��� �������� � �������������� ���� ��� ������ �� ���� ��������������������#�����������������#������������

JOINS con criterios de selección de filas

������ ������ �� ���� �� �����A>.:��������������������������������� ������ �� ���� ���������� ��� ���� ��������������� ���� ���������� �� ��� ������ ��������� ��� ������� �� ���� �� ���� ���������� ���� �� ��� ����� �#������ ��� ��������� ���-�����������

Listar la referencia, descripcion, unidades, precio y descuento de los artículos vendidos que no tienen pedido SELECT A.referencia, A.descripcion, LA.unidades, LA.precio, LA.dto FROM Articulo A, LineaAlbaran LA WHERE A.referencia = LA.referencia AND LA.npedido IS NULL; Listar el número de pedido, fecha, cliente, razón social de aquellos pedidos con forma de pago 2, 3 o 5 SELECT P.npedido, P.fecha, P.cliente, C.razon_social FROM Pedido P, Cliente C WHERE P.cliente = C.nif AND P.forma_pago IN( 2, 3, 5 ); Listar el número de factura, fecha de factura, número de efecto y fecha de vencimiento de aquellos efectos que tengan el vencimiento a más de 30 días con respecto a la fecha de factura SELECT F.nfactura, F.fecha, E.nefecto, E.fecha_vto FROM Factura F, Efectos E WHERE F.nfactura = E.nfactura AND DATEDIFF(E.fecha_vto, F.fecha) > 30;

JOINS con múltiples columnas de emparejamiento

���� �� �� �� ��� ���� ��������� �� ���� #����� ���������� ���#��������9���#�� ���������� ��� ��� ������������ �� �� ����� �� �������� ��

Page 181: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ $ � ���� ��

������������������������ ������ �� ���� �� ���A>.:��-������������ �������������������������� ������� ���$�������������������� ���������#������������������� ���$���-������������ �������������������������������*�� ������������ ���#�� ��������� �� ��� �� ��� $���-���+�� ��� ���� ������� ��� �������� ��������������(�����A������������������������� ������������������

Listar la referencia, unidades vendidas, precio de venta, unidades pedidas, precio de venta pedido de las líneas de albarán que proceden de un pedido SELECT LA.referencia, LA.unidades, LA.precio, LP.unidades, LP.precio FROM LineaAlbaran LA, LineaPedido LP WHERE LA.npedido = LP.npedido AND LA.nlineap = LP.nlinea;

JOINS de tres o más tablas

2��A>.:� ������������ ���������������������������������� �� �������������� �������%�����*������������ �������������+� ����������������������� ���� ���� ����"��A>.:������������������ �������� ������������� �� ���������������������� ��� ����� ��������� ��� ��� �������� ��������� �������������� ��� �� ���-���������������$���-���������� �������������� ������� � �������������D�HHH�n��������� �������� ��� �����������������(������� � ����������!���������������������� ����

Listar el número de pedido, fecha, cliente, razón social, referencia, unidades, precio y dto de los pedidos con total superor a 1000 � SELECT P.npedido, P.fecha, P.cliente, C.razon_social, LP.referencia, LP.unidades, LP.precio, LP.dto FROM Pedido P, Cliente C, LineaPedido LP WHERE P.cliente = C.nif AND P.npedido = LP.npedido AND P.total_pedido > 1000;

����������� ����� �� ��������� ������������������ �� ���#�� ����������������� �������������������(���� ���� � ���������������������������������-��������������� ��� �������� ������ �� ���� ���#�� ������� ����� ��� �� ��� $���-��������������� ���� � ���������!�����

����������������������������������� ���-�������������� ���-��( ������������ �� ��� ������������� �������� ����� ���� ��������� ����� � ���� ��� ������������������������ ������ ��������

Listar el número de pedido, fecha y nombre del representante que tomó el pedido SELECT P.npedido, P.fecha, R.nombre FROM Pedido P, Ped_Rep PR, Representante R WHERE P.npedido = PR.npedido AND PR.dni = R.dni;

1�������������������������������������������#������������������ ���*A>.:��� �����+� ����� � ������ ��� �� � �� ��� !�� 49D9GHH6� ������ �� ��� ��� ��� �������������������� ��������#�� � �����������������������!����� ����� � ���

Listar el número de pedido, fecha, nombre del cliente que hizo el pedido y nombre del representante para los pedidos con fecha 3/1/2005

Page 182: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �� ���� ��

SELECT P.npedido, P.fecha, C.razon_social, R.nombre FROM Pedido P, Cliente C, Representante R, Ped_Rep PR WHERE P.cliente = Cliente.nif AND P.npedido = PR.npedido AND PR.dni = R.dni AND P.fecha = “2005-01-03”;

����� ���!� ����� #���� �������� �� �������� ���� A>.:&� ������� ������ &?�� ��� �%���� ���� ��� �������� �� ��������������� ������� �����������������9���#�� �������� ��� ������� �� �������� ������������ �� �� �� ������ ��� �����(���� ����� �������� �� ��������������� ������� �� ���� �� ���� ����� �� ���� ���� ������� ���� ������� ��� ����� ��� �� ������ ��� ���� �������������������������� ������ ����������������������

Listar el número de pedido, cliente, fecha de pedido, número de albaran, cliente del albarán y fecha de albarán para aquellos pedidos hechos el mismo día que los albaranes SELECT P.npedido, P.cliente, P.fecha, A.nalbaran, A.cliente, A.fecha FROM Pedido P, Albaran A WHERE P.fecha = A.fecha;

JOINS con condiciones de búsqueda sin igualdad

&� ����������� A>.:� �� �� �� �������������������������� �������� �� �� ��� ��� ������ ������ �%����� *�� ����� ����� �� �����������+� �� �� ��������*���� ���� ���� ��+�������� ����������� ������ �� ���� �� ���A>.:��

����� ���!� ���� ����� �����(� �� A>.:&� ��� ��� ���� ��� ��� ��� ������ �� ���� ����������������� ����� � 8������ ��������� ������ ������ �� ���� �� ���A>.:���� ���������������������� ��� ������� ����������� *Z��^Y������+��������������� ��� #������ �� ������������ �� ��� ��������� "�� A>.:� ������ ������� �� ����������� �� ��������� ��� ��� ������� ��� A>.:� ��� ��� ������� �� �� ��� ����������������� ���

"��� ����� �� ��� ��������� ��� �� ���������� ��� ���� ��� ������ �����������!�����!�������������������� ���� ����

JOINS internos y externos

"�� ��������� ���� ��������� ����� ������ �� A>.:� �������� �� �� ��� ���� ��������������A>.:�.:'"/:>������������� �������������������� ���� ����������������� ����� �� ���� ����� ������ ��� ���������� ������� �� �������������� �������� �� �� ��� ����� ��� ��� ������ �� ���� �� ��� A>.:�� ��� ����� �� ��������������������� ������������������ ��������������������� ����������� ������ ����� ���� ����������������������#������-�����������

Listar los artículos con su referencia, descripción, familia y descripción de la familia SELECT A.referencia, A.descripcion, A.familia, F.descripcion FROM Articulo A, Familia F WHERE A.familia = F.familia;

"�� ��� �������� ���������� ��� �������,/>=�������� �� �� ��� ��� ������������ ��� �� ����� �� ��� �� ������*����� �� �� ��� �� ���&������ ��� ����� �� ���

Page 183: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ (� ���� ��

�� ������ ����� �� ��� ��������������� �� ������������� ����� �� ��� ����� �� ��� ���� ��������������W�"/"������ ����������������������������� ���������������� ����� �� ��� �� ������ ���������� ������� ��� ������ �� ��� �� ����������� ������ ������ ��� ������ �� ��� �� ���&������� "�� A���� .������� ������ ���� ����%�� �������� "���������������������� ��������� �������� ��� ���������������������

Listar los artículos con su referencia, descripción, familia y descripción de la familia SELECT A.referencia, A.descripcion, A.familia, F.descripcion FROM Articulo A INNER JOIN Familia ON A.familia = F.familia;

���� ��������#���%������ �������� �����������#����������� ���������������������������� ������� ����������� ����������2&.:3������ �����(��� ��� ��� �������������������������������� ��!���!�

Listar los artículos con su referencia, descripción, familia y descripción de la familia SELECT A.referencia, A.descripcion, A.familia, F.descripcion FROM Articulo A INNER JOIN Familia USING( familia );

&�� ������#���%�������������������������� ������� ����������#������� ��������������������������������2&.:3������� �!������������������ ���������������� ������������

-���� ��� ������ ��� ���� ������� ������ ������ *�� ��������������+� ��� A>.:�.:'"/:>������� �������� �� �������� ��� ������ �� ��� ��������� ���#������ ������!�������� ����� �����������������*����������������#������:2��� ������������� ����������+���

"����������������������#����� ������ ��������������������������������� �� � ��� ���� ������� ���� �������� ��� ���������� ��� ��� ������ �� ���A>.:� ��� ��� �%����� ��� ��������������� ��������� 1 ���� ���� ������� �� � ������������� �������������������#�����:2����

&�� �������� ���� ���� ����� �� ������ ��� ����� ��� ���� ��� ���� ������������������ �������� ������ ��� ����� �� ��� ��� ������ �� ���� �� ��� A>.:�������(��� ��� ��� ������ �� ��� A>.:�� ������� ���� ��� ��� ��� ��������� �� A>.:�"0'"/:>��� ����������� �%������� -��� ��� ������� ��� ����������� �%������ ������� ������ ������� �������������������������������������������������������� ���

JOIN EXTERNO completo

2�� A>.:� "0'"/:>� ��������� �� ���� ����������� �� ��� A>.:� .:'"/:>������������A>.:+�������������������������������������$�

• "��A>.:�.:'"/:>�*��A>.:+� ����� ���� ����

• -��� �� �� ����� �� ��� �������� �� ��� ���� ��� ����� �������� � �� ���������� ����� ��� ���� �� �� ���� �� �)� �� ���� ����� �� ��� ������ ��������(�� �� ���#������ ����������� �� ������������� ������������ ����� #����� :2��� ����� �� �� ��� �������� �� ��� ���� �� �� ����������� ����������������������������

• -��� �� �� ����� �� ��� ���� �� �� ��� ���� ��� ����� �������� � �� ���������� ����� �� ��� �������� �� ���� �� �)� �� ���� ����� �� ��� ������ ��������(�� �����#������ ������������� ��������� ���� ������������ ��

Page 184: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ *� ���� ��

��� #����� :2��� ����� �� �� ��� �������� �� ��� �������� �� ����������� ����������������������������

"�� ������� �� ���������� ��� A���� "%������ ��������� �����(�� ��� ����%�� >2'"/�A>.:���� ��� �������,/>=� �� ��� �������� �� ��� ����%��>:���� ������ �� ��� �������W�"/"� ���� ����� �� ��� ��� ������ �� ���� �� ��� A>.:�� &��� �� ������ ��� �����������#������� ��=�&?�������������� �����A����"%�������

JOIN EXTERNO izquierdo y derecho

"�� ��� ������ �� ��������� ����� #���� ��� A>.:� "0'"/:>� ���������� �������� ������� ������ ��������� A>.:�"0'"/:>�.\?2."/�>����������� ���������� ���� ����������� �������������������������$�

• "��A>.:�.:'"/:>�*��A>.:+� ����� ���� ����

• -��� �� �� ����� �� ����������� �� ����������������������� � ����������������� ��������� ���� �������)� ���������������������� ��������(�� �����#������ ������������� ��������������� ������������ �����#�����:2�������� �� �� ��� �������� �� ��� ���� �� �� ��� �������� ������ ��� �������������������

"�� ������� �� ���������� ��� A>.:� "0'"/:>� .\?2."/�>� �����(�� ��� ����%���",'� A>.:� ��� ��� ������� ,/>=� �� ��� �������� �� ��� ����%�� >:� ��� ������ �� ����������W�"/"���������� �������� ������ �� ���� �� ���A>.:��'�� ��������� ����������������2&.:3����� ������������� ����� ������������� ���� ��������������������� ����

Listar el número de pedido, fecha, forma de pago y la descripcion de la forma de pago de todos pedidos, aunque no tengan la forma de pago NULL SELECT P.npedido, P.fecha, P.forma_pago, FP.descripcion FROM Pedido LEFT JOIN FormaPago FP ON P.forma_pago = FP.forma_pago;

"�� ��� �������� ���������� ��� �������� �� ��� �������� ���� ���������� ��� ���� ����� ����(�� � �� �� ������ ������ ��� ��� �� �� ���� ���� ������ �������� ����� �������(��� ����������2&.:3�������������#���������������������������� ��>:������ �� ����� ������ ������������� ������������� �� �� ��� �� ������� ����������������� �����#�������"���������������������� ��!�� ���������������������

Listar el número de pedido, fecha, forma de pago y la descripcion de la forma de pago de todos pedidos, aunque no tengan la forma de pago NULL SELECT P.npedido, P.fecha, P.forma_pago, FP.descripcion FROM Pedido LEFT JOIN FormaPago FP USING(forma_pago);

&��������������� ��� A>.:� "0'"/:>��"/"��>� �� ��� ���� ������ �� �� ����������� �������������������������$�

• "��A>.:�.:'"/:>�*��A>.:+� ����� ���� ����

• -��� �� �� ����� �� ������� �� �� ����������������������� � ����������������� ��������������� �������)� ���������������������� ��������(�� �����#������ ������������� ��������� ���� ������������ �����#�����:2���

Page 185: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 0� ���� ��

����� �� �� ��� �������� �� ��� �������� �� ��� �������� ������ ��� �������������������

Listar el número de pedido, fecha, forma de pago y la descripcion de la forma de pago de todas las formas de pago, aunque no tengan pedidos SELECT P.npedido, P.fecha, P.forma_pago, FP.descripcion FROM Pedido RIGHT JOIN FormaPago FP ON P.forma_pago = FP.forma_pago;

:����#� ���������������� ��A>.:��������������� ���� ����� �������������� ��������#��������������,/>=� ��������������&"�"�'�������������������������

JOIN con múltiples columnas de emparejamiento

"�� ��� ���� ������ ��� ���� �� ���#�� �%�����9������������� �� �����(��� ����������� ��� ��������������� ���#������ ��������� ���� �� �� �� ��������� ����� ��������(����������� �����������1:����>/�����������(��������� �������������������������������������

Listar el número de albaran, número de línea, referencia, unidades de la línea del albarán, unidades de la línea del pedido y su diferencia de todos artículos vendidos SELECT LA.nalbaran, LA.nlinea, LA.referencia, LA.unidades, LP.unidades FROM LineaAlbaran LA INNER JOIN LineaPedido LP ON LA.npedido = LP.npedido AND LA.nlineap = LP.nlinea;

JOIN anidados

���� ������������� �������������������� ����������������� ��������(�������A���� ������ ����������� ������A�����<����������������

Listar el número de albarán, fecha, cliente, razón social del cliente, número de línea, referencia, descripción del artículo, unidades y precio de los albaranes hechos en la fecha 4/1/2004 SELECT A.nalbaran, A.fecha, LA.nlinea, LA.referencia, AR.descripcion, LA.unidades, LA.precio FROM Albaran A INNER JOIN LineaAlbaran LA INNER JOIN Articulo AR ON LA.referencia = AR.referencia ON A.nalbaran = LA.nalbaran;

����� �� ��� �� #��� ��� ��� ��������� ��� ������� >:� �� #��� ������ �� ����� �����#����������������.::"/�A>.:��"� �����������������������(� ������� ����������� ���� ��� �� ��� $����������� ��� ��� �������� ������� .::"/� A>.:�� "�� ������� ������������(� �� ����� ���$�������������������� ���������������������>:������������������ �����#������������������������ ����������� ����������A>.:����������������������� ����������A>.:��"������������������� ������������2&.:3���� �� �� ���� ���� ��� ������ �� �� ������� .::"/� A>.:� ���� �� ������� 2&.:3��������� �������

Listar el número de albarán, fecha, cliente, razón social del cliente, número de línea, referencia, descripción del

Page 186: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ �� ���� ��

artículo, unidades y precio de los albaranes hechos en la fecha 4/1/2004 SELECT A.nalbaran, A.fecha, LA.nlinea, LA.referencia, AR.descripcion, LA.unidades, LA.precio FROM Albaran A INNER JOIN LineaAlbaran LA USING(nalbaran) INNER JOIN Articulo AR USING(referencia)

"����������������� ����������������� ������ ������ ����A����������������A�����%��������#���#�����'����� ���������������� ������ �����A���� ������������� ������ ���A�����%��������������(����� ����������� ���������������������#���:����� ����� �������A������������ ������ �����A�����%�������������������� �����������������(����� ���

��� �� ���������� ����

Introducir datos. Sentencia INSERT

�������%�� ���� ��������������.:&"/'������������#�������������!���������������

INSERT [LOW_PRIORITY | DELAYED | IGNORE] [INTO] tabla [(lista_columnas)] (valores_de_datos)

���������������������������(��(�������������������������������������� ������ ���� �� ��� ���� "�� ���������� ����(�������� �� ���� ����� ����� �� ��������� �� ��� ��� ��� �� �� ��� ���� �� ��� ��� �����(��� ����� ����������� �������������������������������� �����&����������������� ����(����������� ������������� ������� ������� ���� �����

���� ������ ����(��������������������� �� ����������� �� ����� ����������������#�����:2���*�����#�������� �������� ��������� ����� �������������� ����������+������������������������������������������ �������� ������'� ������������������������� ����� ��� ����� ���������� � ������������#������:2��������������#�������� �������� ���

���������(��(����� �������� �� � ��� �������� ���� ���� ��� ����� ����������� "�� ������� �� #������ �� ���� � �� ��� ��� ��������� ��� ������� ���������� �� ��� ����� �� ����� ��������� �� ������ �� �� �� #����� �� ���� � ��������� ��� ���� ��� �� ��� �������� �������� ����������� ����������� �� ��������������#������ �� ���$�

• 2����(�������.:&"/'�������������&"�"�'��������������������#������ �� �����������������������

• 2����(�������.:&"/'������������&"'������ �������� ���������� ����� �������������������� �����#������ � ���

• 2����(���������� ������#��<1�2"&������ ����������� ����������������������� ������������

�������������������������������!����������������� �� ������������ ����&������%���$�

Page 187: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ 8� ���� ��

INSERT [LOW_PRIORITY | DELAYED | IGNORE] [INTO] tabla [(lista_columnas)] SELECT …

������������&"�"�'���� ������������������������ ����������#���������������������<�������������������������

Crear una tabla, llamada Clientes con las columnas nif, razón social y teléfono CREATE TABLE Clientes ( nif VARCHAR(10) BINARY NOT NULL PRIMARY KEY, razon_social VARCHAR(40) BINARY NOT NULL, telefono INTEGER(9), ); Insertar en la tabla anterior los clientes de la tabla Cliente que tengan teléfono INSERT INTO Clientes SELECT nif, razon_social, telefono FROM Cliente WHERE telefono IS NOT NULL;

���� ��� ���� �� ������� �� �������!�� ���� ����� �� ���� ������� �� �� ����������������� �� ����������� ����������&"'������!��� ���#������ �� ��� ���&������%���$�

INSERT [LOW_PRIORITY | DELAYED | IGNORE] [INTO] tabla SET columna = exp | DEFAULT, columna = exp | DEFAULT, …

�� ���������� ��� �����#����� ���2��������� ����������%�������=�&?��#�� ���&�������������� ������#���",12�'���������!�����#��������� ������� ����� ���������� ��������������������������������������������� �� �������������#������:2�����#���������� ��������-�����������

Introducir en la tabla Albarán un albarán con fecha actual, cliente con nif 30000002A, forma de envío es ‘Transporte propio’, forma de pago 4 INSERT INTO Albaran SET cliente = ‘30000002A', fecha = Current_Date(), forma_envio = ‘Trasporte propio’, forma_pago = 4;

���� ���������� ������� �� ������� ��� ���� ��� ���#�� <1�2"&� ����� �� ����� ��������� ��#������������������������� �����������&������%���$�

INSERT [LOW_PRIORITY | DELAYED | IGNORE] [INTO] tabla [(lista_columnas)] VALUES (valores_de_datos)

���#������ �� �������� ���������� ������������"���������������� � �������� �������������������� ��� ���������(���������-�����������

Introducir en la tabla Cliente un cliente con nif ‘30000100A', razón social ‘Supermercado Mandarín’ y teléfono 957774477 INSERT INTO Cliente (nif, razon_social, telefono) VALUES (‘30000100A',’Supermercado Mandarín’, 957774477;

Page 188: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ � ���� ��

���� ���� ������������ ��� ������� �� ��� ���� ������ �� �������� ��������������������>W@-/.>/.'[�������������� ��������������.:&"/'����������������������������������������������� �� ������� �����

���� �����������"�1["�������#� �������������� ������� �������������� ����������� �� ��� �� ��� ��� �� ��� �� #��� ������� �� �� �� �� �� ����� ������ �� ��� ��#� ���������� �� �� ���� ���������� �� �������� ����� ��� �� ���� &�� ��� ����� ��� ����� �� ����������������������������������������������� ���#���#����������� ����

���� ��� ������� .3:>/"� �� �������� ��� ����� ���� ���#����� ������� ���� ������ � � �����#���������&������������(������������������ ������������������������ ���������������#������������ �������� �������������

Eliminar filas de datos. Sentencia DELETE

�������������"�"'"���������������#���������� �������� ����&������%���$�

DELETE [LOW_PRIORITY] [IGNORE] FROM tabla [WHERE condición] [ORDER BY ...]

[LIMIT n]

"��������������������� �������� ��� �����������#�����������������������&����������� �� �� ��� ����� �� ������ ���� �������� ��� ��� ������ �� ���� �� �� ����������W�"/"��

&����������������������������W�"/"���������������� �� �������� �� ��������� *��������� ��� ���������'/2:�1'"�'1;�"+������ ��� ��������>W@-/.>/.'[����� ������������������������ ���� ����������������������������������� ������� ������.=.'������ ���������������������%���� ���������������� ��� ��������

&������ ���������������>/�"/�;[������������ ��������������� ����"����������������������� ����� ����������������������������.=.'����

Borrar todos los clientes que no han hecho pedido durante el més de enero DELETE FROM Cliente WHERE NOT EXISTS( SELECT * FROM Pedido WHERE nif = cliente );

Actualización de datos. Sentencia UPDATE

��� ����������� 2-�1'"� ��� �� ��� ���� ��� #������ �� ����� �� �#� ������������ ����������� �� �������� �������� �����#�����2��� �����������2-�1'"����������������������������� �����#������� ����� ������� ���� �������� ��������#�(��&������%���$�

UPDATE [LOW_PRIORITY | IGNORE] tabla SET columna = expresión [, columna = expresión] … [WHERE condicion] [ORDER BY exp] [LIMIT n]

&"'� ��������� ���� ����� ����� �� ���� ����� �� ��� �������� ���� � ����������(���� �� ��� ���#�� #����� �� �� �� ��������� ���� ��� �������� ������� =��2��������"��#������������� �����������%�����������������������������������

Page 189: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��-�R��< & �# ����+ / �< & ��& ��� � �1�� ��+ ��# � ��! �� ��� ����� � � � � ���$ -� ���� ��

���������� #������ ��������� �� �� ���� �������� �� ����� �� ��� �� #������������� �����������%���������������������������������������������%�������� � ��� ����� ��� �� ��� �������� ������ ��������� ���� �� �������� �� � ����������� �� ������ ���������������������2-�1'"��

����W�"/"������������������� ������ �� ���� ������ ���������� �������������������������������

���� �>W@-/.>/.'[� �� ���� ���� ��� �� �������� ��� �������(������ ����� ���������������������������� ������� ����

���� .3:>/"� �� �� ��� ���� ���� �������(������ ���� ���#����� ���#�� ������ ������ ���������������������������� ��� ��������� �������������#����������� ���������(�����

���� �.=.'� �� �� ��� ����� ��� ������� �%���� �� ����� ���� �� ��� ����������(����

����>/�"/�;[��%�� ���� ����� ��� ����� ����� �� �������(�������&���� ����������� �������������������������.=.'����

Actualizar las formas de pago de todos los albaranes a ‘Giro 90 días’ cuando el valor de estas sean NULL. UPDATE Albaran SET forma_pago = ( SELECT forma_pago FROM Forma_pago WHERE descripcion = ‘Giro 90 dias’ ) WHERE forma_pago IS NULL; Actualizar el total albarán de todos los albaranes a la suma de los importes de sus correspondientes líneas de albarán UPDATE Albaran A SET total_albaran = ( SELECT SUM( unidades * ( precio – precio * dto) FROM LineaAlbaran LA WHERE A.nalbaran = LA.nalbaran );

Page 190: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ � �R�) � �����! �� ��+ / �< & � � � � � ���$ -� � ���� ��

�1�� � � �� �� � � �� � �� � � � + � ��

������ �������� �� ��

������� ��� ��������� &?��9�����������G���!� $�� �� �<����� =�&?�� �����(������� ������� ��� ������������� ������������ ��� �������!�� ����������� *�� ����� �+� ������� ����������� ���� ���������� �� �����=��9�������������$�� �� �<?�

��� ��������� ��� ��������� �� �� ���������� �� ���� �� �����(��� �������������������������� ������� ����� �� ��� �� ����������������� ��������������!� ����� ����� �������� ��������!����� �� ����#����� ������� ��� ���������1�'"/����/>-��

����� ������������� ������������ ���� ��� ������ ��� �� �����������(��� ��������� �� ������� �� ��� ��������� �/"1'"� '1;�"� *��� #���� ��� ��� ���!�������������+��1�'"/�'1;�"����/>-�'1;�"��

Modificación de tablas con ALTER TABLE

������ �������������� ��������� ������ ���������� ������������������������ ����� ������ ����������������������8������������������� ��$�

• 1�������� �� ������� �� ��������� ��������� 1!�� �� ��� �� ��� ���� ������ ���� ��� ������� �� ��� ����� �� ����� ��� ���������� ��� ������ �� �������������� �� #������ :2��� �� ��� ��������� ������� ���� ��������������������

• 1������������������������������-/.=1/[�X"[���,>/".3:�X"[��

• 1������������������������������2:.?2"�����"�X���!������ �����������*��� ����+��",12�'��

• /�������� ���� �� ��� �� ��� �������� ��������� �� �� ���� �� ��� ����� ����� �(������ ����%����

.�������������������%�� ��1�'"/�'1;�"��� �!����������������$�

ALTER TABLE tabla [CHANGE nombre_columna nombre_columna_nuevo nuevo_tipo_datos [ ( precisión [ , escala ] ) ] [NULL | NOT NULL]] | ADD [COLUMN] declaración_columna [FIRST | AFTER nombre columna] | ADD INDEX nombre_índice (columnas índice) | ADD PRIMARY KEY (columnas_índice) | ADD UNIQUE nombre_índice (columnas_índice) | CHANGE [COLUMN] nombre_columna declaración_columna | ALTER [COLUMN] nombre_columna [SET DEFAULT valor | DROP DEFAULT] | DROP [COLUMN] nombre_columna | DROP INDEX nombre_índice (lista_columnas) | DROP PRIMARY KEY

Page 191: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ � �R�) � �����! �� ��+ / �< & � � � � � ���$ -$ � ���� ��

| MODIFY [COLUMN] declaración_columna | RENAME [AS] nombre_tabla_nueva | ADD [CONSTRAINT [nombre_restricción]] PRIMARY KEY [tipo_índice] (columnas_índice) | ADD [CONSTRAINT [nombre_restricción]] UNIQUE [nombre_índice] [tipo_indice] (columnas_indice) | ADD [CONSTRAINT [nombre_restricción]] FOREIGN KEY [nombre_indice] (columnas_indice) [referencia]

"������������ �������� ������ ��� �� ����� ���������#������ ��������&�� ����� ��� ��� �� ���������� ��� ��� ��� �� ���� �������� ��� ��� �� ���� �� �������������� �%��!����������� ��1:3"� ���������� ���� ��� �������� � �� #�� ����� ����� �� �����(������� �� ������ ������� ����� �� �� �� �������� ������#������� �� ����9�������������!������������������������� ��+��"����� �������������� �� ��� ��� �� ��������� �����������-/.=1/[�X"[� �� M,>/".3:�X"[O�/","/":�"&������������������������"�X���2:.?2"���%�������������������������� ��� ������� � �� ���� �������� �� ������� � #���� ��� ������ �� ��� �����������������"�X���2:.?2"��,./&'��� ����������������������������������������������� �����1,'"/��� ���������������������������� ���� ��������������?�

"�� ���������� �����(������� �� ��� ��� ��� �� ��� �������� ���� �� #�� �����������������������������:2���m�:>'�:2����������������������������� ����������#������:2����

1��� ���������� ���� �� �������� �� ��� �� ��� ���� �� �� ����������� ����������� ����������� �� �������� ������� ��� !� ���� *� ��� ��� ����������������� �����������������<��������������� ���� ���*-/.=1/[�X"[���2:.?2"+��

�/>-�����������������������������*-/.=1/[�X"[���2:.?2"+�����!� ������ ����������������������� ������� ����

=>�.,[� M�>�2=:O� ��� ��� ��� ����������� �� ���� ��������� ��1:3"�M�>�2=:O���� ����� ����� ����� ��� ���������� ���������������/":1="������ ��������� ����

"�� ��� ����%�� �� 1�'"/� '1;�"� ��� ����� #���� ���� ��1:3"�� =>�.,[��/":1="� �� 1��� ��� ������� ����� ������ � � �� �� ������� ������ � �� �� ����������� �� ��� �� ���� ����� ���� ��� �� ��� �� �)� ��� ��������� �� ��� �������������������!� ������������������ ��������� � ��

��� ������� ��1:3"���=>�.,[� �� �����(���������������� � �������� ����� ������ �������� �����������1:3"���� ��� ������������ ����������������� /":1="� �������� ������� ��� ���� -��� �� ������� ��� ������� 1������������������� �������6������������������������������������ ������ ����

Cambiar la definición de la columna ventas en la tabla Cliente. A partir de ahora se llamará total_vendido, será de tipo decimal(9,2) y eliminar su valor por defecto ALTER TABLE Cliente CHANGE COLUMN ventas total_vendido DECIMAL(9,2); ALTER TABLE Cliente ALTER COLUMN total_vendido DROP DEFAULT;

Page 192: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ � �R�) � �����! �� ��+ / �< & � � � � � ���$ -�� ���� ��

Añadir a la tabla Efectos una columna llamada importe con tipo de datos decimal(7,2). Por defecto tendrá el valor 0 y no admitirá valores nulos ALTER TABLE Efectos ADD COLUMN importe DECIMAL(7,2) NOT NULL DEFAULT 0; Añadir un índice a la tabla Cliente por la columna razon_social ALTER TABLE Cliente ADD INDEX Razon_Social (razon_social); Añadir a la tabla Cliente una columna llamada cp, que almacenará el codigo postal y ponerla después de la columna provincia ALTER TABLE Cliente ADD COLUMN cp INTEGER(5) AFTER poblacion Cambiar la tabla Clientes y eliminar la columna telefono ALTER TABLE Clientes DROP COLUMN telefono; Cambiar el nombre de la tabla Efectos a Recibo ALTER TABLE Efectos RENAME Recibo; Borrar el índice Razon_Social de la tabla Cliente ALTER TABLE Cliente DROP INDEX Razon_Social;

Borrado de tablas con DROP TABLE

��� ��������� �/>-�'1;�"� �������� ������ �� ��� ��������� �� ��� ��� �� �����"������������������������ �����������������������������%����#��� ����� ��� ��� ��� ������ ��� ��� ��� �� �����L���������� ��� � ������� ��� �� ��� ��� �� ����*�;1+���� ������������ ��� ���������������

1�� �������� ���� �� ��� ��� ���� �� �������� ��� !� ���� �� ��� ��������������� �� �� ������ ��� �������� ������� �� � ��� �� ��� ������ �� �� ��������������#�� ���� ����� �������������

�������%�� ���/>-�'1;�"��������������$�

DROP TABLE [IF EXISTS] tablal [, tabla2]...;

:�� �� ��� �� �����(��� �/>-�'1;�"� ������������ ���� �� ��� �� ������� �� ���������������� ���� ���� ����������� ,>/".3:� X"[�� ��� ���� �������� �� � �� ������� ��������������,>/".3:�X"[�������� ��� ��������������

���� ��������������� ���������������#��������� �������� �� �������������� ��� �� ������� �� �� ������� ��������������� ��� ������������ �� ����� ��� ��������� ������������&��#���#���������������� ���� � ���#��#���������(��� ��� ������ �� #������ ��� �������� �� ������� ��� #��#��� �� ������ ��� ����� ��� ���������������� ���������������������������

Page 193: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ � �R�) � �����! �� ��+ / �< & � � � � � ���$ -(� ���� ��

'������� �� ��� �� �����(��� ��� ������������/>-�'1;�"� � ��� ��� �� ��� ����������&������������ ���������� �������� ���*�"�"'"������<������� ����%������������� �� ������� ��� ������� ����� �����(��� �/>-� '1;�"� ����������� �� ���������� �������� ����������������� ������� ������������� ��������������

&��������������������������� �����������%�����=�&?������������������� ��������������������������������������.,�"0.&'&�����/>-�'1;�"����������������� ���� �����������%����������������������������������

Borrar la tabla Clientes DROP TABLE IF EXISTS Clientes;

Borrado de bases de datos con DROP DATABASE

"��=�&?���������������� ���������� ��� �� ������������������� ����� ������� �������������������/>-��1'1;1&"�����������%���������������$�

DROP DATABASE [IF EXISTS] nombre_BD;

&�� �� �������� ��������� ���� ��� �� �������� ��� �%�����=�&?�� ������� ���������� ��������������������������������������.,�"0.&'&�����/>-��1'1;1&"����������������� ������ ��� �� ������������%���������������������������������

������ �� ��������� ���� ��� �� ���� �� ��������� ������ ������������ [��� �������� ������������ ������������%���� ��� ��� �� ����������������� ������*��#�����������������������������.,�"0.&'&+���������� ����������������� ����� ������� ����������������������

��� ��

����� �� #��� ��� ���!����� ����������� ���� #���� �� ���� ��������� &?�� ������� ������������������������ ��� �� �����"��=�&?�����#������� �����#�����������#������������ ��������#������6�H������������������ ����!����������������� ����� ���������#�������=�&?���

������ ������������ �������� ���

"�� � ������� ��� �� ��� ��� �� ���� �� ��� ������� �� �� ��� ������ ���������� �� ������� �� =�&?��� ������� �� ���� ������� �� ��� ��� ��������� �����#� ���� � �� �� ����� ���������������������������� ������������� ������������� ���

"%���� ��� &?�� �� =�&?�� �� ��������� #������ ���� �������� ���� ������������ ��������� ����������������������3/1:'���������������������������#����������������������/"<>X"���������������#��������������������3/1:'��� /"<>X"� �������� �� ������� �� ��� �� ���#�������� ������� �� ������� ������������������������� �����$������*�������������������������� ���������������������#� ��������������������#�����������������+�����*���������������#������� ����#��� �� ��� �� ���+�� ������(���� *��������� ��� ���#������� ����#��� �� �� ��+���������(���� *��������� ��� ���#������� �� ��#��� �� �������+�� ���� ����� �� ��� �������������������� ��'������������������������ ������3/1:'����/"<>X"������ ��������3/1:'��������������������������������� ������������������������� ��������� �� �� ��� ��������� ���������� ���������� ���#������� ��� ��� *� ���������#�� �������� ������� ����� ��� �� ���+���� ������������������������&��������������

Page 194: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ � �R�) � �����! �� ��+ / �< & � � � � � ���$ -*� ���� ��

���� ��� �� ����� �� ��� �� ���#������� �� ��������� �� ��������� ��� ��� �� �������������(������������(�����

Sentencia GRANT

������������3/1:'������ �����#������� ������������������������� ��=�&?���������������&������%���������������$�

GRANT tipo_priv [(lista_col)] [, tipo_priv [(lista_col)]… ON {*.* | * | nombre_bd.* | nombre_bd.nombre_tabla | nombre_tabla } TO usuario IDENTIFIED BY ‘contraseña’ [, usuario IDENTIFIED BY ‘contraseña’] … [WITH GRANT OPTION]

"�� ���������� ��(���� ���������� ��� ���#������� ���� �� ����� ���� ������(��� ���������� ��� �������� *����� �� ���� ����+� �� ������� �� ����� �����������#���������������������� �������������������������� �����#����������������������� ��� �� ������� ��������������

*���������� ����� �������������������������������

1�'"/� 1��������������������������� �����!� ����

�/"1'"� 1����������������������� ��� �� �������� ���

�"�"'"� 1����������������� �������������� ���� ���

�/>-� 1�������������������������� ��� �� �������� ���

.:�"0� 1����������������������������������!� ����

.:&"/'� 1�������������������������#����������� ���

&"�"�'� 1�����������������#������������������ ������� ���

2-�1'"� 1������������������������(����� ���

����� �������������������������� �����#�������� ���������#��

*���������� ����� �������������������������������

,.�"� 1���������������������������� ��������#��

-/>�"&&� 1����� ������� ����� ��#���� ������������ � ��� ��� ������������ ����������� ����������#� ���

/"�>1�� 1����� ������� ����� ��������� ��� �� ��� �� � �� �� #������ ���������������������'�������������� ���� ���

&�2'�>W:� 1�����������������������������#� ���

1��� *1���-/.<.�"3"&+�

1������� ������������

2&13"� -��#���������������E������#������F�

����������>:����������������#���*������� +�����������������������#��������������#���������� ��������� ���������� ������� ����� ��� �� ���������� ����� �� ���� ����!����� �� ���� ��� �� ���� �� ����!����� �� �� ���� ��� ����������� ������������������� �����#��������������������������#��������

;����� .���� ����

Page 195: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ � �R�) � �����! �� ��+ / �< & � � � � � ���$ -0� ���� ��

e�e� -��#���������� ����*�� �����;�b����� ��+�

e� -��#���������� ����*���;�������+�

��� ��@;��e� -��#������� �� ��#��� �� ��� ��� �� ���� ����� �� �� ����� ������ �� �������� ��� �� ����

��� ��@;����� ��@�� ��� -��#�����������#��� ���� ��$��� ���������������������� ������������ ���

��� ��@�� ��� -��#�����������#��� ���� ��$��� ���������������������� ������������ ��������� ��� �� ����

���� �� ��� ���� �� ��� �� �����(�� ��� ������� >:�� ��� ���#������� �� ��� ��������� ���� �������� ����!����� ��� ��� �� ���� �� �� �������� ����� �� ��������������������������(����

��� ������� '>� ���������� ��� ������� ����� ������ ��� ��� ���#�������� �� �������� ������� ��� ��� ��� ��� �� ������� �� ��� ��� ��� �� '��� �� ������ ����������������� �����(�����Z�����('��� �� �������������� ���� �������.�":'.,."��;[����������������������)������������������ � �������������������%��� ������� &�� ��� �� �� ���� ��� ��� ��� ��� ����� �� ����� ����������� �� �� �� ��������

'���������� ����������� ������� ���������� ����������� ��� ��� ��� �� ���������� ���������������������� !��@���k����������� �����������������(� ����������������� �� ��������� ���� ������� ��� ������� ���� ���� �� �������� ������ ��������� �.X"�� ���� �� �� ���� ���������� ���� ��� ����� ������������ �� ������ ��������� �� �� ����� ������� ���#�������� ��������� �� �� ������ ������ ��������������*‘nombre_usuario’@’nombre_host’+��

Crear el usuario rafa, que puede acceder a todas las tablas en la base de datos almacen de cualquier host con la contraseña secreto. GRANT ALL ON almacen.* to rafa IDENTIFIED BY “secreto”; Crear un usuario de nombre maria con privilegios de sólo lectura para las tablas en la base de datos almacen pudiendo conectarse en el host localhost GRANT SELECT ON almacen.* TO maria@localhost; Crear el usuario pepe GRANT USAGE ON *.* TO pepe;

Sentencia REVOKE

������������/"<>X"��������(���������#��������#��������������������������&������%���������������$�

REVOKE tipo_priv [(lista_col)] [, tipo_priv [(lista_col)]]… ON { *.* | * | nombre_bd.* | nombre_bd.nombre_tabla | nombre_tabla } FROM usuario [, usuario]

Page 196: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ � �R�) � �����! �� ��+ / �< & � � � � � ���$ -�� ���� ��

��� ���������� ��� � ������� �� ��� �� ��� ��������� 3/1:'�� /"<>X"� �������������� ������� �� ��� �� �������� ����������� ��� �������� ������� ����=�&?���-���� ��������� ����������� ��� ������� ���� ���� ���� ��� ��������� �/>-� 2&"/� ������������������������������ ���������� ��� ����������������

Revocar todos los privilegios para el usuario rafa en el host local REVOKE ALL ON *.* FROM rafa@localhost; Revocar los derechos de inserción, borrado y actualización a todos los usuarios del host local en la tabla Cliente de la base de datos Almacen REVOKE INSERT, DELETE, UPDATE ON Almacen.Cliente FROM ‘%’@localhost; Revocar el derecho de actualización a la columna referencia de la tabla Artículo en la base de datos Almacen para el usuario pepe en cualquier host REVOKE UPDATE (referencia) ON Almacen.Articulo FROM pepe@’%’;

-���� #��� ��� ����� �� ���#������� �������� �� ��� ������� �� ��� �� �����(��� ��������������������$�

SHOW GRANTS FOR usuario;

Contraseñas mediante SET PASSWORD

[�������#������������ �����������������������3/1:'������ ���� ��������� �������)�� �� �������� ��� ��������� &"'� �� ������ ��� ������� -1&&W>/������������� �������������)�������������� � ���&������%���$�

SET PASSWORD [FOR usuario] = PASSWORD(“contraseña”);

&�� ��� �� ���������� ��� ������� ,>/�� ��� �������)�� �� ��� ����� ����� ������������������

��� ����������� ��

"���� ���������� � ���� ������� ������������ ������� � � ����� ��� �� ����=�&?���-�� ����%������������ ����������������������� ���������#������� ��� ����� ����� �/>-� �1'1;1&"� �� �/>-� '1;�"� ���� ���� ���������������������� �)������� ��� �� �����"���������������������� ���������������� ����������������� ������ �������� ������� � �������������� ���������������� �������������������������������

"��=�&?������ ������ ������������������� ������� � � ����� ��� �� �������������#���������������������� � ��!�������������������������������(������������� ������� ����������#�� ����� ��� �� ������ ����������� ���� �������� ����������������#����!����������������

�������������!������������ ���������� ��������� ����������������������� ������ ������� ������ ��� ������������ ���� ��� ��#� ��� =�&?�� �#���� �� ������ ����� �������(������ ������������������������ ����� ���������������������� ��� �� ����� 1 ���� ������� �����#�� �� ��%��� ��������� ��� �� �����

Page 197: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ � �R�) � �����! �� ��+ / �< & � � � � � ���$ -8� ���� ��

������� ���� ����� ��� ��� ��� ������������� �� ��� ������������ ��� ����� ������ ������� ����������

Copia de seguridad con MySQLDUMP (backups)

�������� � ��!������������ ������������ �� ������� ��� ����� ��� �� ������� �������� �� ��%��� ���� ��� ��� ����� ����� ������ �� ����� � � �� ��� �� ������������#��� ��� �� �������������#� �������������������� ��� �� ���� ������ �� �� �������������%��������&������%����������������

mysqldump [opciones] nombre_BD [nombre_tabla]…

���� �� ��� �� ���������� ��� ��� ��� �� �� ��� �� �� ���� ��� ������� ������� ���� ������� ��� ����� ��� �� ������������%������ �����������#��������� ��� �� ��������������������������� �� ��S�����������������

mysqldump nombre_BD > fichero_backup

:�� � ������� ����� �����(���� ��� ������� UU��� ���� �������� ������� ��� �������� ������������ ���������������/>-�'1;�"���>�X�'1;�"�����������#���������������������������������������&������%����

mysqldump –-opt nombre_BD > fichero_backup

��� �������� �� �� ������� �� �� ����� ��� ������� �� ���� �� �� �������)������� �������� ����������������������������� ������� �����������������(����������������� ��!��

mysqldump –u root –p almacen > almacen.bak

"�� �����#�� �� ����������������� �� ��� �����#�� �� ��%��� ���� ��� ���������&?���������������� ������ ��� ��� �� �������������������� ���������� ��� �����������������.:&"/'��

Recuperación de una base de datos

-���� ��������� ��� �� ��� �� ��� ��� �����(��� ��� �����#�� �� ��S��������� �������!������������������ ��������!������ �������������%��

mysql nombre_BD < fichero_backup

&����������� ������� � � ����� ��� �� ��������������(� �������� ���� ���������������#�� �������!������� ����� �� �����(��� ��� ������������� ������ �� ���������������� ����������� ���� ���"��������������������������������� ����������������� �� ���������� �� ��� ��� �� ����=�&?�� ����� #��#��� �� ������ �� ���������� ��� �� ������ 1 ���� ��� ��#� ��� ��� �� ����������� ����� �� �������� ��������������������������������(������������ ���������

Page 198: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ���$ - � ���� ��

���2 � � � � � �) � ��� � �� � � � + � ��"�� ��� ����� 7� � �� =�&?�� *777���������+� �%����� �� ��������� �� ���

������� ������ ��� �� ������������� ����������������������������������� ���������� ���� ������� ��� �� ��� �� ��������� �� �������������������������������%�������$�

• =�&?��1 �����������5������������� ����� ��� � ������������ ������ ����� ��������� ��� ��#� ��� ����� �� ��� ��� �� ���� ���� ��������������������#� ����

• =�&?��?����� ;��7���5������������� ��������� ��� ������� ��� ������ ����� ���� ��� ��� �� ����� "� ���� �������(� &?�� ����� ����������������������������������� ���

• =�&?�� �������� �������5� "��� ������������ ��� ���� ��������� ��������� *��������&?�+� ���� ��������� ��� ������� ��� *������� ���������� ����%����� ���� ��� �� ����� ����+��=�&?����� ��� � ����� ������������#������������������ ��������������������������#��������������������������������������������

<������#��������� ��������� ������ �����������������������

��� �� ������ ����

Instalación del administrador de MySQL

=�&?�� ������ �� ���� ������������ ����� �����(��� ��� � ������������ �� ��� ��� �� ���$�'�.7��/�������������"�������������������������(������������� ��� ���������������������������������������#� ���=�&?�����������(�������� ����������9������ ��� ��#� ���� ��������� ������� �� ����%������ �����(��� ������ ������� � ��������������� ���������#���&������� ��������#������� ��=�&?��V�H������������

��������!�� �������������� ��������(���������(�� ������������(�����!���� ������� �� �� ���� ��� ������������ O�'�.7�/����� ����� ���� ���������������������������������#������$�

• 32.����������������������

• ,�������������� ����������� ���������� ����� ��������������� � ���������#� ���=�&?���

-�������������������������������������������$�

D� ������������������������ �����������7� � ��=�&?���

G� ��������������������#���(����

4� "����������������#�������?�2���

Page 199: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ���$ --� ���� ��

V� &������������� �����������������

2��� #�(� ������ ��� �� ����� ��� ������ ������� ��� ��� �������������� �������������������� 1�� ��������� ��� �������� ���� �� �� ��� ��� ���� �� ���� ����%���� �� �����#� ��� �� ��� �� ����=�&?���-�������������������������������������$�

Figura 5. Cuadro de conexión al servidor

�������� ��#������ ����������������%������$�

D� ����%����5� -� ���� ������ ������ ����%����� ����� �������� ���������������������(�����������%������� ��������� ������ ��������������������-��������������������%����������������� ��������������������#������������������������������

G� 2�������5�:�� ��� �� �������� &�� �� ��� ����� �� ���� ����%����� ��������������������������

4� -�7�� �5��������)�� ��������#�� ������� �������������������� &�����������������%�������#����� �������� ��������������������������� ��#�(���������������������������������������� ��������

V� �������5�����������.-������ ��� ������������� � �� �������������������������� �����#� �����������������

6� -����5�-������ ���� �� �� ��� ��������� ��� ��#� ��� ����� ��� ��������-��� ������������44HN������#����������� �������

����������������������������� �� ��� ������ ��� �������)������� ��� ����������������� �� ��� � ������� ��� ��� ��#� ��� �� �� �� ��� ��� �� �����-���� ������������������� ��� ������������ ����� ����� ��� �������)�� ��� ��� ���������� �������� �� �� �� ��������� ���� ��������� �� �� �� ���� ����� ��� ������ ��� ��������������������������������������������������������������� �������������� ��� ��� �� ��� ��#� ���� 1� ��� �(����� �� ��������� ��� ������ �� � �������������������� ����������������� ��#�(�������������������������������������(����� ������ ������������ ����� ��������

Page 200: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ����� � � ���� ��

Figura 6. MySQL Administrator

Información del Servidor

"���������������������������������������� ���������%��������� ��������� �����#� ���� ������������ ��� ��#� ��� �� ��� ��������� "��� ��������� �� ������������������#������������������ �������������#������

Control del servicio

"�� �������)�� ���������� ����#���������� ���������������������#������ ���#������ ��������� �� �������������� ��� ��#������ ���� ������������� �� ��� �����#���BPH��H�P�!?��� '�� ���� ��� �� ������� �� ����� ���� ��� ��#����� �� �������������!������ ����������

Variables de inicio

"�� ���� ������� �� ��� ��� ��� ������ #������ ��� �������� �� ��� ���#���� ��� �� ������������ �������������� ������ ���� ��� ��� �����#���������� "���#������ �� ��������� �� ��������� �� �������������� ����� �� ��� =�.&1=�� .����;���������������� ������� ����������� ������� � �������

Administración de usuarios

�� �� ���!� �� ��� ������������ ��� ������� �� ��� ��� �� ���� �� ������#������� �� �������� -���� ��� ������ ��� �������)�� ��� ������� ����� ���� ������������ ��� ��� ������ �(����� �� ��� ��� ������� 8���� /������������� "�� ��� �������������������������������������������� �������(������ ���������������� �������

Page 201: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ����� $ � ���� ��

������� ��������������)������������������ ����������� ���-���H�����������-���H���� "�� ��� ���%���� ����%����� ��� �������)�� ��� ������#�� �� �� �� �����������

1�������������������������������������������(����� ���������������������������������� � �� �� ����� ��� ��� ������� -� ��� ����������� ������� ���#��������� �� ��� ��� ����)����'���� -���� ��� ��������� ����������� ���#������� �� ���������������� ������� ��� �� �����

Conexiones del servidor

"�� ���� ������ �� �� ��� ��� #��� ��� ����%����� �������� ��� ��#� ���� &����������� ������� ��� ������� #������ �� ����%������ 2��� �� ��� ��� �������>�;�� ���� ����� �����(�� �� ��� ������������ W��=�&?�1 ���� �� ����� ��� ��� ���������������������������������-����� ������%�������������������������������� ��������������������� ���� ��� ������� ���"������������������������� �����������������%����������� ��������� ����� ������� ���������� ������� ���������������� ������������������%���������������[����'������

Health

"�������������������(�������#��������� !����� �����#� ����1��!������� ���#��� ��� ������� �� ����%����� ���������!�������%���� ���� ��� � ������ ��������������#������

'�� ���� ��� ��� !����� ���������� �� ��� �������� &?������ �� ���� �������������������������������������������������� ���

Server Logs

"������������������ ���#��������������������������������#� ������������#�� ���� �� ����������� ��� ��� ������� #���� ��� �� �������� 3������������� ���������� �����#� ����� �#� �������������"%������������ �����#� ������� ������� ������������������������*�������������%�������� � �� ���������%�������������������������������&?������������������+��'�� ��������������� ����� �� �����#� ���*������� �����#���������� �� �����#����������%�������#��� �����������+��

"��� ������� �� ����� ����� ��������� ��� ������� �� ������ ��� ������ �� �����������

Estado de las réplicas

&������������� ������ ��� �� ���� ���� �� ����%������������� �����������#� ���� �� ��� �� � ������ ��������� �� ��� ���� �� ��� ��� �� ����� "��������� � ��� �� �������(���� ����� �������� �� ��� ������� ���� ��� �� ���� ������ �������������"������������������ �������� ��������� �� ������������������������ ��� ������������������

Backups

"��� ������� �� �����(�� ����� �����(��� ������ �� ����� � � �� ��� �����-������� ������ ��������� ��S��� ���� ��������(��� ��� �����(������ �� ������ ������� � �� -���� �� �� ��������� ���� ���� ����������� ���� ���� �� #��� �� ���������� ��� �� ����������� ����� �� ��� �� �#� ����� �� ��� ���������� �� �� �� ���������

Page 202: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ����� �� ���� ��

������ ���� ���� ����������� ��� �� �� �� ������ �� ��� ����� 3������������ ������������ &?�� ���� ��������� ��� �� ��������� �� ��� ��� �� ���� �� ���������.:&"/'�������� �����-������������������� ������������������������������������ ���� ������� ������� ��� ����� ������������ �������������������������������� !�� �������� ����������������

Restore

"������������������ ���������������� ������������ �������������� ������� � �� -���� ������ �� �� ����� ��� �����#�� �� ������ �� ����� � � ���� �� ����������������������������� ����� ��������(�� ��������������������������������#�� �������� ������� � �����������#���������������&?�������������������������������������

Catálogo

"�� ���� ������� �� ��� �� ��������� �� ��������� ��� ��������� �� ��� �� ����� &�� �� �� ������ �� ���� �� ������ ��� �������������� �� �� ��� ���� ������������ �������� �� ���� �� ������������'�� ��������� ���������!� ��������#�� ���������� ���#�� �%������� ����� -������������� �� ��� ���������� ��� �� ����� ���� �������������� ���� �����������

��� �� ��������$����

Instalación de MySQL Query Browser

"��� ������������ �������� ��� ����� ���� ���� ��� �� ���� �� �������������� &?��� &�� ������� �� ���� ������� ������� ���� �������(� ������� ���������� �������������&?���"��������#�� �������#� �������������������������� ��������� �#���#����������� ����������������������� �����

-����������������������������������������������$�

D� ������������������������ �����������7� � ��=�&?���

G� ��������������������#���(����

4� "����������������#�������?�2���

V� &������������� �����������������

2���#�(����������� ������������������ ������������������������������������ ������������������������������

1�� ������� �� ��� ��� ���� �� ��� ����%���� �� ��� ��������� �� ����� ������� ������ ���� �� ��� ��������� �����=�&?�� 1 ������������ &�� ��� ����%���� ��� � ����������������������������������������� �#� � ����� ����������������

"�� ��������� ������������������� ����� ��� ������������ ������ ����������� �� ��� #�������� "�� ���� ����� ��� �� ����� ���� ��� ��������� &?�� ���� �� �������������� �������������� �� �����!�� ��� ��� ����� �� ����������� ��� ������ �� ������������������(����������������������������

-�� ��� ���������� ������ ��������� &?�� ����� �� ����� �� �� ���#���������������#������������#�� �� ��� �� ������ ���&�� ������������&?���������

Page 203: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ����� (� ���� ��

������������������������������������ �������������������� ��������� ��������� �� �������������

&���� ��������� �����������#��������������&?����� ������ ��������������� ��� �������� ���&����������������������&�������� �������������������%�H�G���!�)�������� �����������#�������������������������������������

"����������� �������������������������� ����� ��� �� ������������� �� ��������������������������� ����� ������ �������������������� ��� �� ��������������������������������������������%�����&��������������� � �������S�� ������� �� ��� ���������� ��������� ���� ��������� &"�"�'� ��� ��� ����� ��� ����������������A���� � ���� ������ ��� ������������%�������������� �� ���������� �#����������� ��������������&"�"�'���������� ��� �������������������� � � �� ��������� &��������� �� ������ ��� ����� � ���� �� �� �� ������� ��� ��� �� ��� ������������������ ������������)� ���������������������� ������������������ ���

Figura 7. MySQL Query Browser

1 ���������� �������������� ������������������ ������� ��� ������E� ���F� �� %�2�� �� ��� �� ��#����� ���� ���� ���������� ���� ��� ����� �����'� ��#���#��������������������������

"����������������������������������� ����� ������!�����������������"����������� ��������� ����������������������� ����������%��� ����������������������������%�������������� ��� ������������������&?���1��!��� ������������� ������������������������=�&?������������������������������������� ��� �� �����

&���� ��������� ��������(������ ��������� ���� �������������������� ��� �� ������ ��� ���� �� ��� ������ �� �� ���� �������� ��� �� ��� �������(� ���� ����� �� �������� ��� ��� ����� ��������� ���� ��� ����� �������� � ����� ��� �� �� ����

Page 204: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ����� *� ���� ��

�� �#� ����� �� ����� ���������� �� � �������S�� ���������� �������� ��� �������#������������� ����������������'� �������� ��������(� ������������������������������������� ���������!��'�� ��������������������������������(��������� ��� �� ������������ �������������'�� ������ ������������� ����

��� �����������������

"��� ������������ ��� ��� �� �� ������������ � � �� ������ �� ������������� ����������� �� ������ ���� ��� �� ����������� 1 ���� ��� ������ ��� ������������ ���� �������� �����(��� ��� ���� ������ ��� �� ���� ������ ���� ������������ ������%���������� ��� �� ������ ����������&?���������

-�����������������������������������������$�

D� ������������������������ �����������7� � ��=�&?���

G� ��������������������#���(����

4� "����������������#�������?�2���

V� &������������� �����������������

2��� #�(� ������ ��� �� ������ �� ��� ������ ������� ��� ��� ��������� ����������������� ����������������������#�(����������� ��� ��������������������� ��������� �� �������� ����%����� �� ��������������� ������ ����� 1�������� ������������������������������

Figura 8. Pantalla de creación de una conexión al servidor

Page 205: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ����� 0� ���� ��

"�� ��� ����� ���� ���� ����� ����� ���� ���� ���� ��� ���������� &������� ����������� ��� ���������%�������� ����� ���������.-� �����#� ��� �� ����������� ��=�&?�����������������������������(���������%�����&���� ��������� ������� ����� ����������)�������������������� � �����������#��� ����������-�� �������������5�� ����� ���� �� �� #�(� ���� �� ��� ��� ����%���� �� �� ��� �������)�����#��������

1� ������� �� ������� �� �� #�(����� �� �������� ��� ������������� �� �����(��� �������%����� &�� �� ��� ������ ������ ����%����� ����� �� ���������� ���� ������ ���� �� ���� �������� �� ��� ���� ��� ���� �������� �� �� #�(� ���� �� �������� ����������������

1�����������=�&?������ ����� �������(��� ���������������������������� ���������������������

Figura 9. Pantalla principal de MySQL Control Center

"�� ��� ������ �(����� �� �������� ��� � ��� �� ��#� ���� �� ��� ���� �� ��� ������������ ��� ����� �������������� ������ �� ����������� �����(��� ������������� ������������������������� �� ����������������� ���� ��� ����������������� ����� ��� � ��� �� ��#� ���� =�&?��� �� �� ���!� �� ��� ��� ��������� �����������%������� ������

"�� ������ �� � ������������ ��������� �� ��� �� � ����� ��� ������� �� ��� ��� �� ����� � ������������ �� ������� �� ��� ��#� ���� ������� ���� �������������������������������������������������� ��� �������

"�� ��� ����� �� ������������ ��� ��� �����&?������ �� �������� �� �� ������������ ���� ��� �� �����������&������������������ ������������������������������� ����� ����� �������� &?�� ���� ��� ���������� ��������� ��� ������ �� ��� ���

Page 206: Sistemas Gestores de Bases de Datos

����������� ����������� � ����� ���� �������� ��� ����� ��� �����

7�� ��$ $ �R�; ����� ������� �� "��� ��+ / �< & � � � � � ����� �� ���� ��

���������������&���� ������ ������ ������������������� �� ��������������������� ��������� 1 ��� ��� ������ �� ��� � ��� ���� ����� �� ����������� ��������� �� ���� �� ��������

���������� ��#������������������������)� ���� �����#�������#��������������������� �������(������������������������ ���������������������������������� �� �������� �� �� ���� � ��� �� ������� ����������� ��� ������ ���� ������� ��� �� ��� ��� �� ���� �� ��� ������ ������������� ������������������������������ ����������������������=�&�?������� ��� �� ��� ���