Sunteți pe pagina 1din 3

Enter password: ****

Welcome to the MySQL monitor. Commands end with ; or \g.


Your MySQL connection id is 1
Server version: 5.0.37-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database agencia_seguros;


Query OK, 1 row affected (0.22 sec)

mysql> use agencia_seguros;


Database changed
mysql> create table persona (
-> id_persona int(14) auto_increment,
-> nombre varchar(25),
-> apellidos varchar(35),
-> direccion varchar(40),
-> poblacion varchar(30),
-> telefono int,
-> primary key (id_persona));
Query OK, 0 rows affected (0.44 sec)

mysql> create table vehiculo (


-> matricula int,
-> marca varchar(30),
-> modelo varchar(30),
-> primary key (matricula));
Query OK, 0 rows affected (0.13 sec)

mysql> create table accidentes (


-> No_ref_a int(14) auto_increment,
-> fecha_accidente date,
-> hora_accidente time,
-> lugar_accidente varchar(50),
-> primary key (No_ref_a));
Query OK, 0 rows affected (0.13 sec)

mysql> create table multas (


-> No_ref_mul int(14) auto_increment,
-> fecha_mul date,
-> hora_mul time,
-> lugar_mul varchar(50),
-> primary key (No_ref_mul));
Query OK, 0 rows affected (0.37 sec)

mysql> alter table persona add cve_vehiculo int;


Query OK, 0 rows affected (0.29 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> ALTER TABLE persona ADD FOREIGN KEY


-> (cve_vehiculo) REFERENCES vehiculo (matricula);
Query OK, 0 rows affected (0.77 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table multas add cve_persona int(14);


Query OK, 0 rows affected (0.21 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table multas add cve_vehiculo int(14);


Query OK, 0 rows affected (0.15 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> ALTER TABLE multas ADD FOREIGN KEY


-> (cve_persona) REFERENCES persona (id_persona);
Query OK, 0 rows affected (0.24 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> ALTER TABLE multas ADD FOREIGN KEY


-> (cve_vehiculo) REFERENCES vehiculo (matricula);
Query OK, 0 rows affected (0.17 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table accidentes add cve_vehiculo int(14);


Query OK, 0 rows affected (0.47 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> ALTER TABLE accidentes ADD FOREIGN KEY


-> (cve_vehiculo) REFERENCES vehiculo (matricula);
Query OK, 0 rows affected (0.32 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table accidentes add cve_persona int(14);


Query OK, 0 rows affected (0.46 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> ALTER TABLE accidentes ADD FOREIGN KEY


-> (cve_persona) REFERENCES persona (id_persona);
Query OK, 0 rows affected (0.40 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> desc persona;


+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| id_persona | int(14) | NO | PRI | NULL | auto_increment |
| nombre | varchar(25) | YES | | NULL | |
| apellidos | varchar(35) | YES | | NULL | |
| direccion | varchar(40) | YES | | NULL | |
| poblacion | varchar(30) | YES | | NULL | |
| telefono | int(11) | YES | | NULL | |
| cve_vehiculo | int(11) | YES | MUL | NULL | |
+--------------+-------------+------+-----+---------+----------------+
7 rows in set (0.01 sec)

mysql> desc vehiculo;


+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| matricula | int(11) | NO | PRI | 0 | |
| marca | varchar(30) | YES | | NULL | |
| modelo | varchar(30) | YES | | NULL | |
+-----------+-------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

mysql> desc accidentes;


+-----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+----------------+
| No_ref_a | int(14) | NO | PRI | NULL | auto_increment |
| fecha_accidente | date | YES | | NULL | |
| hora_accidente | time | YES | | NULL | |
| lugar_accidente | varchar(50) | YES | | NULL | |
| cve_vehiculo | int(14) | YES | MUL | NULL | |
| cve_persona | int(14) | YES | MUL | NULL | |
+-----------------+-------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)

mysql> desc multas;


+--------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+----------------+
| No_ref_mul | int(14) | NO | PRI | NULL | auto_increment |
| fecha_mul | date | YES | | NULL | |
| hora_mul | time | YES | | NULL | |
| lugar_mul | varchar(50) | YES | | NULL | |
| cve_persona | int(14) | YES | MUL | NULL | |
| cve_vehiculo | int(14) | YES | MUL | NULL | |
+--------------+-------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)

mysql>

S-ar putea să vă placă și