1 / 14

Base de datos

Base de datos. Francisco Castro http://franciscocastro.ublog.cl. Conceptos básico de consultas. Conceptos básico de consultas. Primero necesitamos poblar una tabla para eso podemos utilizar este ejemplo…. /*==============================================================*/

len-morales
Download Presentation

Base de datos

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Base de datos Francisco Castro http://franciscocastro.ublog.cl

  2. Conceptos básico de consultas

  3. Conceptos básico de consultas • Primero necesitamos poblar una tabla para eso podemos utilizar este ejemplo…

  4. /*==============================================================*//*==============================================================*/ /* Tabla: NUB */ /*==============================================================*/ create table NUB ( ID NUMBER not null, ID2 VARCHAR2(50) not null, constraint PK_NUB primary key (ID, ID2) ); /*==============================================================*/ /* índice: NUB_FK */ /*==============================================================*/ create index NUB_FK on NUB ( ID ASC ); /*==============================================================*/ /* índice: NUB2_FK */ /*==============================================================*/ create index NUB2_FK on NUB ( ID2 ASC ); /*==============================================================*/ /* Tabla: TABLAX */ /*==============================================================*/ create table TABLAX ( NOMBRE VARCHAR2(50) not null, ID NUMBER not null, constraint PK_TABLAX primary key (ID) ); /*==============================================================*/ /* Tabla: TABLAY */ /*==============================================================*/ create table TABLAY ( NOMBRE2 VARCHAR2(50), ID2 VARCHAR2(50) not null, constraint PK_TABLAY primary key (ID2) ); alter table NUB add constraint FK_NUB_NUB_TABLAX foreign key (ID) references TABLAX (ID); alter table NUB add constraint FK_NUB_NUB2_TABLAY foreign key (ID2) references TABLAY (ID2);

  5. Uso Cláusula Select • Indica que tablas y como se deben mostrar principalmente

  6. Uso Cláusula From • Nos indica la o las fuentes de donde obtendremos la información.

  7. Ejemplo ----------------------------------------------------------------- select "TABLAX"."ID" as "ID", "TABLAX"."NOMBRE" as "NOMBRE" from "TABLAX“ ----------------------------------------------------------------- select * from TABLAX -----------------------------------------------------------------

  8. Uso Cláusula Where • Esta cláusula nos sirve para indicarnos condiciones (o filtros) a la hora de realizar una consulta.

  9. Ejemplo

  10. Consultas anidadas

  11. EJERCICIO • En base a lo mostrado anteriormente realizar una consulta anidada que nos permita obtener el campo ID de la tabla NUB que sea igual al ID2 de la tabla TABLAY

  12. Uniones de tablas Select "TABLAX"."ID" as "ID", "TABLAY"."NOMBRE2" as "NOMBRE2" from "TABLAY" , "TABLAX", "NUB" where "TABLAX"."ID"="NUB"."ID" and "NUB"."ID2"="TABLAY"."ID2"

  13. Ejercicio 2

  14. Se pide • Indicar cuantos tramos en construcción tiene cada municipio. • Indicar el largo total de las carreteras. • Indicar el área con mayor cantidad de salidas. • Indicar el municipio con el tramo de carretera mas largo.

More Related