Vous êtes sur la page 1sur 5

mysql> select database();

+------------+
| database() |
+------------+
| demo
|
+------------+
1 row in set (0.00 sec)
mysql> show databases;
+--------------------+
| Database
|
+--------------------+
| information_schema |
| demo
|
| mysql
|
| performance_schema |
| sakila
|
| test
|
| world
|
+--------------------+
7 rows in set (0.00 sec)
mysql> use demo;
Database changed
mysql> show tables;
+----------------+
| Tables_in_demo |
+----------------+
| ganancia
|
| precios
|
| productos
|
| proveedores
|
+----------------+
4 rows in set (0.00 sec)
mysql> describe ganancia;
+--------+-------------------------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+--------+-------------------------------+------+-----+---------+-------+
| venta | enum('Por mayor','Por menor') | YES |
| NULL
|
|
| factor | float(6,2)
| YES |
| NULL
|
|
+--------+-------------------------------+------+-----+---------+-------+
2 rows in set (0.02 sec)
mysql> describe precios;
+---------+--------------------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+---------+--------------------------+------+-----+---------+-------+
| empresa | varchar(20)
| NO | MUL | NULL
|
|
| clave | int(3) unsigned zerofill | NO | MUL | NULL
|
|
| precio | float(6,2)
| YES |
| NULL
|
|
+---------+--------------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> describe proveedores;
+---------+---------------------------+------+-----+---------+-------+
| Field | Type
| Null | Key | Default | Extra |
+---------+---------------------------+------+-----+---------+-------+
| empresa | varchar(20)
| NO | PRI | NULL
|
|
| pago
| set('credito','efectivo') | YES |
| NULL
|
|

+---------+---------------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> describe productos;
+----------------+--------------------------+------+-----+---------+---------------+
| Field
| Type
| Null | Key | Default | Extra
|
+----------------+--------------------------+------+-----+---------+---------------+
| parte
| varchar(20)
| YES |
| NULL
|
|
| tipo
| varchar(20)
| YES |
| NULL
|
|
| especificacion | varchar(20)
| YES |
| NULL
|
|
| psugerido
| float(6,2)
| YES |
| NULL
|
|
| clave
| int(3) unsigned zerofill | NO | PRI | NULL
| auto_increm
ent |
+----------------+--------------------------+------+-----+---------+---------------+
5 rows in set (0.00 sec)
mysql> select concat (parte,'',tipo) as producto,
-> psugerido as 'precio sugerido',
-> psugerido + 10 as precio_con_envio
-> from productos;
+-------------------+-----------------+------------------+
| producto
| precio sugerido | precio_con_envio |
+-------------------+-----------------+------------------+
| Procesador2 GHz |
NULL |
NULL |
| Procesador2.4 GHz |
35.00 |
45.00 |
| Procesador1.7 GHz |
205.00 |
215.00 |
| Procesador3 GHz |
560.00 |
570.00 |
| RAM128MB
|
10.00 |
20.00 |
| RAM256MB
|
35.00 |
45.00 |
| Disco Duro80 GB |
60.00 |
70.00 |
| Disco Duro120 GB |
78.00 |
88.00 |
| Disco Duro200 GB |
110.00 |
120.00 |
| Disco Duro40 GB |
NULL |
NULL |
| Monitor1024x876 |
80.00 |
90.00 |
| Monitor1024x876 |
67.00 |
77.00 |
+-------------------+-----------------+------------------+
12 rows in set (0.00 sec)
mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
+--------------------------------------------+
| CASE WHEN 1>0 THEN 'true' ELSE 'false' END |
+--------------------------------------------+
| true
|
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT IF(STRCMP('TEST','TEST1'),'NO','YES');
+---------------------------------------+
| IF(STRCMP('TEST','TEST1'),'NO','YES') |
+---------------------------------------+
| NO
|
+---------------------------------------+

1 row in set (0.00 sec)


