Está en la página 1de 22

Laboratorio 12-

Diogenes Eli Castrillon Rodriguez.


Aprendiz-SENA
Ejercicios:

1. Cree una base de datos llamada laboratoriosSQL.

R// Creando la base de datos << laboratoriosSQL>>

mysql> create database laboratorioSQL;


Query OK, 1 row affected (0.09 sec)

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| centromedico |
| laboratoriosql |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)

mysql>

2. Ubicado en la base de datos que acab� de crear, construya las siguientes


tablas con los respectivos campos y tipos de datos.
Table-profesor.

mysql> use laboratoriosql;


Database changed
mysql> create table Profesor(
-> doc_prof varchar(11) not null,
-> nom_prof varchar(30) not null,
-> ape_prof varchar(30) not null,
-> cate_prof int not null,
-> sal_prof int not null,
-> primary key(doc_prof)
-> );
Query OK, 0 rows affected (0.82 sec)

mysql> describe profesor;


+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| doc_prof | varchar(11) | NO | PRI | NULL | |
| nom_prof | varchar(30) | NO | | NULL | |
| ape_prof | varchar(30) | NO | | NULL | |
| cate_prof | int(11) | NO | | NULL | |
| sal_prof | int(11) | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

mysql>

Tabla � Curso
mysql> create table Curso(
-> cod_curs int not null auto_increment,
-> nom_cur varchar(100) not null,
-> horas_cur int not null,
-> valor_cur int not null,
-> primary key(cod_curs)
-> )auto_increment=1;
Query OK, 0 rows affected (0.38 sec)

mysql> describe Curso;


+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| cod_curs | int(11) | NO | PRI | NULL | auto_increment |
| nom_cur | varchar(100) | NO | | NULL | |
| horas_cur | int(11) | NO | | NULL | |
| valor_cur | int(11) | NO | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

mysql>

Tabla_Estudiante.
mysql> create table Estudiante(
-> doc_est varchar(11) not null,
-> nom_est varchar(30) not null,
-> ape_est varchar(30) not null,
-> edad_est int not null,
-> primary key(doc_est)
-> );
Query OK, 0 rows affected (0.58 sec)

mysql> describe Estudiante;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| doc_est | varchar(11) | NO | PRI | NULL | |
| nom_est | varchar(30) | NO | | NULL | |
| ape_est | varchar(30) | NO | | NULL | |
| edad_est | int(11) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql>

Tabla-EstudiantexCurso.
mysql> create table Estudiantexcurso(
-> cod_cur_estcur int(11) not null,
-> doc_est_estcur varchar(11) not null,
-> fec_ini_estcur date not null,
-> Foreign key(cod_cur_estcur) references Curso(cod_curs),
-> Foreign key(doc_est_estcur) references Estudiante(doc_est)
-> );
Query OK, 0 rows affected (0.55 sec)

mysql> describe Estudiantexcurso;


+----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| cod_cur_estcur | int(11) | NO | MUL | NULL | |
| doc_est_estcur | varchar(11) | NO | MUL | NULL | |
| fec_ini_estcur | date | NO | | NULL | |
+----------------+-------------+------+-----+---------+-------+
3 rows in set (0.23 sec)

mysql>

Tabla-Cliente.
mysql> create table Cliente(
-> id_cli varchar(11) not null,
-> nom_cli varchar(30) not null,
-> ape_cli varchar(30) not null,
-> dir_cli varchar(100) not null,
-> dep_cli varchar(20) not null,
-> mes_cum_cli varchar(10) not null,
-> Primary key(id_cli)
-> );
Query OK, 0 rows affected (0.51 sec)

mysql> describe Cliente;


+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| id_cli | varchar(11) | NO | PRI | NULL | |
| nom_cli | varchar(30) | NO | | NULL | |
| ape_cli | varchar(30) | NO | | NULL | |
| dir_cli | varchar(100) | NO | | NULL | |
| dep_cli | varchar(20) | NO | | NULL | |
| mes_cum_cli | varchar(10) | NO | | NULL | |
+-------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)

mysql>

Tabla-Articulo

mysql> create table Articulo(


-> id_art int not null auto_increment,
-> tit_art varchar(100) not null,
-> aut_art varchar(100) not null,
-> edi_art varchar(300) not null,
-> prec_art int not null,
-> Primary key(id_art)
-> );
Query OK, 0 rows affected (0.41 sec)

mysql> describe Articulo;


+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id_art | int(11) | NO | PRI | NULL | auto_increment |
| tit_art | varchar(100) | NO | | NULL | |
| aut_art | varchar(100) | NO | | NULL | |
| edi_art | varchar(300) | NO | | NULL | |
| prec_art | int(11) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+
5 rows in set (0.05 sec)
mysql>

Tabla-Pedido

mysql> describe pedido;


+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| id_ped | int(11) | NO | PRI | NULL | auto_increment |
| id_cli_ped | varchar(11) | NO | MUL | NULL | |
| fec_pec | date | NO | | NULL | |
| val_ped | int(11) | NO | | NULL | |
+------------+-------------+------+-----+---------+----------------+
4 rows in set (0.49 sec)

Tabla-Articuloxpedido

mysql> create table Articuloxpedido(


-> id_ped_artped int not null,
-> id_art_artped int not null,
-> can_art_artped int not null,
-> val_ven_art_artped int not null,
-> Foreign key(id_ped_artped) references Pedido(id_ped),
-> Foreign key(id_art_artped) references articulo(id_art)
-> );
Query OK, 0 rows affected (6.43 sec)

