miércoles, 6 de febrero de 2013

Consulta de una BD en MYSQL



C:\xampp>cd mysql

C:\xampp\mysql>cd bin

C:\xampp\mysql\bin>mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.41 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database veterinaria;
Query OK, 1 row affected (0.00 sec)

mysql> use veterinaria
Database changed
mysql> create tabla  mascota;
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 'tabla
  mascota' at line 1
mysql> create tabla  mascota (color varchar(30),sexo varchar(10),especie varchar
(30),raza varchar(30),motivoconsulta varchar(30),fnac varchar(8));
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 'tabla
  mascota (color varchar(30),sexo varchar(10),especie varchar(30),raza varc' at
line 1
mysql> create table  mascota (color varchar(30),sexo varchar(10),especie varchar
(30),raza varchar(30),motivoconsulta varchar(30),fnac varchar(8));
Query OK, 0 rows affected (0.03 sec)

mysql> delete table mascota;
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 'table
 mascota' at line 1
mysql> drope table mascota;
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 'drope
 table mascota' at line 1
mysql> drop table mascota;
Query OK, 0 rows affected (0.00 sec)

mysql> create table  mascota (numcliente int not null primary key,color varchar(
30),sexo varchar(10),especie varchar(30),raza varchar(30),motivoconsulta varchar
(30),fnac varchar(8),nombre varchar(30));
Query OK, 0 rows affected (0.03 sec)

mysql> create table cliente (numcliente int not null primary key,nombre varchar(
30), telefono int(10),direccion varchar(30), email varchar(30));
Query OK, 0 rows affected (0.03 sec)

insert in' at line 1
mysql> insert into cliente values(0001,'Juan Perez',6562582525,'CAmino nose','ju
anperez@gmail.com');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into cliente values(0002,'Juana Perez',6562592525,'camino real','j
uanaperez@gmail.com');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into mascota values(0001,'azul','hembra','desconocido','chihuhua',
'dolor pie','01/05/2008','chata');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into mascota values(0002,'verde','macho','desconocido','chihuhua',
'dolor espalda','01/06/2008','chato');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select *from mascota;
+------------+-------+--------+-------------+----------+----------------+-------
---+--------+
| numcliente | color | sexo   | especie     | raza     | motivoconsulta | fnac
   | nombre |
+------------+-------+--------+-------------+----------+----------------+-------
---+--------+
|          1 | azul  | hembra | desconocido | chihuhua | dolor pie      | 01/05/
20 | chata  |
|          2 | verde | macho  | desconocido | chihuhua | dolor espalda  | 01/06/
20 | chato  |
+------------+-------+--------+-------------+----------+----------------+-------
---+--------+
2 rows in set (0.00 sec)

mysql> select nombre, nombre form mascota, 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 'masco
ta, cliente' at line 1
mysql> select nombre, nombre from mascota, cliente;
ERROR 1052 (23000): Column 'nombre' in field list is ambiguous
mysql> select nombre from mascota, cliente;
ERROR 1052 (23000): Column 'nombre' in field list is ambiguous
mysql> drop mascota;
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 'masco
ta' at line 1
mysql> drop table mascota;
Query OK, 0 rows affected (0.00 sec)

mysql> create tabla mascota;
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 'tabla
 mascota' at line 1
mysql> create table  mascota (numcliente int not null primary key,color varchar(
30),sexo varchar(10),especie varchar(30),raza varchar(30),motivoconsulta varchar
(30),fnac varchar(8),nombrem varchar(30));
Query OK, 0 rows affected (0.03 sec)

mysql> insert into mascota values(0001,'azul','hembra','desconocido','chihuhua',
'dolor pie','01/05/2008','chata');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into cliente values(0002,'Juana Perez',6562592525,'camino real','j
uanaperez@gmail.com');
ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'
mysql> insert into cliente values(0003,'Juana Perez',6562592525,'camino real','j
uanaperez@gmail.com');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select nombre, nombre from mascota, cliente;
+-------------+-------------+
| nombre      | nombre      |
+-------------+-------------+
| Juan Perez  | Juan Perez  |
| Juana Perez | Juana Perez |
| Juana Perez | Juana Perez |
+-------------+-------------+
3 rows in set (0.00 sec)

mysql> select nombrem, nombre from mascota, cliente;
+---------+-------------+
| nombrem | nombre      |
+---------+-------------+
| chata   | Juan Perez  |
| chata   | Juana Perez |
| chata   | Juana Perez |
+---------+-------------+
3 rows in set (0.00 sec)

mysql> insert into mascota values(0001,'azul','hembra','desconocido','chihuhua',
'dolor pie','01/05/2008','chata');
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> insert into mascota values(0002,'verde','macho','desconocido','chihuhua',
'dolor espalda','01/06/2008','chato');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select nombrem, nombre from mascota, cliente;
+---------+-------------+
| nombrem | nombre      |
+---------+-------------+
| chata   | Juan Perez  |
| chato   | Juan Perez  |
| chata   | Juana Perez |
| chato   | Juana Perez |
| chata   | Juana Perez |
| chato   | Juana Perez |
+---------+-------------+
6 rows in set (0.00 sec)

mysql> show table mascota;
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 'masco
ta' at line 1
mysql> drop table mascota;
Query OK, 0 rows affected (0.00 sec)

mysql> drop table cliente;
Query OK, 0 rows affected (0.00 sec)

mysql> create table cliente (numcliente int not null primary key,nombre varchar(
30), telefono int(10),direccion varchar(30), email varchar(30));
Query OK, 0 rows affected (0.03 sec)

mysql> insert into cliente values(0001,'Juan Perez',6562582525,'CAmino nose','ju
anperez@gmail.com');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into cliente values(0001,'Harry Mndz',6562582424,'CAmino real','ha
rrypotter@gmail.com');
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
mysql> insert into cliente values(0002,'Harry Mndz',6562582424,'CAmino real','ha
rrypotter@gmail.com');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into cliente values(0003,'Harry Pack',6562582754,'CAminar','harryp
ack@gmail.com');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select *from cliente;
+------------+------------+------------+-------------+-----------------------+
| numcliente | nombre     | telefono   | direccion   | email                 |
+------------+------------+------------+-------------+-----------------------+
|          1 | Juan Perez | 2147483647 | CAmino nose | juanperez@gmail.com   |
|          2 | Harry Mndz | 2147483647 | CAmino real | harrypotter@gmail.com |
|          3 | Harry Pack | 2147483647 | CAminar     | harrypack@gmail.com   |
+------------+------------+------------+-------------+-----------------------+
3 rows in set (0.00 sec)

mysql> create table  mascota (numcliente int not null primary key,color varchar(
30),sexo varchar(10),raza varchar(30),motivoconsulta varchar(30),nombrem varchar
(30));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into mascota values(0001,'verde','macho','chihuhua','dolor espalda
','chato');
Query OK, 1 row affected (0.00 sec)

mysql> insert into mascota values(0002,'azul','macho','pitbull','dolor pata','pi
nto');
Query OK, 1 row affected (0.00 sec)

mysql> insert into mascota values(0003,'gris','macho','viejo pastor','cortada','
kisha');
Query OK, 1 row affected (0.00 sec)

mysql> select *from mascota;
+------------+-------+-------+--------------+----------------+---------+
| numcliente | color | sexo  | raza         | motivoconsulta | nombrem |
+------------+-------+-------+--------------+----------------+---------+
|          1 | verde | macho | chihuhua     | dolor espalda  | chato   |
|          2 | azul  | macho | pitbull      | dolor pata     | pinto   |
|          3 | gris  | macho | viejo pastor | cortada        | kisha   |
+------------+-------+-------+--------------+----------------+---------+
3 rows in set (0.00 sec)


Setting environment for using XAMPP for Windows.

Sergio@SERGIO-PC d:\xampp
# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.27 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select *from mascota;
+------------+-------+-------+--------------+----------------+---------+
| numcliente | color | sexo  | raza         | motivoconsulta | nombrem |
+------------+-------+-------+--------------+----------------+---------+
|          1 | verde | macho | chihuhua     | dolor espalda  | chato   |
|          2 | azul  | macho | pitbull      | dolor pata     | pinto   |
|          3 | gris  | macho | viejo pastor | cortada        | kisha   |
+------------+-------+-------+--------------+----------------+---------+
3 rows in set (0.00 sec)

mysql> alter table cliente add foreign key (numcliente) references mascota(numcl
iente);
Query OK, 3 rows affected (0.07 sec)
Records: 3  Duplicates: 0  Warnings: 0


mysql> select mascota.nombrem,cliente.nombre from mascota,cliente where cliente.
numcliente=mascota.numcliente;
+---------+------------+
| nombrem | nombre     |
+---------+------------+
| chato   | Juan Perez |
| pinto   | Harry Mndz |
| kisha   | Harry Pack |
+---------+------------+
3 rows in set (0.00 sec)

mysql>

No hay comentarios:

Publicar un comentario