Académique Documents
Professionnel Documents
Culture Documents
A. Ingresar las sigueintes tablas en una base de datos llamada VIDEOTIENDA, debajo de
cada uno de los ITEMS escribir el codigo empleado para realizar cada uno de los
ejercicios.
1. Crear al base de datos Videotienda.
mysql> create database videotienda;
2. Crear las tablas expuestas a continuación con sus claves primarias y foráneas.
TABLA SOCIO
NOMBRE DEL CAMPO TIPO DE CAMPO PROPIEDAD
Doc_Socio Int
Nombre Varchar (20) PK
Ciudad Varchar (20) Not null
Teléfono Int Not null
Cod_Pelicula Int FK, Not Null
mysql> create table socio (doc_socio int,nombre varchar(20) primary key,ciudad
varchar(20),telefono int,cod_pelicula int);
mysql> alter table socio add constraint fk_pelic foreign key(cod_pelicula) references
pelicula(cod_pelicula);
TABLA PELICULA
NOMBRE DEL CAMPO TIPO DE CAMPO PROPIEDAD
Cod_Pelicula Int Autonumerico, PK
Titulo Varchar (20) Not null
Genero Varchar (20) Not null
Valor_Compra Mediumint Not null
mysql> create table pelicula (cod_pelicula int primary key auto_increment,titulo
varchar(20),genero varchar(20),valor_compra mediumint);
TABLA ALQUILER
NOMBRE DEL CAMPO TIPO DE CAMPO PROPIEDAD
Num_Alquiler Int Autonumerico, PK
Doc_Socio Int FK, Not null
Cod_Pelicula Int FK, Not null
Fecha_Retiro Date Not null
Fecha_Entrega DateTime Not null
Valor_Alquiler Smallint Not null
mysql> create table alquiler (num_alquiler int primary key auto_increment,doc_socio
int,cod_pelicula int,fecha_retiro date,fecha_entrega datetime,valor_alquiler smallint);
mysql> alter table alquiler add constraint fk_soc foreign key (doc_socio) references socio
(doc_socio);
mysql> alter table alquiler add constraint fk_peli foreign key(cod_pelicula) references
pelicula(cod_pelicula);
5. Ingresar 7 datos a cada tabla; tengan en cuenta lo sgte: En la tabla película los géneros
son (Comedia, Acción, Drama, Romántico, Infantil); el valor_Compra debe estar entre
25000 y 95000. En la tabla Alquiler las fechas de retiro deben estar entre enero y
diciembre de 2017; La fecha de entrega debe estar entre enero y diciembre con su
respectiva hora; El Valor_Alquiler debe estar entre 3000 y 10000.
6. Actualizar al menos uno de los datos de cada uno de los atributos de cada una de las
tablas.
mysql> update alquiler set fecha_retiro='20171108' where num_alquiler='1';
mysql> update alquiler set fecha_entrega='20170631221048' where num_alquiler='2';
mysql> update alquiler set valor_alquiler='5500' where num_alquiler='7';
mysql> update pelicula set titulo="jumanji" where cod_pelicula='6';
mysql> update pelicula set genero="comedia" where cod_pelicula='7';
mysql> update pelicula set valor_compra="50000" where cod_pelicula='6';
mysql> update socio set nombre="daniela" where doc_socio='123';
mysql> update socio set ciudad="cartagena" where doc_socio='665';
mysql> update socio set telefono='2723590' where doc_socio='456';