mysql> describe Articuloxpedido;


+--------------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+---------+------+-----+---------+-------+
| id_ped_artped | int(11) | NO | MUL | NULL | |
| id_art_artped | int(11) | NO | MUL | NULL | |
| can_art_artped | int(11) | NO | | NULL | |
| val_ven_art_artped | int(11) | NO | | NULL | |
+--------------------+---------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql>

Tabla-Compa��a
mysql> create table Compa�ia(
-> comnit varchar(11) not null,
-> comnombre varchar(30) not null,
-> coma�ofun int not null,
-> comreplegal int not null,
-> Primary key(comnit)
-> );
Query OK, 0 rows affected (4.44 sec)

mysql> describe Compa�ia;


+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| comnit | varchar(11) | NO | PRI | NULL | |
| comnombre | varchar(30) | NO | | NULL | |
| coma�ofun | int(11) | NO | | NULL | |
| comreplegal | int(11) | NO | | NULL | |
+-------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql>

Tabla- TiposAutomotores

mysql> create table TipoAutomotores(


-> auttipo int not null,
-> primary key(auttipo)
-> );
Query OK, 0 rows affected (4.87 sec)
mysql> describe tipoautomotores;
+---------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| auttipo | int(11) | NO | PRI | NULL | |
+---------+---------+------+-----+---------+-------+
1 row in set (0.00 sec)

mysql>

Tabla-Automotores.

mysql> create table Automotores(


-> autoplaca varchar(6) not null,
-> Automarca varchar(30) not null,
-> Autotipo int not null,
-> Automodelo int not null,
-> Autonumpasajeros int not null,
-> autocilindraje int not null,
-> Autonumchasis int not null,
-> Primary key(autoplaca),
-> constraint fk_tipoauto Foreign Key(Autotipo) references
TipoAutomotores(auttipo)
-> );
Query OK, 0 rows affected (10.85 sec)

mysql> describe Automotores;


+------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-------------+------+-----+---------+-------+
| autoplaca | varchar(6) | NO | PRI | NULL | |
| Automarca | varchar(30) | NO | | NULL | |
| Autotipo | int(11) | NO | MUL | NULL | |
| Automodelo | int(11) | NO | | NULL | |
| Autonumpasajeros | int(11) | NO | | NULL | |
| autocilindraje | int(11) | NO | | NULL | |
| Autonumchasis | int(11) | NO | | NULL | |
+------------------+-------------+------+-----+---------+-------+
7 rows in set (0.00 sec)

mysql>

Tabla-Aseguramientos.
mysql> create table Aseguramientos(
-> asecodigo int(6) primary key not null auto_increment,
-> asefechainicio date not null,
-> asefechaexpiracion date not null,
-> asevalorasegurado int not null,
-> aseestado varchar(20) not null,
-> asecosto int not null,
-> aseplaca varchar(20) not null,
-> constraint fk_placaase Foreign key(aseplaca) references
Automotores(autoplaca)
-> );
Query OK, 0 rows affected (4.89 sec)

mysql> describe Aseguramientos;


+--------------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+-------------+------+-----+---------+----------------+
| asecodigo | int(6) | NO | PRI | NULL | auto_increment |
| asefechainicio | date | NO | | NULL | |
| asefechaexpiracion | date | NO | | NULL | |
| asevalorasegurado | int(11) | NO | | NULL | |
| aseestado | varchar(20) | NO | | NULL | |
| asecosto | int(11) | NO | | NULL | |
| aseplaca | varchar(20) | NO | MUL | NULL | |
+--------------------+-------------+------+-----+---------+----------------+
7 rows in set (0.70 sec)

mysql>
Tabla-Incidentes.
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,
-> inciantheridos int not null,
-> incicanfatalidades int not null,
-> incicanautosinvolucrados int not null,
-> constraint fk_placainci Foreign key(inciplaca) references
Automotores(autoplaca)
-> );
Query OK, 0 rows affected (7.64 sec)

mysql> describe incidentes;


+--------------------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------------+-------------+------+-----+---------+----------------+
| incicodigo | int(11) | NO | PRI | NULL | auto_increment |
| incifecha | date | NO | | NULL | |
| inciplaca | varchar(6) | NO | MUL | NULL | |
| incilugar | varchar(40) | NO | | NULL | |
| inciantheridos | int(11) | NO | | NULL | |
| incicanfatalidades | int(11) | NO | | NULL | |
| incicanautosinvolucrados | int(11) | NO | | NULL | |
+--------------------------+-------------+------+-----+---------+----------------+
7 rows in set (0.52 sec)

mysql>
mysql> use laboratoriosql;
Database changed
mysql> show tables from laboratoriosql;
+--------------------------+
| Tables_in_laboratoriosql |
+--------------------------+
| articulo |
| articuloxpedido |
| aseguramientos |
| automotores |
| cliente |
| compa�ia |
| curso |
| estudiante |
| estudiantexcurso |
| incidentes |
| pedido |
| profesor |
| tipoautomotores |
+--------------------------+
13 rows in set (0.00 sec)

mysql>

3. Inserte los siguientes registros seg�n las tablas que se presentan a


continuaci�n:
Modificamos la longitud del par�metro doc_prof --> varchar(11) a varchar(20).
mysql> alter table profesor modify doc_prof varchar(20);
Query OK, 0 rows affected (10.88 sec)
Records: 0 Duplicates: 0 Warnings: 0

Ingresando los a la tabla profesor.


