mysql> create database if not exists examen; Query OK, 1 row affected (0.01 sec) mysql> create table persona ( -> id int auto_increment, -> nombre varchar(30), -> edad int, -> key (id), -> primary key (id)); Query OK, 0 rows affected (0.05 sec) mysql> desc persona; +--------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | nombre | varchar(30) | YES | | NULL | | | edad | int(11) | YES | | NULL | | +--------+-------------+------+-----+---------+----------------+ 3 rows in set (0.07 sec) mysql> alter table persona add ap_pat varchar(200); Query OK, 0 rows affected (0.21 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc persona; +--------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | nombre | varchar(30) | YES | | NULL | | | edad | int(11) | YES | | NULL | | | ap_pat | varchar(200) | YES | | NULL | | +--------+--------------+------+-----+---------+----------------+ 4 rows in set (0.02 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('cesar', 'celis', nu ll, 21); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('luisa', 'mondragon' , null, 18); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('pedro', 'solis', nu ll, 18); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('alberto', 'castella nos', null, 27); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('josue', 'larios', n ull, 17); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('andres', 'sanches', null, 22); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('leslie', 'ramirez', null, 20); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('claudia', 'zamora', null, 29); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('leticia', 'sanches' , null, 25); Query OK, 1 row affected (0.00 sec) mysql> insert into persona(nombre, ap_pat, id, edad) values('jose', 'garcia', nu ll, 18); Query OK, 1 row affected (0.00 sec) mysql> select * from persona; +----+---------+------+-------------+ | id | nombre | edad | ap_pat | +----+---------+------+-------------+ | 1 | cesar | 21 | celis | | 2 | luisa | 18 | mondragon | | 3 | pedro | 18 | solis | | 4 | alberto | 27 | castellanos | | 5 | josue | 17 | larios | | 6 | andres | 22 | sanches | | 7 | leslie | 20 | ramirez | | 8 | claudia | 29 | zamora | | 9 | leticia | 25 | sanches | | 10 | jose | 18 | garcia | +----+---------+------+-------------+ 10 rows in set (0.00 sec) mysql> insert into persona values(null, 'andrea', 23, 'lopez'); Query OK, 1 row affected (0.01 sec) mysql> insert into persona values(null, 'roberto', 37, 'alanis'); Query OK, 1 row affected (0.00 sec) mysql> insert into persona values(null, 'jose', 22, 'garcia'); Query OK, 1 row affected (0.00 sec) mysql> insert into persona values(null, 'marisol', 21, 'flores'); Query OK, 1 row affected (0.00 sec) mysql> insert into persona values(null, 'salvador', 21, 'morales'); Query OK, 1 row affected (0.01 sec) mysql> insert into persona values(null, 'claudia', 21, 'peralta'); Query OK, 1 row affected (0.00 sec) mysql> insert into persona values(null, 'miriam', 26, 'hernandez'); Query OK, 1 row affected (0.00 sec) mysql> insert into persona values(null, 'julia', 19, 'hernandez'); Query OK, 1 row affected (0.01 sec) mysql> insert into persona values(null, 'guillermo', 23, 'ramirez'); Query OK, 1 row affected (0.00 sec) mysql> insert into persona values(null, 'jose', 20, 'sanches'); Query OK, 1 row affected (0.00 sec) mysql> select * from persona; +----+-----------+------+-------------+ | id | nombre | edad | ap_pat | +----+-----------+------+-------------+ | 1 | cesar | 21 | celis | | 2 | luisa | 18 | mondragon | | 3 | pedro | 18 | solis | | 4 | alberto | 27 | castellanos | | 5 | josue | 17 | larios | | 6 | andres | 22 | sanches | | 7 | leslie | 20 | ramirez | | 8 | claudia | 29 | zamora | | 9 | leticia | 25 | sanches | | 10 | jose | 18 | garcia | | 11 | andrea | 23 | lopez | | 12 | roberto | 37 | alanis | | 13 | jose | 22 | garcia | | 14 | marisol | 21 | flores | | 15 | salvador | 21 | morales | | 16 | claudia | 21 | peralta | | 17 | miriam | 26 | hernandez | | 18 | julia | 19 | hernandez | | 19 | guillermo | 23 | ramirez | | 20 | jose | 20 | sanches | +----+-----------+------+-------------+ 20 rows in set (0.00 sec) mysql> create table salario( -> id_persona int, -> salario decimal(6,2), -> puesto varchar(200), -> key (id_persona), -> foreign key (id_persona) references persona (id)); Query OK, 0 rows affected (0.07 sec) mysql> desc salario; +------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+-------+ | id_persona | int(11) | YES | MUL | NULL | | | salario | decimal(6,2) | YES | | NULL | | | puesto | varchar(200) | YES | | NULL | | +------------+--------------+------+-----+---------+-------+ 3 rows in set (0.03 sec) mysql> alter table persona drop edad; Query OK, 0 rows affected (0.20 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from persona; +----+-----------+-------------+ | id | nombre | ap_pat | +----+-----------+-------------+ | 1 | cesar | celis | | 2 | luisa | mondragon | | 3 | pedro | solis | | 4 | alberto | castellanos | | 5 | josue | larios | | 6 | andres | sanches | | 7 | leslie | ramirez | | 8 | claudia | zamora | | 9 | leticia | sanches | | 10 | jose | garcia | | 11 | andrea | lopez | | 12 | roberto | alanis | | 13 | jose | garcia | | 14 | marisol | flores | | 15 | salvador | morales | | 16 | claudia | peralta | | 17 | miriam | hernandez | | 18 | julia | hernandez | | 19 | guillermo | ramirez | | 20 | jose | sanches | +----+-----------+-------------+ 20 rows in set (0.00 sec) mysql> alter table salario change puesto puesto_persona varchar(200); Query OK, 0 rows affected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc salario; +----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+-------+ | id_persona | int(11) | YES | MUL | NULL | | | salario | decimal(6,2) | YES | | NULL | | | puesto_persona | varchar(200) | YES | | NULL | | +----------------+--------------+------+-----+---------+-------+ 3 rows in set (0.01 sec) mysql> alter table salario change salario salario_persona int not null; Query OK, 0 rows affected (0.15 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> desc salario; +-----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+-------+ | id_persona | int(11) | YES | MUL | NULL | | | salario_persona | int(11) | NO | | NULL | | | puesto_persona | varchar(200) | YES | | NULL | | +-----------------+--------------+------+-----+---------+-------+ 3 rows in set (0.02 sec) mysql> insert into salario values(1, 5000, 'tecnico'); Query OK, 1 row affected (0.02 sec) mysql> insert into salario values(2, 11000, 'programador'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(3, 4000, 'intendencia'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(4, 12500, 'contador'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(5, 6500, 'tecnico'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(6, 6500, 'tecnico'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(7, 9700, 'ingeniero'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(8, 14250, 'ingeniero'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(9, 8800, 'vendedor'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(10, 4400, 'mensajero'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(11, 6000, 'soporte tecnico'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(12, 17500, 'gerente'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(13, 4950, 'almacenista'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(14, 5350, 'secretaria'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(15, 4350, 'empacador'); Query OK, 1 row affected (0.01 sec) mysql> insert into salario values(16, 6000, 'secretaria'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(17, 6200, 'tecnico'); Query OK, 1 row affected (0.01 sec) mysql> insert into salario values(18, 10500, 'administrador'); Query OK, 1 row affected (0.01 sec) mysql> insert into salario values(19, 7000, 'tecnico'); Query OK, 1 row affected (0.00 sec) mysql> insert into salario values(20, 13000, 'ingeniero'); Query OK, 1 row affected (0.02 sec) mysql> select * from salario; +------------+-----------------+-----------------+ | id_persona | salario_persona | puesto_persona | +------------+-----------------+-----------------+ | 1 | 5000 | tecnico | | 2 | 11000 | programador | | 3 | 4000 | intendencia | | 4 | 12500 | contador | | 5 | 6500 | tecnico | | 6 | 6500 | tecnico | | 7 | 9700 | ingeniero | | 8 | 14250 | ingeniero | | 9 | 8800 | vendedor | | 10 | 4400 | mensajero | | 11 | 6000 | soporte tecnico | | 12 | 17500 | gerente | | 13 | 4950 | almacenista | | 14 | 5350 | secretaria | | 15 | 4350 | empacador | | 16 | 6000 | secretaria | | 17 | 6200 | tecnico | | 18 | 10500 | administrador | | 19 | 7000 | tecnico | | 20 | 13000 | ingeniero | +------------+-----------------+-----------------+ 20 rows in set (0.00 sec) mysql> alter table salario drop puesto_persona; Query OK, 0 rows affected (0.11 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from salario; +------------+-----------------+ | id_persona | salario_persona | +------------+-----------------+ | 1 | 5000 | | 2 | 11000 | | 3 | 4000 | | 4 | 12500 | | 5 | 6500 | | 6 | 6500 | | 7 | 9700 | | 8 | 14250 | | 9 | 8800 | | 10 | 4400 | | 11 | 6000 | | 12 | 17500 | | 13 | 4950 | | 14 | 5350 | | 15 | 4350 | | 16 | 6000 | | 17 | 6200 | | 18 | 10500 | | 19 | 7000 | | 20 | 13000 | +------------+-----------------+ 20 rows in set (0.00 sec) mysql> alter table persona add edad int null default 21; Query OK, 0 rows affected (0.13 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from persona; +----+-----------+-------------+------+ | id | nombre | ap_pat | edad | +----+-----------+-------------+------+ | 1 | cesar | celis | 21 | | 2 | luisa | mondragon | 21 | | 3 | pedro | solis | 21 | | 4 | alberto | castellanos | 21 | | 5 | josue | larios | 21 | | 6 | andres | sanches | 21 | | 7 | leslie | ramirez | 21 | | 8 | claudia | zamora | 21 | | 9 | leticia | sanches | 21 | | 10 | jose | garcia | 21 | | 11 | andrea | lopez | 21 | | 12 | roberto | alanis | 21 | | 13 | jose | garcia | 21 | | 14 | marisol | flores | 21 | | 15 | salvador | morales | 21 | | 16 | claudia | peralta | 21 | | 17 | miriam | hernandez | 21 | | 18 | julia | hernandez | 21 | | 19 | guillermo | ramirez | 21 | | 20 | jose | sanches | 21 | +----+-----------+-------------+------+ 20 rows in set (0.00 sec) mysql> alter table persona add sexo enum('M','F') default 'M'; Query OK, 0 rows affected (0.12 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> select * from persona; +----+-----------+-------------+------+------+ | id | nombre | ap_pat | edad | sexo | +----+-----------+-------------+------+------+ | 1 | cesar | celis | 21 | M | | 2 | luisa | mondragon | 21 | M | | 3 | pedro | solis | 21 | M | | 4 | alberto | castellanos | 21 | M | | 5 | josue | larios | 21 | M | | 6 | andres | sanches | 21 | M | | 7 | leslie | ramirez | 21 | M | | 8 | claudia | zamora | 21 | M | | 9 | leticia | sanches | 21 | M | | 10 | jose | garcia | 21 | M | | 11 | andrea | lopez | 21 | M | | 12 | roberto | alanis | 21 | M | | 13 | jose | garcia | 21 | M | | 14 | marisol | flores | 21 | M | | 15 | salvador | morales | 21 | M | | 16 | claudia | peralta | 21 | M | | 17 | miriam | hernandez | 21 | M | | 18 | julia | hernandez | 21 | M | | 19 | guillermo | ramirez | 21 | M | | 20 | jose | sanches | 21 | M | +----+-----------+-------------+------+------+ 20 rows in set (0.00 sec) mysql> update persona set nombre = 'nallely', ap_pat = 'najera' where id = 1; Query OK, 1 row affected (0.08 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set nombre = 'monica', ap_pat = 'avila' where id = 2; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set nombre = 'monserrat', ap_pat = 'zendejas' where id = 3 ; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set nombre = 'carmen', ap_pat = 'islas' where id = 4; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 26 where id = 1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 22 where id = 2; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 31 where id = 3; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 25 where id = 4; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 40 where id = 5; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 37 where id = 6; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 27 where id = 7; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 28 where id = 8; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 19 where id = 9; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 21 where id = 10; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> update persona set edad = 29 where id = 11; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 31 where id = 12; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 33 where id = 13; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 20 where id = 14; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 22 where id = 15; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 26 where id = 16; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 35 where id = 17; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 19 where id = 18; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 24 where id = 19; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set edad = 21 where id = 20; Query OK, 0 rows affected (0.01 sec) Rows matched: 1 Changed: 0 Warnings: 0 mysql> update persona set sexo = 'F' where sexo = 'M' limit 4; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> update persona set sexo = 'F' where id > 6 limit 3; Query OK, 3 rows affected (0.01 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> update persona set sexo = 'F' where id = 11; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set sexo = 'F' where id = 14; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> update persona set sexo = 'F' where id > 15 limit 3; Query OK, 3 rows affected (0.01 sec) Rows matched: 3 Changed: 3 Warnings: 0 mysql> select * from persona -> ; +----+-----------+-----------+------+------+ | id | nombre | ap_pat | edad | sexo | +----+-----------+-----------+------+------+ | 1 | nallely | najera | 26 | F | | 2 | monica | avila | 22 | F | | 3 | monserrat | zendejas | 31 | F | | 4 | carmen | islas | 25 | F | | 5 | josue | larios | 40 | M | | 6 | andres | sanches | 37 | M | | 7 | leslie | ramirez | 27 | F | | 8 | claudia | zamora | 28 | F | | 9 | leticia | sanches | 19 | F | | 10 | jose | garcia | 21 | M | | 11 | andrea | lopez | 29 | F | | 12 | roberto | alanis | 31 | M | | 13 | jose | garcia | 33 | M | | 14 | marisol | flores | 20 | F | | 15 | salvador | morales | 22 | M | | 16 | claudia | peralta | 26 | F | | 17 | miriam | hernandez | 35 | F | | 18 | julia | hernandez | 19 | F | | 19 | guillermo | ramirez | 24 | M | | 20 | jose | sanches | 21 | M | +----+-----------+-----------+------+------+ 20 rows in set (0.00 sec) mysql> select nombre, ap_pat, edad, sexo from persona; +-----------+-----------+------+------+ | nombre | ap_pat | edad | sexo | +-----------+-----------+------+------+ | nallely | najera | 26 | F | | monica | avila | 22 | F | | monserrat | zendejas | 31 | F | | carmen | islas | 25 | F | | josue | larios | 40 | M | | andres | sanches | 37 | M | | leslie | ramirez | 27 | F | | claudia | zamora | 28 | F | | leticia | sanches | 19 | F | | jose | garcia | 21 | M | | andrea | lopez | 29 | F | | roberto | alanis | 31 | M | | jose | garcia | 33 | M | | marisol | flores | 20 | F | | salvador | morales | 22 | M | | claudia | peralta | 26 | F | | miriam | hernandez | 35 | F | | julia | hernandez | 19 | F | | guillermo | ramirez | 24 | M | | jose | sanches | 21 | M | +-----------+-----------+------+------+ 20 rows in set (0.00 sec) mysql> select nombre, edad from persona where sexo = 'M'; +-----------+------+ | nombre | edad | +-----------+------+ | josue | 40 | | andres | 37 | | jose | 21 | | roberto | 31 | | jose | 33 | | salvador | 22 | | guillermo | 24 | | jose | 21 | +-----------+------+ 8 rows in set (0.00 sec) mysql> select nombre, edad from persona where sexo = 'F'; +-----------+------+ | nombre | edad | +-----------+------+ | nallely | 26 | | monica | 22 | | monserrat | 31 | | carmen | 25 | | leslie | 27 | | claudia | 28 | | leticia | 19 | | andrea | 29 | | marisol | 20 | | claudia | 26 | | miriam | 35 | | julia | 19 | +-----------+------+ 12 rows in set (0.00 sec) mysql> select sexo, count('id') cuantos from persona group by sexo; +------+---------+ | sexo | cuantos | +------+---------+ | M | 8 | | F | 12 | +------+---------+ 2 rows in set (0.00 sec) mysql> select avg(edad) promedio_edad, count('id') cuantos, sexo from persona gr oup by sexo; +---------------+---------+------+ | promedio_edad | cuantos | sexo | +---------------+---------+------+ | 28.6250 | 8 | M | | 25.5833 | 12 | F | +---------------+---------+------+ 2 rows in set (0.00 sec) mysql> select count(id) 'menores de 21', sexo from persona where edad < 22 group by sexo; +---------------+------+ | menores de 21 | sexo | +---------------+------+ | 2 | M | | 3 | F | +---------------+------+ 2 rows in set (0.00 sec) C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqldump -p -u root examen > C:\Use rs\Batcaver\examen.sql Enter password: ********* C:\Program Files\MySQL\MySQL Server 5.6\bin>