mysql> select productos.clave, concat(parte,'',tipo,'',especificacion) as produc
to,proveedores.empresa, precio, pago from productos natural join precios natural
join proveedores;
+-------+--------------------------+----------+--------+------------------+
| clave | producto
| empresa | precio | pago
|
+-------+--------------------------+----------+--------+------------------+
| 001 | Procesador2 GHz32 bits | Nacional | 30.82 | credito,efectivo |
| 002 | Procesador2.4 GHz32 bits | Nacional | 32.73 | credito,efectivo |
| 003 | Procesador1.7 GHz64 bits | Nacional | 202.25 | credito,efectivo |
| 005 | RAM128MB333 MHz
| Nacional | 9.76 | credito,efectivo |
| 006 | RAM256MB400 MHz
| Nacional | 31.52 | credito,efectivo |
| 007 | Disco Duro80 GB7200 rpm | Nacional | 58.41 | credito,efectivo |
| 010 | Disco Duro40 GB4200 rpm | Nacional | 64.38 | credito,efectivo |
| 001 | Procesador2 GHz32 bits | Patito | 30.40 | efectivo
|
| 002 | Procesador2.4 GHz32 bits | Patito | 33.63 | efectivo
|
| 003 | Procesador1.7 GHz64 bits | Patito | 195.59 | efectivo
|
| 005 | RAM128MB333 MHz
| Patito | 9.78 | efectivo
|
| 006 | RAM256MB400 MHz
| Patito | 32.44 | efectivo
|
| 007 | Disco Duro80 GB7200 rpm | Patito | 59.99 | efectivo
|
| 010 | Disco Duro40 GB4200 rpm | Patito | 62.02 | efectivo
|
| 003 | Procesador1.7 GHz64 bits | Tecno-k | 198.34 | credito
|
| 005 | RAM128MB333 MHz
| Tecno-k | 9.27 | credito
|
| 006 | RAM256MB400 MHz
| Tecno-k | 34.85 | credito
|
| 007 | Disco Duro80 GB7200 rpm | Tecno-k | 59.95 | credito
|
| 010 | Disco Duro40 GB4200 rpm | Tecno-k | 61.22 | credito
|
| 012 | Monitor1024x87660 Hz
| Tecno-k | 62.29 | credito
|
+-------+--------------------------+----------+--------+------------------+
20 rows in set (0.00 sec)
mysql> explain select productos.clave, concat(parte,'',tipo,'',especificacion) a
s producto, proveedores.empresa, precio, pago from productos natural join precio
s natural join proveedores;
+----+-------------+-------------+--------+---------------+---------+---------+-------------------------+------+-------+
| id | select_type | table
| type | possible_keys | key
| key_len |
ref
| rows | Extra |
+----+-------------+-------------+--------+---------------+---------+---------+-------------------------+------+-------+
| 1 | SIMPLE
| proveedores | ALL
| PRIMARY
| NULL
| NULL
|
NULL
|
3 | NULL |
| 1 | SIMPLE
| precios
| ref
| empresa,clave | empresa | 62
|
demo.proveedores.empresa |
1 | NULL |
| 1 | SIMPLE
| productos | eq_ref | PRIMARY
| PRIMARY | 4
|
demo.precios.clave
|
1 | NULL |
+----+-------------+-------------+--------+---------------+---------+---------+-------------------------+------+-------+
3 rows in set (0.00 sec)
mysql> explain select productos.clave, concat(parte,'',tipo,'',especificacion) a
s producto, proveedores.empresa,
-> \c
mysql> explain select productos.clave, concat(parte,'',tipo,'',especificacion) a
s producto, proveedores.empresa, precio, pago from productos natural join precio
s natural join proveedores;
+----+-------------+-------------+--------+---------------+---------+---------+-------------------------+------+-------+
| id | select_type | table
| type | possible_keys | key
| key_len |
ref
| rows | Extra |

+----+-------------+-------------+--------+---------------+---------+---------+-------------------------+------+-------+
| 1 | SIMPLE
| proveedores | ALL
| PRIMARY
| NULL
| NULL
|
NULL
|
3 | NULL |
| 1 | SIMPLE
| precios
| ref
| empresa,clave | empresa | 62
|
demo.proveedores.empresa |
1 | NULL |
| 1 | SIMPLE
| productos | eq_ref | PRIMARY
| PRIMARY | 4
|
demo.precios.clave
|
1 | NULL |
+----+-------------+-------------+--------+---------------+---------+---------+-------------------------+------+-------+
3 rows in set (0.00 sec)
mysql> alter table precios add index empresa_idx (empresa);
Query OK, 0 rows affected (0.44 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table precios add index clave_idx (clave);
Query OK, 0 rows affected (0.38 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> explain select productos.clave, concat(parte,'',tipo,'',especificacion) a
s producto, proveedores.empresa, precio,pago from productos natural join precios
natural join proveedores;
+----+-------------+-------------+--------+-----------------------+------------+---------+--------------------------+------+-------+
| id | select_type | table
| type | possible_keys
| key
| key_len | ref
| rows | Extra |
+----+-------------+-------------+--------+-----------------------+------------+---------+--------------------------+------+-------+
| 1 | SIMPLE
| proveedores | ALL
| PRIMARY
| NULL
| NULL
| NULL
|
3 | NULL |
| 1 | SIMPLE
| precios
| ref
| empresa_idx,clave_idx | empresa_idx
| 62
| demo.proveedores.empresa |
3 | NULL |
| 1 | SIMPLE
| productos | eq_ref | PRIMARY
| PRIMARY
| 4
| demo.precios.clave
|
1 | NULL |
+----+-------------+-------------+--------+-----------------------+------------+---------+--------------------------+------+-------+
3 rows in set (0.00 sec)
mysql> select user from user;
+------+
| user |
+------+
| root |
+------+
1 row in set (0.00 sec)
mysql> create database prueba;
Query OK, 1 row affected (0.00 sec)
mysql> connet prueba;
Connection id: 12
Current database: prueba
mysql> create table prueba (codigo varchar(4) PRIMARY KEY, nombre varchar(100));
Query OK, 0 rows affected (0.14 sec)
mysql> select * from prueba;
Empty set (0.00 sec)

mysql> quit;

Vous aimerez peut-être aussi