mysql> create table profesor(
-> doc_prof varchar(20) not null,
-> nom_prof varchar(30) not null,
-> ape_prof varchar(30) not null,
-> cate_prof int not null,
-> sal_prof int not null,
-> primary key(doc_prof)
-> );
Query OK, 0 rows affected (1.66 sec)

mysql> insert into profesor(doc_prof,nom_prof,ape_prof,cate_prof,sal_prof)


-> values('91.216.904', 'Carlos', 'P�rez', 3, 950000);
Query OK, 1 row affected (0.55 sec)

mysql> insert into profesor(doc_prof,nom_prof,ape_prof,cate_prof,sal_prof)


-> values('13.826.789', 'Maritza', 'Angarita', 1, 550000);
Query OK, 1 row affected (0.16 sec)

mysql> insert into profesor values('1.098.765.789', 'Alejandra', 'Torres', 4,


1100000);
Query OK, 1 row affected (0.29 sec)

mysql> select * from profesor;


+---------------+-----------+----------+-----------+----------+
| doc_prof | nom_prof | ape_prof | cate_prof | sal_prof |
+---------------+-----------+----------+-----------+----------+
| 1.098.765.789 | Alejandra | Torres | 4 | 1100000 |
| 13.826.789 | Maritza | Angarita | 1 | 550000 |
| 63.502.720 | Martha | Rojas | 2 | 690000 |
| 91.216.904 | Carlos | P�rez | 3 | 950000 |
+---------------+-----------+----------+-----------+----------+
4 rows in set (0.00 sec)

mysql> insert into curso values


