You are on page 1of 16

UNIVERSIDAD AUTONOMA DE

CHIHUAHUA
FACULTAD DE INGENIERIA
22/NOVIEMBRE/2011
INGENIERIA DE SOFTWARE Y COMPUTACION II

Nombre:

Noel Cuevas Soltero


Eduardo Curiel Prez
Jonathan Talavera Aguilar

Matricula:

245279
244931
225704

MANEJO DE SQL
PROYECTO FINAL

Ejercicio 1.- ...................................................................................................................... 2


Creacin de la base de datos ......................................................................................... 2
Creacin de la tabla alumnos .................................................................................... 2
Insercin de datos ................................................................................................. 2
Creacin de la tabla MATERIAS ............................................................................. 4
Insercin de datos ................................................................................................. 4
Creacin de la tabla de MAESTROS ....................................................................... 5
Insercion de datos ................................................................................................. 5
Creacion de la tabla de HORARIOS ........................................................................ 6
Insercin de datos ................................................................................................. 6
Ejercicio 2.- ...................................................................................................................... 7
Ejercicio 3 ......................................................................................................................... 9
Ejercicio 4.- .................................................................................................................... 10
Ejercicio 5.- .................................................................................................................... 11
Ejercicio 6.- .................................................................................................................... 12
Ejercicio 7.- .................................................................................................................... 13
Ejercicio 8.- .................................................................................................................... 14
Ejercicio 9.- .................................................................................................................... 15
Ejercicio 10.- .................................................................................................................. 16

Ejercicio 1.Creacin de la base de datos


Crear una base de datos llamada LABFINAL, en la cual se debern generar las siguientes tablas,
las cuales debern incluir la informacin tal y como viene especificado.
create database LABFINAL;

Creacin de la tabla alumnos


1.-Tabla ALUMNOS:
create table ALUMNOS(
MATRICULA int,
NOMBRE varchar(30),
APELLIDO_P varchar(30),
APELLIDO_M varchar(30),
EMAIL varchar(30)
);

Insercin de datos
insert into alumnos
values(1,'Juan', 'Arevalo',
'Rodriguez', 'juan@dominio.com');
insert into alumnos

values(2,'Pedro', 'Bustamante',
'Rodriguez', 'pedro@dominio.com');
insert into alumnos
values(3,'Maria', 'Tagle',
'Contreras', 'maria@dominio.com');
insert into alumnos
values(4,'Concepcion', 'Hidalgo',
'Madero', 'concepcion@dominio.com');
insert into alumnos
values(5,'Felipe', 'Frisco',
'Villa', 'felipe@dominio.com');
insert into alumnos
values(6,'Guadalupe', 'Hidalgo',
'Contreras', 'guadalupe@dominio.com');
select *
from alumnos;

Creacin de la tabla MATERIAS


create table MATERIAS(
Clave varchar(6),
NOMBRE_MAT varchar(30),
CREDITOS int
);

Insercin de datos
insert into materias
values ('A', 'Matematicas', 10);
insert into materias
values ('B', 'Espaol', 10);
insert into materias
values ('C', 'Historia', 8);
select *
from materias

Creacin de la tabla de MAESTROS


create table MAESTROS(
CLAVE_M int,
NOMBRE_M varchar(30),
APELLIDO_P_M varchar(30),
APELLIDO_M_M varchar(30),
EMAIL_M varchar(30)
);

Insercion de datos
insert into maestros
values (100, 'Jorge', 'Cantor',
'Cantor', 'jorge.cantor@dominio.com');
insert into maestros
values (101, 'Josefa', 'Ortiz',
'Dominguez', 'josefa.ortiz@dominio.com');
insert into maestros
values (102, 'Gabriel', 'Garcia',
'Marquez', 'gabriel.garcia@dominio.com');
select *
from maestros

Creacion de la tabla de HORARIOS


create table HORARIOS(
NUM int,
CLAVE_MAT varchar(6),
MATRICULA_ALUMNO int,
CLAVE_MTRO int,
CALIFICACION real
);

