Professional Documents
Culture Documents
mysql> create table Profesor(doc_prof varchar(11) primary key not null, nom_prof varchar(30)
not null, ape_profesor varchar(30) not null, cate_prof int, sal_prof int);
mysql> create table Estudiante(doc_est varchar(11) primary key not null, nom_est varchar(30)
not null, ape_est varchar(30) not null, edad_est int);
mysql> create table Cliente(id_cli varchar(11) primary key not null, nom_cli varchar(30) not null,
ape_cli varchar(30) not null, dir_cli varchar(100), dep_cli varchar(20), mes_cum_cli varchar(10));
mysql> create table Articulo(id_art int primary key not null auto_increment, tit_art varchar(100),
aut_art varchar(100), edi_art varchar(300), prec_art int not null);
mysql> create table Pedido(id_pedido int primary key not null auto_increment, id_cli_ped
varchar(11), fec_ped date not null, val_ped int not null);
mysql> alter table pedido add constraint fkid_cli foreign key(id_cli_ped) references
Cliente(id_cli);
mysql> create table Articuloxpedido(id_ped_artped int not null, id_art_artped int, can_art_artped
int, val_ven_art_artped int);
mysql> create table Compaia(comnit varchar(11) primary key not null, comnombre varchar(30)
not null, comaofun int, comreplegal varchar(100));
mysql> create table Automotores(autoplaca varchar(6) primary key not null, automarca
varchar(30) not null, autotipo int, automodelo int, autonumpasajeros int, autocilindraje int,
autonumchasis varchar(20));
mysql> alter table Automotores add constraint fk_tipoauto foreign key(Autotipo) references
TiposAutomotores(autotipo);
mysql> create table aseguramientos(asecodigo int(6) primary key not null auto_increment,
asefechainicio datenot null, asefechainspiracion date not null, asevalorasegurado int not null,
aseestado varchar not null, asecosto int not null, aseplaca varchar(6));
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'date not null,
asefechainspiracion date not null, asevalorasegurado int not null,' at line 1
Como fall varias veces al intentar crear la tabla decid crearla slo con su tabla
primaria para ir aadiendo columnas hasta hallar el error:
mysql> create table aseguramientos(asecodigo int(6) primary key not null auto_increment);
mysql> alter table aseguramientos add asefechainicio date not null after asecodigo;
mysql> alter table aseguramientos add asefechaexpiracion date not null after asefechainicio;
mysql> alter table aseguramientos add asevalorasegurado int not null after asefechaexpiracion;
El problema era que aseestado no tena longitud en el ejercicio y hay varchar hay
que asignarle una:
mysql> alter table aseguramientos add constraint fk_placas foreign key(aseplaca) references
automotores(autoplaca);
mysql> create table incidentes(incicodigo int primary key not null auto_increment, incifecha
date not null, inciplaca varchar(6) not null, incilugar varchar(40) not null, incicantheridos int,
incicantfatalidades int, incicanautosinvolucrados int);
mysql> alter table incidentes add constraint fk_inciplacas foreign key(inciplaca) references
automotores(autoplaca);
-> ('77191956', 'Juan Carlos', 'Arenas', 'Diagonal 23 No. 12-34 apto. 101', 'Valle', 'Marzo'), ->
('1098765789', 'Catalina', 'Zapata', 'Avenida el Libertador No. 30-14', 'Cauca', 'Marzo');
mysql> alter table tiposautomotores add column (autnombre varchar(11) not null); Query OK, 0
rows affected (0.72 sec)
3. Realizamos consultas
Calcular el valor promedio de lso cursos cuyas horas sean mayores a 40:
Mostrar estudiantes (cdigo y nombre) que iniciaron curso el 01-02-2011, del curso
debe mostrarse el nombre, las horas y el valor:
mysql> select doc_est, nom_est, fec_ini_estcur, nom_curs, horas_cur, valor_cur -> from
estudiante join estudiantexcurso join curso
-> on fec_ini_estcur = '2011-01-02'and doc_est = doc_est_estcur and cod_curso_estcur =
cod_curso;
+----------
+-------
+-----------------+-----------+-----------------+------------------------ - ---- +
| doc_est | nom_est | fec_ini_estcur | nom_curs | horas_cur | valor_cur |
+----------------- +-----------------------
--+-------
+-----------------+----------- -- +--------- ---- +
| 1.098.765.678 | Carlos | 2011-01-02 | Manejo de MySQL | 45 | 550000 |
| 1.098.098.097 | Jonatan | 2011-01-02 | Manejo de MySQL | 45 | 550000 |
+----------- +----------------------- +----------
+-------
+----------------- -+----------------- -- - ---- +
2 rows in set (0.01 sec)
mysql> select id_ped_artped, nom_cli, dir_cli, tit_art, prec_art, can_art_artped, val_ped -> from
articuloxpedido join cliente join articulo join pedido
-> on id_cli = id_cli_ped and id_pedido = id_ped_artped and id_ped_artped = 1 and id_art=
id_art_artped;
|
| Diagonal 23 M
No. 12-34 ar
apto. 101 | z
| 77191956 | Juan Carlos | Arenas Valle o|
|
Ant
ioq
| Carrera uia |
30 No. Juni
| 13890234 | Roger | Ariza 13-45 o |
|
Sant
ande
r |
| Calle 34 Abri
| 63502718 | Maritza | Rojas No. 14-45l |
| Avenida el
Libertador |
No. 30-14 | M
| 1098765789 | Catalina | Zapata Cauca ar |
z
o
+-
--
+- --
--- --
+---------- --- --
--------------- --
+------------ +---------------- +-------------------- - --+
Visualizar los pedidos que se han realizado para el artculo con id 2, el listado debe
mostrar nombre, direccin, nmero de pedido y cantidad:
Esa bsqueda da un resultado vaco porque no se ha registrado ningn vehculo que expire en
octubre de 2013.
Pero s se han registrado dos que expiran en septiembre. Si lo hago con septiembre obtengo el
resultado:
Visualizar incidentes del 30 de septiembre de 2012 con nmero de poliza, fecha de inicio,
valor asegurado y valor pliza.
Se obtuvo datos adicionales sobre la sintaxis SQL en los siguientes sitios web:
www.mysqlconclase.net
www.genbetadev.com
www.forosdelweb.com