-> (149842, 'Fundamentos de bases de datos', 40, 500000),(250067,'Fundamentos
de SQL', 20, 700000),(289011, 'Manejo de MYSQL', 45, 550000),(345671, 'Fundamentals
of Oracle',60, 3000000);
Query OK, 4 rows affected (0.25 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from curso;


+----------+-------------------------------+-----------+-----------+
| cod_curs | nom_cur | horas_cur | valor_cur |
+----------+-------------------------------+-----------+-----------+
| 149842 | Fundamentos de bases de datos | 40 | 500000 |
| 250067 | Fundamentos de SQL | 20 | 700000 |
| 289011 | Manejo de MYSQL | 45 | 550000 |
| 345671 | Fundamentals of Oracle | 60 | 3000000 |
+----------+-------------------------------+-----------+-----------+
4 rows in set (0.00 sec)

mysql>

Error por longitud de �doc_est�.


mysql> insert into estudiante values ('63.502.720', 'Mar�a', 'Perez', 23),
('91.245.678', 'Carlos Jose', 'Lopez', 25),('1.098.098.097', 'Jonatan', 'Ardila',
17),('1.098.765.768', 'Carlos', 'Martinez', 19);
ERROR 1406 (22001): Data too long for column 'doc_est' at row 3
mysql> show table from estudiante;
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 'from
estudiante' at line 1

Modifico la longitud de �doc_est�.


mysql> alter table estudiante modify doc_est varchar(20);
Query OK, 0 rows affected (3.28 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> describe estudiante;


+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| doc_est | varchar(20) | NO | PRI | NULL | |
| nom_est | varchar(30) | NO | | NULL | |
| ape_est | varchar(30) | NO | | NULL | |
| edad_est | int(11) | NO | | NULL | |
+----------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> insert into estudiante values ('63.502.720', 'Mar�a', 'Perez', 23),


('91.245.678', 'Carlos Jose', 'Lopez', 25),('1.098.098.097', 'Jonatan', 'Ardila',
17),('1.098.765.768', 'Carlos', 'Martinez', 19);
Query OK, 4 rows affected (0.46 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from estudiante;


+---------------+-------------+----------+----------+
| doc_est | nom_est | ape_est | edad_est |
+---------------+-------------+----------+----------+
| 1.098.098.097 | Jonatan | Ardila | 17 |
| 1.098.765.768 | Carlos | Martinez | 19 |
| 63.502.720 | Mar�a | Perez | 23 |
| 91.245.678 | Carlos Jose | Lopez | 25 |
+---------------+-------------+----------+----------+
4 rows in set (0.00 sec)

Modificamos la longitud doc_cur_estcur;

mysql> alter table estudiantexcurso modify doc_est_estcur varchar(20);


Query OK, 0 rows affected (1.67 sec)
Records: 0 Duplicates: 0 Warnings: 0
Ya que dio muchos errores toco deshabilitar las claves for�neas por un momento con
los siguientes comandos.

Desactivaci�n de todas las claves for�neas:


SET FOREIGN_KEY_CHECKS = 0;

Activaci�n:
SET FOREIGN_KEY_CHECKS = 1;

Datos de la tabla articulo.


mysql> UPDATE articulo SET tit_art = ' Administracion de sistemas operativos '
WHERE id_art = 4;
Query OK, 1 row affected (1.45 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from articulo;


+--------+-----------------------------------------+-----------------------
+---------------+----------+
| id_art | tit_art | aut_art |
edi_art | prec_art |
+--------+-----------------------------------------+-----------------------
+---------------+----------+
| 1 | Redes cisco | Ernesto Arigasello |
AlfaomegaRama | 60000 |
| 2 | Facebook y twitter para adulto | Veloso Claudio |
AlfaOmega | 55000 |
| 3 | Creaci�n de un portal con php y mysql | Jacobo Pav�n Puertas |
AlfaOmegaRama | 40000 |
| 4 | Administracion de sistemas operativos | Julio G�mez |
AlfaomegaRama | 55000 |
+--------+-----------------------------------------+-----------------------
+---------------+----------+
4 rows in set (0.15 sec)

mysql> UPDATE articulo SET prec_art = 55000 WHERE id_art = 4;


Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> select * from articulo;


+--------+-----------------------------------------+-----------------------
+---------------+----------+
| id_art | tit_art | aut_art |
edi_art | prec_art |
+--------+-----------------------------------------+-----------------------
+---------------+----------+
| 1 | Redes cisco | Ernesto Arigasello |
AlfaomegaRama | 60000 |
| 2 | Facebook y twitter para adulto | Veloso Claudio |
AlfaOmega | 55000 |
| 3 | Creaci�n de un portal con php y mysql | Jacobo Pav�n Puertas |
AlfaOmegaRama | 40000 |
| 4 | Administracion de sistemas operativos | Julio G�mez |
AlfaomegaRama | 55000 |
+--------+-----------------------------------------+-----------------------
+---------------+----------+
4 rows in set (0.00 sec)

mysql>

Datos Ingresados en la tabla pedido:


mysql> insert into pedido (id_cli_ped,fec_pec,val_ped) values
-> ('63502718','2011-12-10',260000),
-> ('63502718','2012-02-25',120000),
-> ('77191956','2012-04-30',55000),
-> ('1098765789','2012-02-25',1800000);
Query OK, 4 rows affected (0.49 sec)
Records: 4 Duplicates: 0 Warnings: 0

mysql> select * from pedido;


+--------+------------+------------+---------+
| id_ped | id_cli_ped | fec_pec | val_ped |
+--------+------------+------------+---------+
| 1 | 63502718 | 2011-12-10 | 260000 |
| 2 | 63502718 | 2012-02-25 | 120000 |
| 3 | 77191956 | 2012-04-30 | 55000 |
| 4 | 1098765789 | 2012-02-25 | 1800000 |
+--------+------------+------------+---------+
4 rows in set (0.00 sec)

mysql>

Datos ingresados en la tabla articuloxpedido;


mysql> insert into articuloxpedido values
-> (1, 3, 5, 40000),
-> (1, 4, 12, 55000),
-> (2, 1, 5, 65000),
-> (3, 2, 10, 55000),
-> (3, 3, 12, 45000),
-> (4, 1, 20, 65000);
Query OK, 6 rows affected (0.22 sec)
Records: 6 Duplicates: 0 Warnings: 0

mysql> select * from articuloxpedido;


+---------------+---------------+----------------+--------------------+
| id_ped_artped | id_art_artped | can_art_artped | val_ven_art_artped |
+---------------+---------------+----------------+--------------------+
| 1 | 3 | 5 | 40000 |
| 1 | 4 | 12 | 55000 |
| 2 | 1 | 5 | 65000 |
| 3 | 2 | 10 | 55000 |
| 3 | 3 | 12 | 45000 |
| 4 | 1 | 20 | 65000 |
+---------------+---------------+----------------+--------------------+
6 rows in set (0.00 sec)

mysql>
Datos Ingresados en Compa��a.
-------------+---------------------+------------+---------------------+
| comnit | comnombre | coma�ofun | comreplegal |
+-------------+---------------------+------------+---------------------+
| 800890890-2 | Seguros Atlantida | 1998 | Carlos L�pez |
| 899999999-1 | Aseguradora Rojas | 1991 | Luis Fernando Rojas |
| 899999999-5 | Seguros del Estadio | 2001 | Maria Margarita |
+-------------+---------------------+------------+---------------------+
3 rows in set (0.02 sec)

mysql>

Agregamos la columna autnombre a la tabla Tipoautomotores;

mysql> alter table tipoautomotores add column (autnombre varchar(11) not null);
Query OK, 0 rows affected (1.24 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> describe tipoautomores;


ERROR 1146 (42S02): Table 'laboratoriosql.tipoautomores' doesn't exist
mysql> describe tipoautomotores;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| auttipo | int(11) | NO | PRI | NULL | |
| autnombre | varchar(11) | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql>

mysql> insert into tipoautomotores values (1, 'Autom�viles'), (2, 'Camperos'), (3,
'Camiones');
Query OK, 3 rows affected (0.17 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from tipoautomotores;


+---------+--------------+
| auttipo | autnombre |
+---------+--------------+
| 1 | Autom�viles |
| 2 | Camperos |
| 3 | Camiones |
+---------+--------------+
3 rows in set (0.01 sec)
mysql>

Datos Ingresado en la tabla Automotores:


mysql> insert into automotores values
-> ('FLL420', 'Chevrolet corsa', 1, 2003, 5, 1400, 'wywzzz167kk009d25'),
-> ('DKZ820', 'Renault stepway', 1, 2008, 5, 1600, 'wywzzz157kk009d45'),
-> ('KJQ920', 'Kia sportage', 2, 2009, 7, 2000, 'wywzzz157kk009d25');
Query OK, 3 rows affected (0.30 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from automotores;


+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+
| autoplaca | Automarca | Autotipo | Automodelo | Autonumpasajeros |
autocilindraje | Autonumchasis |
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+
| DKZ820 | Renault stepway | 1 | 2008 | 5 |
1600 | wywzzz157kk009d45 |
| FLL420 | Chevrolet corsa | 1 | 2003 | 5 |
1400 | wywzzz167kk009d25 |
| KJQ920 | Kia sportage | 2 | 2009 | 7 |
2000 | wywzzz157kk009d25 |
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+
3 rows in set (0.00 sec)

mysql>

Datos ingresados de la tabla aseguramientos;

mysql> insert into aseguramientos values ('1', '2012-09-30', '2013-09-30',


30000000, 'Vigente', 500000,'FLL420');
Query OK, 1 row affected (4.24 sec)

mysql> insert into aseguramientos values (2, '2012-09-27', '2013-09-27', 35000000,


'Vigente', 600000, 'DKZ820'),
-> (3, '2011-09-28', '2012-09-28', 50000000, 'Vencido',800000,'KJQ920');
Query OK, 2 rows affected (0.25 sec)
Records: 2 Duplicates: 0 Warnings: 0

Datos ingresados en la tabla Incidentes: mysql> insert into incidentes values


-> (1, '2012-09-30', 'DKZ820', 'Bucaramanga', 0, 0, 2),
-> (2, '2012-09-27', 'FLL420', 'Gir�n', 1, 0, 1),
-> (3, '2011-09-28', 'FLL420', 'Bucaramanga', 1, 0, 2);
Query OK, 3 rows affected (0.25 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from incidentes;


+------------+------------+-----------+-------------+----------------
+--------------------+--------------------------+
| incicodigo | incifecha | inciplaca | incilugar | inciantheridos |
incicanfatalidades | incicanautosinvolucrados |
+------------+------------+-----------+-------------+----------------
+--------------------+--------------------------+
| 1 | 2012-09-30 | DKZ820 | Bucaramanga | 0 |
0 | 2 |
| 2 | 2012-09-27 | FLL420 | Gir�n | 1 |
0 | 1 |
| 3 | 2011-09-28 | FLL420 | Bucaramanga | 1 |
0 | 2 |
+------------+------------+-----------+-------------+----------------
+--------------------+--------------------------+
3 rows in set (0.00 sec)

mysql>

4 � realizar consultas.
Muestre los salarios de los profesores ordenados por categor�a .

Muestre los cursos cuyo valor sea mayor a $500.000.


mysql> select valor_cur from curso where valor_cur > 500000;
+-----------+
| valor_cur |
+-----------+
| 700000 |
| 550000 |
| 3000000 |
+-----------+
3 rows in set (0.21 sec)

mysql>
Cuente el n�mero de estudiantes cuya edad sea mayor a 22.
select count(*) from estudiante where edad_est > 22;
+----------+
| count(*) |
+----------+
| 2 |
+----------+
1 row in set (0.22 sec)

mysql>
Muestre el nombre y la edad del estudiante m�s joven.
select edad_est from estudiante order by edad_est asc limit 1;
+----------+
| edad_est |
+----------+
| 17 |
+----------+
1 row in set (0.00 sec)

mysql>
Calcule el valor promedio de los cursos cuyas horas sean mayores a 40.
mysql> select avg(valor_cur) from curso where horas_cur > 40;
+----------------+
| avg(valor_cur) |
+----------------+
| 1775000.0000 |
+----------------+
1 row in set (0.01 sec)
mysql>
Obtener el sueldo promedio de los profesores de la categor�a 1.
mysql> select avg(sal_prof) from profesor where cate_prof = 1;
+---------------+
| avg(sal_prof) |
+---------------+
| 550000.0000 |
+---------------+
1 row in set (0.01 sec)

mysql>

Muestre todos los campos de la tabla curso en orden ascendente seg�n


el valor.
mysql> select * from curso order by valor_cur asc;
+----------+-------------------------------+-----------+-----------+
| cod_curs | nom_curs | horas_cur | valor_cur |
+----------+-------------------------------+-----------+-----------+
| 149842 | Fundamentos de bases de datos | 40 | 500000 |
| 289011 | Manejo de MySQL | 45 | 550000 |
| 250067 | Fundamentos de SQL | 20 | 700000 |
| 345671 | Fundamentos de Oracle | 60 | 3000000 |
+----------+-------------------------------+-----------+-----------+
4 rows in set (0.00 sec)

mysql>

Muestre el nombre del profesor con menor sueldo.


mysql> select nom_prof from profesor order by sal_prof asc limit 1;
+----------+
| nom_prof |
+----------+
| Maritza |
+----------+
1 row in set (0.00 sec)

mysql>

Visualizar todos los estudiantes (c�digo y nombre) que iniciaron cursos


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_cur_estcur = cod_curs;
+---------------+---------+----------------+-----------------+-----------
+-----------+
| doc_est | nom_est | fec_ini_estcur | nom_curs | horas_cur |
valor_cur |
+---------------+---------+----------------+-----------------+-----------
+-----------+
| 1.098.098.097 | Jonatan | 2011-01-02 | Manejo de MySQL | 45 |
550000 |
+---------------+---------+----------------+-----------------+-----------
+-----------+
1 row in set (0.14 sec)

mysql>
Visualice los profesores cuyo sueldo este entre $500.000 y $700.000.
mysql> select nom_prof, ape_prof, sal_prof
-> from profesor
-> where sal_prof >= 500000 and sal_prof <= 700000;
+----------+----------+----------+
| nom_prof | ape_prof | sal_prof |
+----------+----------+----------+
| Maritza | Angarita | 550000 |
| Martha | Rojas | 690000 |
+----------+----------+----------+
2 rows in set (0.00 sec)

mysql>

Visualizar el nombre, apellido y direcci�n de todos aquellos clientes


que hayan realizado un pedido el d�a 25 /02/2012.

mysql> select nom_cli, ape_cli, fec_pec


-> from cliente join pedido
-> on id_cli = id_cli_ped and fec_pec = '2012-02-25';
+----------+---------+------------+
| nom_cli | ape_cli | fec_pec |
+----------+---------+------------+
| Maritza | Rojas | 2012-02-25 |
| Catalina | Zapata | 2012-02-25 |
+----------+---------+------------+
2 rows in set (0.00 sec)

mysql>

Listar todos los pedidos realizados incluyendo el nombre del articulo.


mysql> select fec_pec, tit_art, nom_cli, can_art_artped
-> from articulo join articuloxpedido join pedido join cliente
-> on id_cli_ped = id_cli and id_ped_artped = id_ped and id_art =
id_art_artped;
+------------+-----------------------------------------+-------------
+----------------+
| fec_pec | tit_art | nom_cli |
can_art_artped |
+------------+-----------------------------------------+-------------
+----------------+
| 2011-12-10 | Creaci�n de un portal con php y mysql | Maritza |
5 |
| 2011-12-10 | Administracion de sistemas operativos | Maritza |
12 |
| 2012-02-25 | Redes cisco | Maritza |
5 |
| 2012-04-30 | Facebook y twitter para adulto | Juan Carlos |
10 |
| 2012-04-30 | Creaci�n de un portal con php y mysql | Juan Carlos |
12 |
| 2012-02-25 | Redes cisco | Catalina |
20 |
+------------+-----------------------------------------+-------------
+----------------+
6 rows in set (0.14 sec)

mysql>

Visualizar los clientes que cumplen a�os en marzo.


mysql> select nom_cli, mes_cum_cli
-> from cliente
-> where mes_cum_cli = 'Marzo';
+-------------+-------------+
| nom_cli | mes_cum_cli |
+-------------+-------------+
| Catalina | Marzo |
| Juan Carlos | Marzo |
+-------------+-------------+
2 rows in set (0.00 sec)

mysql>

Visualizar los datos del pedido 1, incluyendo el nombre del cliente, la direcci�n
del mismo, el nombre y el valor de los art�culos que tiene dicho pedido.

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_ped = id_ped_artped and id_ped_artped = 1 and
id_art=id_art_artped;
+---------------+---------+--------------------
+-----------------------------------------+----------+----------------+---------+
| id_ped_artped | nom_cli | dir_cli | tit_art
| prec_art | can_art_artped | val_ped |
+---------------+---------+--------------------
+-----------------------------------------+----------+----------------+---------+
| 1 | Maritza | Calle 34 No. 14-45 | Creaci�n de un portal con php y
mysql | 40000 | 5 | 260000 |
| 1 | Maritza | Calle 34 No. 14-45 | Administracion de sistemas
operativos | 55000 | 12 | 260000 |
+---------------+---------+--------------------
+-----------------------------------------+----------+----------------+---------+
2 rows in set (0.05 sec)

mysql>

Visualizar el nombre del cliente, la fecha y el valor del pedido m�s costoso.
mysql> select nom_cli, fec_pec,val_ped
-> from cliente join pedido
-> on id_cli = id_cli_ped order by val_ped desc limit 1;
+----------+------------+---------+
| nom_cli | fec_pec | val_ped |
+----------+------------+---------+
| Catalina | 2012-02-25 | 1800000 |
+----------+------------+---------+
1 row in set (0.02 sec)

mysql>
Mostrar cuantos art�culos se tienen de cada editorial.
mysql> select count(*) as id_art
-> from articulo
-> group by edi_art;
+--------+
| id_art |
+--------+
| 1 |
| 3 |
+--------+
2 rows in set (0.09 sec)

mysql>

Mostrar los pedidos con los respectivos art�culos(c�digo, nombre, valor


y cantidad pedida).
mysql> select id_art_artped, tit_art, can_art_artped, val_ven_art_artped
-> from articuloxpedido join articulo join pedido
-> on id_ped = id_ped_artped and id_art = id_art_artped;
+---------------+-----------------------------------------+----------------
+--------------------+
| id_art_artped | tit_art | can_art_artped |
val_ven_art_artped |
+---------------+-----------------------------------------+----------------
+--------------------+
| 3 | Creaci�n de un portal con php y mysql | 5 |
40000 |
| 4 | Administracion de sistemas operativos | 12 |
55000 |
| 1 | Redes cisco | 5 |
65000 |
| 2 | Facebook y twitter para adulto | 10 |
55000 |
| 3 | Creaci�n de un portal con php y mysql | 12 |
45000 |
| 1 | Redes cisco | 20 |
65000 |
+---------------+-----------------------------------------+----------------
+--------------------+
6 rows in set (0.07 sec)

mysql>

Visualizar todos los clientes organizados por apellido.


mysql> select * from cliente order by ape_cli;
+------------+-------------+---------+---------------------------------+-----------
+-------------+
| id_cli | nom_cli | ape_cli | dir_cli | dep_cli
| mes_cum_cli |
+------------+-------------+---------+---------------------------------+-----------
+-------------+
| 77191956 | Juan Carlos | Arenas | Diagonal 23 No. 12-34 apto. 101 | Valle
| Marzo |
| 13890234 | Roger | Ariza | Carrera 30 No. 13-45 | Antioquia
| Junio |
| 63502718 | Maritza | Rojas | Calle 34 No. 14-45 | Santander
| Abril |
| 1098765789 | Catalina | Zapata | Avenida el Libertador No. 30-14 | Cauca
| Marzo |
+------------+-------------+---------+---------------------------------+-----------
+-------------+
4 rows in set (0.00 sec)

mysql>

Visualizar todos los art�culos organizados por autor.

Visualizar los pedidos que se han realizado para el articulo con id 2, el


listado debe mostrar el nombre y direcci�n del cliente, el respectivo
n�mero de pedido y la cantidad solicitada.

mysql> select id_art_artped, nom_cli, dir_cli, can_art_artped


-> from articuloxpedido join cliente join pedido join articulo
-> on id_art = id_art_artped and id_art_artped = 2 group by id_art;
+---------------+----------+---------------------------------+----------------+
| id_art_artped | nom_cli | dir_cli | can_art_artped |
+---------------+----------+---------------------------------+----------------+
| 2 | Catalina | Avenida el Libertador No. 30-14 | 10 |
+---------------+----------+---------------------------------+----------------+
1 row in set (0.01 sec)

Visualizar los datos de las empresas fundadas entre el a�o 1991 y 1998.

mysql> select * from compa�ia


-> where coma�ofun >= 1991 and coma�ofun <= 1998;
+-------------+-------------------+------------+---------------------+
| comnit | comnombre | coma�ofun | comreplegal |
+-------------+-------------------+------------+---------------------+
| 800890890-2 | Seguros Atlantida | 1998 | Carlos L�pez |
| 899999999-1 | Aseguradora Rojas | 1991 | Luis Fernando Rojas |
+-------------+-------------------+------------+---------------------+
2 rows in set (0.21 sec)

mysql>

Listar los todos datos de los automotores cuya p�liza expira en octubre
de 2013, este reporte debe visualizar la placa, el modelo, la marca,
n�mero de pasajeros, cilindraje nombre de automotor, el valor de la
p�liza y el valor asegurado.

mysql> select autoplaca, automarca, autotipo, automodelo, autonumpasajeros,


autocilindraje,
-> autonumchasis, asefechaexpiracion
-> from automotores join aseguramientos
-> on autoplaca = aseplaca and asefechaexpiracion > '2013-10-01' and
asefechaexpiracion <
-> '2013-10-31';
Empty set (0.08 sec)

mysql> select autoplaca, automarca, autotipo, automodelo, autonumpasajeros,


autocilindraje,
-> autonumchasis, asefechaexpiracion
-> from automotores join aseguramientos
-> on autoplaca = aseplaca and asefechaexpiracion >= '2013-09-01' and
asefechaexpiracion <='2013-09-30';
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+--------------------+
| autoplaca | automarca | autotipo | automodelo | autonumpasajeros |
autocilindraje | autonumchasis | asefechaexpiracion |
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+--------------------+
| FLL420 | Chevrolet corsa | 1 | 2003 | 5 |
1400 | wywzzz167kk009d25 | 2013-09-30 |
| DKZ820 | Renault stepway | 1 | 2008 | 5 |
1600 | wywzzz157kk009d45 | 2013-09-27 |
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+--------------------+
2 rows in set (0.00 sec)

mysql>

Visualizar los datos de los incidentes ocurridos el 30 de septiembre de


2012, con su respectivo n�mero de p�liza, fecha de inicio de la p�liza,
valor asegurado y valor de la p�liza.

mysql> select asecodigo, asefechainicio, asecosto, asevalorasegurado, incicodigo,


incifecha, inciplaca, incilugar, inciantheridos, incicanfatalidades,
incicanautosinvolucrados
-> from aseguramientos join incidentes
-> on incifecha = '2012-09-30'group by incifecha;
+-----------+----------------+----------+-------------------+------------
+------------+-----------+-------------+----------------+--------------------
+--------------------------+
| asecodigo | asefechainicio | asecosto | asevalorasegurado | incicodigo |
incifecha | inciplaca | incilugar | inciantheridos | incicanfatalidades |
incicanautosinvolucrados |
+-----------+----------------+----------+-------------------+------------
+------------+-----------+-------------+----------------+--------------------
+--------------------------+
| 1 | 2012-09-30 | 500000 | 30000000 | 1 | 2012-09-
30 | DKZ820 | Bucaramanga | 0 | 0 |
2 |
+-----------+----------------+----------+-------------------+------------
+------------+-----------+-------------+----------------+--------------------
+--------------------------+
1 row in set (0.00 sec)

mysql>

Visualizar los datos de los incidentes que han tenido un(1) herido, este
reporte debe visualizar la placa del automotor, con los respectivos
datos de la p�liza como son fecha de inicio, valor, estado y valor asegurado.
mysql> select incicodigo, inciplaca, asefechainicio, asecosto, aseestado,
asevalorasegurado,
-> inciantheridos
-> from incidentes join aseguramientos
-> on inciplaca = aseplaca and inciantheridos = 1;
+------------+-----------+----------------+----------+-----------
+-------------------+----------------+
| incicodigo | inciplaca | asefechainicio | asecosto | aseestado |
asevalorasegurado | inciantheridos |
+------------+-----------+----------------+----------+-----------
+-------------------+----------------+
| 2 | FLL420 | 2012-09-30 | 500000 | Vigente |
30000000 | 1 |
| 3 | FLL420 | 2012-09-30 | 500000 | Vigente |
30000000 | 1 |
+------------+-----------+----------------+----------+-----------
+-------------------+----------------+
2 rows in set (0.00 sec)

Visualizar todos los datos de la p�liza m�s costosa.


mysql> select * from aseguramientos order by asecosto desc limit 1;
+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+
| asecodigo | asefechainicio | asefechaexpiracion | asevalorasegurado | aseestado |
asecosto | aseplaca |
+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+
| 3 | 2011-09-28 | 2012-09-28 | 50000000 | Vencido |
800000 | KJQ920 |
+-----------+----------------+--------------------+-------------------+-----------
+----------+----------+
1 row in set (0.00 sec)

mysql>

Visualizar los incidentes con el m�nimo n�mero de autos involucrados,


de este incidente visualizar el estado de la p�liza y el valor asegurado.
mysql> select incicodigo, incifecha, inciplaca, incilugar, inciantheridos,
incicanfatalidades,
-> incicanautosinvolucrados, asecodigo, asevalorasegurado
-> from incidentes join aseguramientos
-> on inciplaca = aseplaca order by incicanautosinvolucrados asc limit 1;
+------------+------------+-----------+-----------+----------------
+--------------------+--------------------------+-----------+-------------------+
| incicodigo | incifecha | inciplaca | incilugar | inciantheridos |
incicanfatalidades | incicanautosinvolucrados | asecodigo | asevalorasegurado |
+------------+------------+-----------+-----------+----------------
+--------------------+--------------------------+-----------+-------------------+
| 2 | 2012-09-27 | FLL420 | Gir�n | 1 |
0 | 1 | 1 | 30000000 |
+------------+------------+-----------+-----------+----------------
+--------------------+--------------------------+-----------+-------------------+
1 row in set (0.00 sec)

mysql>

Visualizar los incidentes del veh�culo con placas " FLL420", este reporte
debe visualizar la fecha, el lugar, la cantidad de heridos del incidente,
la fecha de inicio la de expiraci�n de la p�liza y el valor asegurado.

mysql> select incifecha, inciplaca, incilugar, inciantheridos, asefechainicio,


asefechaexpiracion,
-> asevalorasegurado
-> from incidentes join aseguramientos
-> on inciplaca = aseplaca and inciplaca = 'FLL420';
+------------+-----------+-------------+----------------+----------------
+--------------------+-------------------+
| incifecha | inciplaca | incilugar | inciantheridos | asefechainicio |
asefechaexpiracion | asevalorasegurado |
+------------+-----------+-------------+----------------+----------------
+--------------------+-------------------+
| 2012-09-27 | FLL420 | Gir�n | 1 | 2012-09-30 | 2013-09-
30 | 30000000 |
| 2011-09-28 | FLL420 | Bucaramanga | 1 | 2012-09-30 | 2013-09-
30 | 30000000 |
+------------+-----------+-------------+----------------+----------------
+--------------------+-------------------+
2 rows in set (0.01 sec)

mysql>
Visualizar los datos de la empresa con nit 899999999-5.
mysql> select * from compa�ia where comnit = '899999999-5';
+-------------+---------------------+------------+-----------------+
| comnit | comnombre | coma�ofun | comreplegal |
+-------------+---------------------+------------+-----------------+
| 899999999-5 | Seguros del Estadio | 2001 | Maria Margarita |
+-------------+---------------------+------------+-----------------+
1 row in set (0.00 sec)

mysql>

Visualizar los datos de la p�liza cuyo valor asegurado es el m�s


costoso, este reporte adem�s de visualizar todos los datos de la p�liza,
debe presentar todos los datos del veh�culo que tiene dicha p�liza.
mysql> select asecodigo, asefechainicio, asefechaexpiracion, aseplaca, aseestado,
-> asevalorasegurado, automarca, autotipo, automodelo, autocilindraje,
autonumchasis
-> from aseguramientos join automotores
-> on aseplaca = autoplaca order by asevalorasegurado desc limit 1;
+-----------+----------------+--------------------+----------+-----------
+-------------------+--------------+----------+------------+----------------
+-------------------+
| asecodigo | asefechainicio | asefechaexpiracion | aseplaca | aseestado |
asevalorasegurado | automarca | autotipo | automodelo | autocilindraje |
autonumchasis |
+-----------+----------------+--------------------+----------+-----------
+-------------------+--------------+----------+------------+----------------
+-------------------+
| 3 | 2011-09-28 | 2012-09-28 | KJQ920 | Vencido |
50000000 | Kia sportage | 2 | 2009 | 2000 |
wywzzz157kk009d25 |
+-----------+----------------+--------------------+----------+-----------
+-------------------+--------------+----------+------------+----------------
+-------------------+
1 row in set (0.00 sec)

mysql>
mysql>

Visualizar los datos de las p�lizas de los automotores tipo 1, este


reporte debe incluir placa, marca, modelo, cilindraje del veh�culo junto
con la fecha de inicio, de finalizaci�n y estado de la p�liza.
mysql> select autoplaca, automarca, autotipo, automodelo, autonumpasajeros,
autocilindraje,
-> autonumchasis, asefechainicio, asefechaexpiracion, aseestado,
asevalorasegurado
-> from automotores join aseguramientos
-> on aseplaca = autoplaca and autotipo = 1;
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+----------------+--------------------
+-----------+-------------------+
| autoplaca | automarca | autotipo | automodelo | autonumpasajeros |
autocilindraje | autonumchasis | asefechainicio | asefechaexpiracion |
aseestado | asevalorasegurado |
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+----------------+--------------------
+-----------+-------------------+
| FLL420 | Chevrolet corsa | 1 | 2003 | 5 |
1400 | wywzzz167kk009d25 | 2012-09-30 | 2013-09-30 | Vigente |
30000000 |
| DKZ820 | Renault stepway | 1 | 2008 | 5 |
1600 | wywzzz157kk009d45 | 2012-09-27 | 2013-09-27 | Vigente |
35000000 |
+-----------+-----------------+----------+------------+------------------
+----------------+-------------------+----------------+--------------------
+-----------+-------------------+
2 rows in set (0.04 sec)

mysql>

También podría gustarte