miércoles, 6 de febrero de 2013

Consulta Veterinaria



C:\xampp\mysql\bin>mysql -hlocalhost -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.16 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> create database Veterinaria1;
Query OK, 1 row affected (0.01 sec)

mysql> use veterinaria1;
Database changed
mysql> create table mascota(id_mascota int not null primary key,nombre varchar(1
0),sexo varchar(8),edad int(2),raza varchar(10),color varchar(10),especie varcha
r(10));
Query OK, 0 rows affected (0.11 sec)

mysql> create table propietario(id_propietario int primary key not null,id_masco
ta int(10),nombre varchar(15),telefono int(7),direccion varchar(15),profesion va
rchar(10));
Query OK, 0 rows affected (0.07 sec)

mysql> describe mascota;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| id_mascota | int(11)     | NO   | PRI | NULL    |       |
| nombre     | varchar(10) | YES  |     | NULL    |       |
| sexo       | varchar(8)  | YES  |     | NULL    |       |
| edad       | int(2)      | YES  |     | NULL    |       |
| raza       | varchar(10) | YES  |     | NULL    |       |
| color      | varchar(10) | YES  |     | NULL    |       |
| especie    | varchar(10) | YES  |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+
7 rows in set (0.53 sec)

mysql> describe propietario;
+----------------+-------------+------+-----+---------+-------+
| Field          | Type        | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| id_propietario | int(11)     | NO   | PRI | NULL    |       |
| id_mascota     | int(10)     | YES  |     | NULL    |       |
| nombre         | varchar(15) | YES  |     | NULL    |       |
| telefono       | int(7)      | YES  |     | NULL    |       |
| direccion      | varchar(15) | YES  |     | NULL    |       |
| profesion      | varchar(10) | YES  |     | NULL    |       |
+----------------+-------------+------+-----+---------+-------+
6 rows in set (0.07 sec)

mysql> ALTER TABLE propietario ADD FOREIGN KEY(id_mascota) REFERENCES mascota(id
_mascota);
Query OK, 0 rows affected (0.23 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> describe mascota;
+------------+-------------+------+-----+---------+-------+
| Field      | Type        | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| id_mascota | int(11)     | NO   | PRI | NULL    |       |
| nombre     | varchar(10) | YES  |     | NULL    |       |
| sexo       | varchar(8)  | YES  |     | NULL    |       |
| edad       | int(2)      | YES  |     | NULL    |       |
| raza       | varchar(10) | YES  |     | NULL    |       |
| color      | varchar(10) | YES  |     | NULL    |       |
| especie    | varchar(10) | YES  |     | NULL    |       |
+------------+-------------+------+-----+---------+-------+
7 rows in set (0.04 sec)

mysql> describe propietario;
+----------------+-------------+------+-----+---------+-------+
| Field          | Type        | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+-------+
| id_propietario | int(11)     | NO   | PRI | NULL    |       |
| id_mascota     | int(10)     | YES  | MUL | NULL    |       |
| nombre         | varchar(15) | YES  |     | NULL    |       |
| telefono       | int(7)      | YES  |     | NULL    |       |
| direccion      | varchar(15) | YES  |     | NULL    |       |
| profesion      | varchar(10) | YES  |     | NULL    |       |
+----------------+-------------+------+-----+---------+-------+
6 rows in set (0.04 sec)
mysql> insert into mascota(id_mascota,nombre,sexo,edad,raza,color,especie)values
(1,'peluche','macho',4,'frenchs poodle','blanco','terrestre');
Query OK, 1 row affected, 1 warning (0.09 sec)
mysql> insert into propietario(id_propietario,id_mascota,nombre,telefono,direcci
on,profesion)values (1,1,'rodolfo gallegos',6545634,'ciudad juarez','estudiante'
);
Query OK, 1 row affected, 1 warning (0.04 sec)

mysql> select *from mascota;
+------------+---------+-------+------+------------+--------+-----------+
| id_mascota | nombre  | sexo  | edad | raza       | color  | especie   |
+------------+---------+-------+------+------------+--------+-----------+
|          1 | peluche | macho |    4 | frenchs po | blanco | terrestre |
+------------+---------+-------+------+------------+--------+-----------+
1 row in set (0.00 sec)

mysql> select *from propietario;
+----------------+------------+-----------------+----------+---------------+----
--------+
| id_propietario | id_mascota | nombre          | telefono | direccion     | pro
fesion  |
+----------------+------------+-----------------+----------+---------------+----
--------+
|              1 |          1 | rodolfo gallego |  6545634 | ciudad juarez | est
udiante |
+----------------+------------+-----------------+----------+---------------+----
--------+
1 row in set (0.00 sec)

mysql>

No hay comentarios:

Publicar un comentario