Insercin de datos
insert into horarios
values (1, 'A', 1, 100, null);
insert into horarios
values (2, 'B', 1, 101, null);
insert into horarios
values (3, 'A', 2, 100, null);
insert into horarios
values (4, 'C', 2, 102, null);
insert into horarios
values (5, 'B', 3, 101, null);
insert into horarios
values (6, 'C', 3, 102, null);
insert into horarios
values (7, 'A', 4, 102, null);
insert into horarios
values (8, 'B', 4, 101, null);
insert into horarios
values (9, 'A', 5, 100, null);
insert into horarios
values (10, 'C', 5, 102, null);
insert into horarios
values (11, 'B', 6, 101, null);
insert into horarios
values (12, 'C', 6, 102, null);
select *
from horarios

Ejercicio 2.Corregir el campo de calificacin, para que cada alumno tenga sus calificaciones dadas de alta,
utilizar la sentencia UPDATE, deber hacer una sentencia para cada uno de los registros.
update horarios set calificacion=10
where num =1;
update horarios set calificacion=9
where num =2;
update horarios set calificacion=8.8
where num =3;
update horarios set calificacion=7
where num =4;
update horarios set calificacion=9.2
where num =5;
update horarios set calificacion=7.5
where num =6;
update horarios set calificacion=10
where num =7;
update horarios set calificacion=9.9
where num =8;
update horarios set calificacion=5
where num =9;

update horarios set calificacion=6.1


where num =10;
update horarios set calificacion=5.7
where num =11;
update horarios set calificacion=6.9
where num =12;
select *
from horarios

Ejercicio 3
Suponga que el registro numero 12 de la tabla HORARIOS esta incorrecto, por esta razn es
necesario darlo de baja.
delete
from horarios
where num=12;
select *
from horarios

Ejercicio 4.Consultar nombre y apellido paterno de los alumnos del profesor Jorge Cantor.
select A.nombre, A.apellido_p
from alumnos A, horarios B
where A.matricula=B.matricula_alumno and B.clave_mtro=100;

10

Ejercicio 5.Realizar un reporte que nos muestre nombre, apellido paterno del profesor y la cantidad de
alumnos dados de alta.
select A.nombre_m, A.apellido_p_m, (count (B.matricula_alumno)) as
alumnos_alta
from maestros A, horarios B
where A.clave_m = B.clave_mtro
group by A.nombre_m, A.apellido_p_m;

11

Ejercicio 6.Seleccionar las 3 calificaciones ms altas, mostrando nombre y el apellido paterno del alumno.
select top 3 A.nombre, A.apellido_p, max(B.calificacion)as
calificacion
from alumnos A, horarios B
where A.matricula=B.matricula_alumno
group by A.nombre, A.apellido_p
order by calificacion desc;

12

Ejercicio 7.Listar la matricula, Nombre de Materia y calificacin de los alumnos que hayan reprobado
materias. La calificacin aprobatoria es >=6.0.
select A.matricula_alumno, A.calificacion, B.nombre_mat
from horarios A, materias B
where A.clave_mat = B.clave and A.calificacion<6;

13

Ejercicio 8.Realizar la consulta para el horario de Juan Arevalo (Matricula 1) Incluyendo: Nombre, clave,
Crditos de la materia y nombre del profesor (con apellidos).
select A.matricula, A.nombre, A.apellido_p, B.clave, B.nombre_mat,
B.creditos,
C.nombre_m, C.apellido_p_m, C.apellido_m_m
from alumnos A, materias B, maestros C, horarios D
where A.matricula = D.matricula_alumno and D.clave_mat = B.clave and
C.clave_m = D.clave_mtro and A.matricula=1;

14

Ejercicio 9.Realizar una copia de seguridad de la tabla de HORARIOS a HORANEW, se respaldaran solo
aquellos horarios en donde su materia tenga como numero de crditos = 10.
create table HORANEW(
NUM int,
CLAVE_MAT varchar(6),
MATRICULA_ALUMNO int,
CLAVE_MTRO int,
CALIFICACION real
);
insert into horanew
select *
from horarios
where clave_mat in (select clave
from horarios A, materias B
where A.clave_mat = B.clave and B.creditos = 10);
select *
from horanew

15

Ejercicio 10.Despus se deber de borrar la tabla de HORARIOS.


drop table horarios;

16

You might also like