Académique Documents
Professionnel Documents
Culture Documents
Aprendiz
Edwin Urueta Rodríguez
Abril 2019
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 Estudiantexcurso(cod_curso_estcur int not null, doc_est_estcur varchar(11) not
null, fec_ini_estcur date);
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 Compañia(comnit varchar(11) primary key not null, comnombre varchar(30) not null,
comañofun 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 sólo con su tabla
primaria para ir añadiendo 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 tenía 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);
|
|
| MUL |
NULL | |
| autotipo
| YES
|
| NUL
| YES |L | |
| automodelo | NUL
| autonumpasajeros | int(11) | YES |L | |
|
| NUL
| YES |L | |
| autocilindraje | |
varch NUL
| autonumchasis ar(20) | YES | L | |
+------- +-
-------- +---------
+--------------------- - +------ +------- ------ +
7 rows in set (0.00 sec)
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);
mysql> insert into profesor values('1.098.765.789', 'Alejandra', 'Torres', 4, 1100000); ERROR 1406
(22001): Data too long for column 'doc_profesor' at row 1
-> ('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
+
+--------
--
| sal_prof |
+
+--------
--
| 550000 |
| 690000 |
| 950000 |
| 1100000 |
+
+--------
--
Mostrar cursos con valor mayor a $500000:
+--------- +
--
| 700000 |
| 550000 |
| 3000000 |
+--------- +
--
Calcular el valor promedio de lso cursos cuyas horas sean mayores a 40:
+
+-------------
-----
| avg(valor_cur) |
+------------- +
-----
| 1775000.0000 |
+
+-------------
------
1 row in set (0.00 sec)
+
+-----------
----
| 550000.0000 |
+
+-----------
----
1 row in set (0.02 sec)
Mostrar todos los campos de la tabla curso en orden ascendente por 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;
r
e
c
i
r
t
a
l 4
c 0
0
0
0
| 3 | ||
s
l
|
i
s
t
r
a
c
i
s
i
s
t
e
a
s
e
r
a 5
t 5
i 0
10
20
| 4s| | |
|
e 6
5
e 0
s 0
c 50
| 1 i | ||
s
c
c
e
i
t
t
e
r
a
a
5
5
l 0
t 10
00
| 2s| | |
|
r
e
c
i
4
5
r 0
t 10
a 20
| 3 l | ||
c
l
|
e
s 6
c 5
i 0
s 0
c 0
| 1 | ||
+
-
-
- +
- -
- -
- -
- +-
- --
- --
- --
- --
- --
- --
- --
- --
- --
- --
- --
- --
- --
- --
- --
- --
+--------------- - --
- --
- - -+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Todos los clientes organizados por apellido:
|
| Diagonal 23M
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 artículo con id 2, el listado debe
mostrar nombre, dirección, número de pedido y cantidad:
Esa búsqueda da un resultado vacío porque no se ha registrado ningún vehículo 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 número de poliza, fecha de inicio, valor
asegurado y valor póliza.
Se obtuvo datos adicionales sobre la sintaxis SQL en los siguientes sitios web:
www.mysqlconclase.net
www.genbetadev.com
www.forosdelweb.com