mysql> create database credito; Query OK, 1 row affected (0.13 sec) mysql> use credito; Database changed mysql> create table compra( -> idcompra int primary key, -> descripcion varchar(20), -> numcuotas int); Query OK, 0 rows affected (1.02 sec) mysql> create table cliente( -> idcliente int primary key, -> nombre varchar(20), -> dir varchar(45), -> tel int); Query OK, 0 rows affected (0.30 sec) mysql> create table tipocliente( -> idtipocliente int primary key, -> descripcion varchar(45), -> idcliente int, -> idcompra int, -> foreign key(idcliente) references cliente(idcliente) on update cascade on delete cascade, -> foreign key(idcompra) references compra(idcompra) on update cascade on delete cascade); Query OK, 0 rows affected (0.49 sec) mysql> create table producto( -> idproducto int primary key, -> descripcion varchar(45), -> presio double, -> idtipocredito int); Query OK, 0 rows affected (0.63 sec) mysql> alter table tipocliente rename to tipocredito; Query OK, 0 rows affected (0.25 sec) mysql> alter table tipocredito modify idtipocredito int primary key; ERROR 1054 (42S22): Unknown column 'idtipocredito' in 'tipocredito' mysql> alter table tipocredito drop primary key; Query OK, 0 rows affected (0.84 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe tipocredito; +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | idtipocliente | int(11) | NO | | NULL | | | descripcion | varchar(45) | YES | | NULL | | | idcliente | int(11) | YES | MUL | NULL | | | idcompra | int(11) | YES | MUL | NULL | | +---------------+-------------+------+-----+---------+-------+ 4 rows in set (0.19 sec) mysql> alter table tipocredito drop idtipocliente; Query OK, 0 rows affected (0.67 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe tipocredito; +-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | descripcion | varchar(45) | YES | | NULL | | | idcliente | int(11) | YES | MUL | NULL | | | idcompra | int(11) | YES | MUL | NULL | | +-------------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> alter table tipocredito add idtipocredito int primary key first; Query OK, 0 rows affected (0.66 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe tipocredito; +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | idtipocredito | int(11) | NO | PRI | NULL | | | descripcion | varchar(45) | YES | | NULL | | | idcliente | int(11) | YES | MUL | NULL | | | idcompra | int(11) | YES | MUL | NULL | | +---------------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> describe producto; +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | idproducto | int(11) | NO | PRI | NULL | | | descripcion | varchar(45) | YES | | NULL | | | presio | double | YES | | NULL | | | idtipocredito | int(11) | YES | | NULL | | +---------------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> alter table producto add foreign key(idtipocredito) references tipocredito(idtipocredito) on update cascade on delete cascade; Query OK, 0 rows affected (0.66 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe producto; +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | idproducto | int(11) | NO | PRI | NULL | | | descripcion | varchar(45) | YES | | NULL | | | presio | double | YES | | NULL | | | idtipocredito | int(11) | YES | MUL | NULL | | +---------------+-------------+------+-----+---------+-------+ 4 rows in set (0.02 sec) mysql> create table ref_pers( -> idref_pers int primary key, -> nombre varchar(20), -> dir varchar(45), -> tel int, -> email varchar(50)); Query OK, 0 rows affected (0.31 sec) mysql> create table cliente_ref_pers( -> idcliente int, -> idref_pers int, -> foreign key(idcliente) references cliente(idcliente) on update cascade on delete cascade, -> foreign key(idref_pers) references ref_pers(idref_pers) on update cascade on delete cascade); Query OK, 0 rows affected (0.55 sec) mysql> show tables; +-------------------+ | Tables_in_credito | +-------------------+ | cliente | | cliente_ref_pers | | compra | | producto | | ref_pers | | tipocredito | +-------------------+ 6 rows in set (0.16 sec) mysql> describre cliente; 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 'describre cliente' at line 1 mysql> describe cliente; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | idcliente | int(11) | NO | PRI | NULL | | | nombre | varchar(20) | YES | | NULL | | | dir | varchar(45) | YES | | NULL | | | tel | int(11) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 4 rows in set (0.06 sec) mysql> describe cliente_ref_pers; +------------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+---------+------+-----+---------+-------+ | idcliente | int(11) | YES | MUL | NULL | | | idref_pers | int(11) | YES | MUL | NULL | | +------------+---------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> describe compra; +-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | idcompra | int(11) | NO | PRI | NULL | | | descripcion | varchar(20) | YES | | NULL | | | numcuotas | int(11) | YES | | NULL | | +-------------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> describe producto; +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | idproducto | int(11) | NO | PRI | NULL | | | descripcion | varchar(45) | YES | | NULL | | | presio | double | YES | | NULL | | | idtipocredito | int(11) | YES | MUL | NULL | | +---------------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> describe ref_pers; +------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-------+ | idref_pers | int(11) | NO | PRI | NULL | | | nombre | varchar(20) | YES | | NULL | | | dir | varchar(45) | YES | | NULL | | | tel | int(11) | YES | | NULL | | | email | varchar(50) | YES | | NULL | | +------------+-------------+------+-----+---------+-------+ 5 rows in set (0.02 sec) mysql> describe tipocredito; +---------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+-------+ | idtipocredito | int(11) | NO | PRI | NULL | | | descripcion | varchar(45) | YES | | NULL | | | idcliente | int(11) | YES | MUL | NULL | | | idcompra | int(11) | YES | MUL | NULL | | +---------------+-------------+------+-----+---------+-------+ 4 rows in set (0.02 sec) mysql> exit; mysql> use credito; Database changed mysql> show tables; +-------------------+ | Tables_in_credito | +-------------------+ | cliente | | cliente_ref_pers | | compra | | producto | | ref_pers | | tipocredito | +-------------------+ 6 rows in set (0.00 sec) mysql> create table vendedor( -> idvendedor int primary key, -> nombre varchar(20), -> dir varchar(45), -> tel int); Query OK, 0 rows affected (0.63 sec) mysql> create table vende_cliente( -> idcliente int, -> idvendedor int, -> foreign key(idcliente) references cliente(idcliente) on update cascade on delete cascade, -> foreign key(idvendedor) references vendedor(idvendedor) on update cascade on delete cascade); Query OK, 0 rows affected (0.41 sec) mysql> create table tipocredito_vendedor( -> idvendedor int, -> idtipocredito int, -> foreign key(idvendedor) references vendedor(idvendedor) on update cascade on delete cascade, -> foreign key(idtipocredito) references tipocredito(idtipocredito) on update cascade on delete cascade); Query OK, 0 rows affected (0.34 sec) mysql> describe vendedor; +------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-------+ | idvendedor | int(11) | NO | PRI | NULL | | | nombre | varchar(20) | YES | | NULL | | | dir | varchar(45) | YES | | NULL | | | tel | int(11) | YES | | NULL | | +------------+-------------+------+-----+---------+-------+ 4 rows in set (0.01 sec) mysql> alter table vendedor change dir porcentaje float; Query OK, 0 rows affected (0.64 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table vendedor change tel zona varchar(20); Query OK, 0 rows affected (0.55 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe vendedor; +------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+-------+ | idvendedor | int(11) | NO | PRI | NULL | | | nombre | varchar(20) | YES | | NULL | | | porcentaje | float | YES | | NULL | | | zona | varchar(20) | YES | | NULL | | +------------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> describe cliente; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | idcliente | int(11) | NO | PRI | NULL | | | nombre | varchar(20) | YES | | NULL | | | dir | varchar(45) | YES | | NULL | | | tel | int(11) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> alter table cliente change dir cupo varchar(20); Query OK, 0 rows affected (0.59 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table cliente drop tel; Query OK, 0 rows affected (0.78 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe cliente; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | idcliente | int(11) | NO | PRI | NULL | | | nombre | varchar(20) | YES | | NULL | | | cupo | varchar(20) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> insert into vendedor(idvendedor,nombre,porcentaje,zona) values( -> 001,'Luis Meza','0.5','Norte'), -> (002,'Camilo Lleras','0.6','Centro'), -> (003,'Sergio Agudelo','0.3','Centro'), -> (004,'Lina Ocampo','0.5','Sur'); Query OK, 4 rows affected (0.16 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> select * from vendedor; +------------+----------------+------------+--------+ | idvendedor | nombre | porcentaje | zona | +------------+----------------+------------+--------+ | 1 | Luis Meza | 0.5 | Norte | | 2 | Camilo Lleras | 0.6 | Centro | | 3 | Sergio Agudelo | 0.3 | Centro | | 4 | Lina Ocampo | 0.5 | Sur | +------------+----------------+------------+--------+ 4 rows in set (0.05 sec) mysql> show tables; +----------------------+ | Tables_in_credito | +----------------------+ | cliente | | cliente_ref_pers | | compra | | producto | | ref_pers | | tipocredito | | tipocredito_vendedor | | vende_cliente | | vendedor | +----------------------+ 9 rows in set (0.01 sec) mysql> describe cliente; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | idcliente | int(11) | NO | PRI | NULL | | | nombre | varchar(20) | YES | | NULL | | | cupo | varchar(20) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 3 rows in set (0.01 sec) mysql> insert into cliente(idcliente,nombre,cupo) values(50964,'Oscar de Le¢n',500000), -> (85963,'Ana Palencia',1000000), -> (25147,'Teresa Su rez',1200000), -> (36259,'Shamir Beltr n',700000); Query OK, 4 rows affected (0.06 sec) Records: 4 Duplicates: 0 Warnings: 0 mysql> select * from cliente; +-----------+----------------+---------+ | idcliente | nombre | cupo | +-----------+----------------+---------+ | 25147 | Teresa Su rez | 1200000 | | 36259 | Shamir Beltr n | 700000 | | 50964 | Oscar de Le¢n | 500000 | | 85963 | Ana Palencia | 1000000 | +-----------+----------------+---------+ 4 rows in set (0.00 sec) mysql> select * from vendedor; +------------+----------------+------------+--------+ | idvendedor | nombre | porcentaje | zona | +------------+----------------+------------+--------+ | 1 | Luis Meza | 0.5 | Norte | | 2 | Camilo Lleras | 0.6 | Centro | | 3 | Sergio Agudelo | 0.3 | Centro | | 4 | Lina Ocampo | 0.5 | Sur | +------------+----------------+------------+--------+ 4 rows in set (0.00 sec) mysql> select * from cliente where nombre like'a%'; +-----------+--------------+---------+ | idcliente | nombre | cupo | +-----------+--------------+---------+ | 85963 | Ana Palencia | 1000000 | +-----------+--------------+---------+ 1 row in set (0.01 sec) mysql> select * from cliente where nombre like'%a'; +-----------+--------------+---------+ | idcliente | nombre | cupo | +-----------+--------------+---------+ | 85963 | Ana Palencia | 1000000 | +-----------+--------------+---------+ 1 row in set (0.00 sec) mysql> select * from vendedor where nombre like'%a%'; +------------+----------------+------------+--------+ | idvendedor | nombre | porcentaje | zona | +------------+----------------+------------+--------+ | 1 | Luis Meza | 0.5 | Norte | | 2 | Camilo Lleras | 0.6 | Centro | | 3 | Sergio Agudelo | 0.3 | Centro | | 4 | Lina Ocampo | 0.5 | Sur | +------------+----------------+------------+--------+ 4 rows in set (0.00 sec) mysql> select * from cliente where cupo between 500000 and 1000000; +-----------+----------------+---------+ | idcliente | nombre | cupo | +-----------+----------------+---------+ | 36259 | Shamir Beltr n | 700000 | | 50964 | Oscar de Le¢n | 500000 | | 85963 | Ana Palencia | 1000000 | +-----------+----------------+---------+ 3 rows in set (0.06 sec) mysql> exit; mysql> use credito; Database changed mysql> show tables -> ; +----------------------+ | Tables_in_credito | +----------------------+ | cliente | | cliente_ref_pers | | compra | | producto | | ref_pers | | tipocredito | | tipocredito_vendedor | | vende_cliente | | vendedor | +----------------------+ 9 rows in set (0.00 sec) mysql> select*from vendedor; +------------+----------------+------------+--------+ | idvendedor | nombre | porcentaje | zona | +------------+----------------+------------+--------+ | 1 | Luis Meza | 0.5 | Norte | | 2 | Camilo Lleras | 0.6 | Centro | | 3 | Sergio Agudelo | 0.3 | Centro | | 4 | Lina Ocampo | 0.5 | Sur | +------------+----------------+------------+--------+ 4 rows in set (0.00 sec) mysql> select*from vendedor where zona='norte'; +------------+-----------+------------+-------+ | idvendedor | nombre | porcentaje | zona | +------------+-----------+------------+-------+ | 1 | Luis Meza | 0.5 | Norte | +------------+-----------+------------+-------+ 1 row in set (0.03 sec) mysql> select*from vendedor where zona='centro' and porcentaje='0.3'; Empty set (0.01 sec) mysql> select * from vendedor where zona ='centro' and porcentaje=0.3; Empty set (0.08 sec) mysql> select * from vendedor where zona ='centro' and porcentaje<=0.3; Empty set (0.05 sec) mysql> select * from vendedor where zona ='centro' or porcentaje<=0.3; +------------+----------------+------------+--------+ | idvendedor | nombre | porcentaje | zona | +------------+----------------+------------+--------+ | 2 | Camilo Lleras | 0.6 | Centro | | 3 | Sergio Agudelo | 0.3 | Centro | +------------+----------------+------------+--------+ 2 rows in set (0.00 sec) mysql> select * from vendedor where zona ='centro' and porcentaje<=0.3; Empty set (0.00 sec) mysql> select * from vendedor where zona ='centro' and porcentaje = 0.3; Empty set (0.00 sec) mysql> select * from vendedor where zona ='centro' and porcentaje == 0.3; 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 '== 0.3' at line 1 mysql> select * from vendedor where porcentaje = 0.3; Empty set (0.00 sec) mysql> select * from vendedor where porcentaje ='0.3'; Empty set (0.00 sec) mysql> describe cliente; +-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | idcliente | int(11) | NO | PRI | NULL | | | nombre | varchar(20) | YES | | NULL | | | cupo | varchar(20) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+ 3 rows in set (0.08 sec) mysql> select * from cliente; +-----------+----------------+---------+ | idcliente | nombre | cupo | +-----------+----------------+---------+ | 25147 | Teresa Su rez | 1200000 | | 36259 | Shamir Beltr n | 700000 | | 50964 | Oscar de Le¢n | 500000 | | 85963 | Ana Palencia | 1000000 | +-----------+----------------+---------+ 4 rows in set (0.00 sec) mysql> select sum(cupo) fron cliente; 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 'cliente' at line 1 mysql> select sum(cupo) from cliente; +-----------+ | sum(cupo) | +-----------+ | 3400000 | +-----------+ 1 row in set (0.08 sec) mysql> select sum(cupo) 'el total es' from cliente; +-------------+ | el total es | +-------------+ | 3400000 | +-------------+ 1 row in set (0.04 sec) mysql> select avg(cupo) 'el promedio es' from cliente; +----------------+ | el promedio es | +----------------+ | 850000 | +----------------+ 1 row in set (0.00 sec) mysql> select max(cupo) 'el cupo mas alto es' from cliente; +---------------------+ | el cupo mas alto es | +---------------------+ | 700000 | +---------------------+ 1 row in set (0.06 sec) mysql> select min(cupo) 'el cupo mas bajo es' from cliente; +---------------------+ | el cupo mas bajo es | +---------------------+ | 1000000 | +---------------------+ 1 row in set (0.00 sec) mysql> select cout(cupo) 'la cantidad de cupos es' from cliente; ERROR 1305 (42000): FUNCTION credito.cout does not exist mysql> select count(cupo) 'la cantidad de cupos es' from cliente; +-------------------------+ | la cantidad de cupos es | +-------------------------+ | 4 | +-------------------------+ 1 row in set (0.00 sec) mysql> select * from cliente order by cupo; +-----------+----------------+---------+ | idcliente | nombre | cupo | +-----------+----------------+---------+ | 85963 | Ana Palencia | 1000000 | | 25147 | Teresa Su rez | 1200000 | | 50964 | Oscar de Le¢n | 500000 | | 36259 | Shamir Beltr n | 700000 | +-----------+----------------+---------+ 4 rows in set (0.00 sec) mysql> select * from cliente order by cupo desc; +-----------+----------------+---------+ | idcliente | nombre | cupo | +-----------+----------------+---------+ | 36259 | Shamir Beltr n | 700000 | | 50964 | Oscar de Le¢n | 500000 | | 25147 | Teresa Su rez | 1200000 | | 85963 | Ana Palencia | 1000000 | +-----------+----------------+---------+ 4 rows in set (0.00 sec) mysql> select * from cliente order by nombre desc; +-----------+----------------+---------+ | idcliente | nombre | cupo | +-----------+----------------+---------+ | 25147 | Teresa Su rez | 1200000 | | 36259 | Shamir Beltr n | 700000 | | 50964 | Oscar de Le¢n | 500000 | | 85963 | Ana Palencia | 1000000 | +-----------+----------------+---------+ 4 rows in set (0.01 sec) mysql> update cliente set nombre='Jonathan Vasquez' where idcliente=25147; Query OK, 1 row affected (0.14 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from cliente; +-----------+------------------+---------+ | idcliente | nombre | cupo | +-----------+------------------+---------+ | 25147 | Jonathan Vasquez | 1200000 | | 36259 | Shamir Beltr n | 700000 | | 50964 | Oscar de Le¢n | 500000 | | 85963 | Ana Palencia | 1000000 | +-----------+------------------+---------+ 4 rows in set (0.00 sec) mysql> select * from vendedor; +------------+----------------+------------+--------+ | idvendedor | nombre | porcentaje | zona | +------------+----------------+------------+--------+ | 1 | Luis Meza | 0.5 | Norte | | 2 | Camilo Lleras | 0.6 | Centro | | 3 | Sergio Agudelo | 0.3 | Centro | | 4 | Lina Ocampo | 0.5 | Sur | +------------+----------------+------------+--------+ 4 rows in set (0.00 sec) mysql> update vendedor set nombre='Jonathan Vasquez' where idvendedor=1; Query OK, 1 row affected (0.06 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from vendedor; +------------+------------------+------------+--------+ | idvendedor | nombre | porcentaje | zona | +------------+------------------+------------+--------+ | 1 | Jonathan Vasquez | 0.5 | Norte | | 2 | Camilo Lleras | 0.6 | Centro | | 3 | Sergio Agudelo | 0.3 | Centro | | 4 | Lina Ocampo | 0.5 | Sur | +------------+------------------+------------+--------+ 4 rows in set (0.00 sec) mysql> delete from cliente where like cupo<=500000; 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 'like cupo<=500000' at line 1 mysql> select * from cliente; +-----------+------------------+---------+ | idcliente | nombre | cupo | +-----------+------------------+---------+ | 25147 | Jonathan Vasquez | 1200000 | | 36259 | Shamir Beltr n | 700000 | | 50964 | Oscar de Le¢n | 500000 | | 85963 | Ana Palencia | 1000000 | +-----------+------------------+---------+ 4 rows in set (0.00 sec) mysql> delete from cliente where cupo<=500000; Query OK, 1 row affected (0.06 sec) mysql> select * from cliente; +-----------+------------------+---------+ | idcliente | nombre | cupo | +-----------+------------------+---------+ | 25147 | Jonathan Vasquez | 1200000 | | 36259 | Shamir Beltr n | 700000 | | 85963 | Ana Palencia | 1000000 | +-----------+------------------+---------+ 3 rows in set (0.00 sec) mysql> exit;