You are on page 1of 10

Last login: Mon Nov 6 12:12:43 on ttys001

MBP-de-Dany:~ dany$ /usr/local/mysql/bin/mysql -uroot -p


Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 164
Server version: 5.7.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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> show databases;


+--------------------+
| Database |
+--------------------+
| information_schema |
| ciclistas |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.02 sec)

mysql> create database Rutas;


Query OK, 1 row affected (0.02 sec)

mysql> use rutas;


Database changed
mysql> create table Autobus(
-> placa varchar(9) not null,
-> modelo varchar(50) not null,
-> noAsientos integer not null,
-> idChofer integer,
-> primary key(placa)
-> );
Query OK, 0 rows affected (0.52 sec)

mysql> create table Chofer(


-> idChofer integer not null auto_increment,
-> nombre varchar(255) not null,
-> telefono varchar(10) not null,
-> fechaNacimiento date,
-> idCiudad integer not null,
-> primary key (idChofer)
-> );
Query OK, 0 rows affected (0.09 sec)

mysql> create table Ciudad(


-> idCiudad integer not null auto_increment,
-> nombre varchar(100) not null,
-> primary key(idCiudad)
-> );
Query OK, 0 rows affected (0.09 sec)

mysql> create table Ruta(


-> idRuta integer not null auto_increment,
-> nombre varchar(50) not null,
-> idCiudadSalida integer not null,
-> idCiudadLlegada integer not null,
-> primary key(idRuta)
-> );
Query OK, 0 rows affected (0.06 sec)

mysql> create table Autobus_Ruta(


-> idRuta integer not null,
-> placa varchar(9) not null,
-> tiempoSalida datetime,
-> tiempoLlegada datetime,
-> primary key(idRuta, placa)
-> );
Query OK, 0 rows affected (0.12 sec)

mysql> alter table Autobus add constraint


-> fk_autobus_1 foreign key (idChofer)
-> references Chofer (idChofer);
Query OK, 0 rows affected (0.12 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table Chofer add constraint


-> fk_chofer_1 foreign key (idCiudad)
-> references Ciudad (idCiudad);
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table Autobus_Ruta add constraint


-> fk_autobusruta_1 foreign key (idRuta)
-> references Ruta (idRuta);
Query OK, 0 rows affected (0.13 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table Autobus_Ruta add constraint


-> fk_autobusruta_2 foreign key (placa)
-> references Autobus (placa);
Query OK, 0 rows affected (0.12 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table Ruta add constraint


-> fk_ruta_1 foreign key (idCiudadSalida)
-> references Ciudad (idCiudad);
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> alter table Ruta add constraint


-> fkruta_2 foreign key (idCiudadLlegada)
-> references Ciudad (idCiudad);
Query OK, 0 rows affected (0.08 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> show tables;


+-----------------+
| Tables_in_rutas |
+-----------------+
| Autobus |
| Autobus_Ruta |
| Chofer |
| Ciudad |
| Ruta |
+-----------------+
5 rows in set (0.00 sec)

mysql> describe ciudad;


+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| idCiudad | int(11) | NO | PRI | NULL | auto_increment |
| nombre | varchar(100) | NO | | NULL | |
+----------+--------------+------+-----+---------+----------------+
2 rows in set (0.09 sec)

mysql> insert into ciudad values(null,'Xalapa');


Query OK, 1 row affected (0.06 sec)

mysql> insert into ciudad values(null,'Xalapa');


Query OK, 1 row affected (0.02 sec)
mysql> delete * from ciudad;
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 '* from ciudad' at line 1
mysql> delete from ciudad;
Query OK, 2 rows affected (0.02 sec)

mysql> insert into ciudad values(null,'Xalapa');


Query OK, 1 row affected (0.00 sec)

mysql> insert into ciudad values(null,'Veracruz');


Query OK, 1 row affected (0.06 sec)

mysql> insert into ciudad values(null,'Coatepec');


Query OK, 1 row affected (0.00 sec)

mysql> insert into ciudad values(null,'Xico');


Query OK, 1 row affected (0.06 sec)

mysql> insert into ciudad values(null,'Banderilla');


Query OK, 1 row affected (0.02 sec)

mysql> insert into ciudad values(null,'Cordoba');


Query OK, 1 row affected (0.00 sec)

mysql> insert into ciudad values(null,'Actopan');


Query OK, 1 row affected (0.00 sec)

mysql> select * from ciudad;


+----------+------------+
| idCiudad | nombre |
+----------+------------+
| 3 | Xalapa |
| 4 | Veracruz |
| 5 | Coatepec |
| 6 | Xico |
| 7 | Banderilla |
| 8 | Cordoba |
| 9 | Actopan |
+----------+------------+
7 rows in set (0.00 sec)

mysql> drop ciudad;


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 'ciudad' at line 1
mysql> drop table ciudad;
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key
constraint fails
mysql> mysql> insert chofer values(null,'Antonio
Hernandez','2281111111','1960-08-20','Xalapa');
ERROR 1146 (42S02): Table 'rutas.cichofer' doesn't exist
mysql> insert chofer values(null,'Antonio Hernandez','2281111111','1960-
08-20','Xalapa');
ERROR 1366 (HY000): Incorrect integer value: 'Xalapa' for column 'idCiudad'
at row 1
mysql> insert chofer values(null,'Antonio Hernandez','2281111111','1960-
08-20',3);
Query OK, 1 row affected (0.01 sec)

mysql> select * from chofer;


+----------+-------------------+------------+-----------------+----------+
| idChofer | nombre | telefono | fechaNacimiento | idCiudad |
+----------+-------------------+------------+-----------------+----------+
| 1 | Antonio Hernandez | 2281111111 | 1960-08-20 | 3|
+----------+-------------------+------------+-----------------+----------+
1 row in set (0.00 sec)

mysql> describe chofer;


+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| idChofer | int(11) | NO | PRI | NULL | auto_increment |
| nombre | varchar(255) | NO | | NULL | |
| telefono | varchar(10) | NO | | NULL | |
| fechaNacimiento | date | YES | | NULL | |
| idCiudad | int(11) | NO | MUL | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
5 rows in set (0.01 sec)

mysql> insert chofer values(null,'Miguel Rebolledo','2292222222','1975-03-


05',3);
Query OK, 1 row affected (0.02 sec)

mysql> select * from chofer;


+----------+-------------------+------------+-----------------+----------+
| idChofer | nombre | telefono | fechaNacimiento | idCiudad |
+----------+-------------------+------------+-----------------+----------+
| 1 | Antonio Hernandez | 2281111111 | 1960-08-20 | 3|
| 2 | Miguel Rebolledo | 2292222222 | 1975-03-05 | 3|
+----------+-------------------+------------+-----------------+----------+
2 rows in set (0.00 sec)

mysql> insert chofer values(null,'Rafael Jimenez','2282222222','1983-04-


06',4);
Query OK, 1 row affected (0.02 sec)

mysql> insert chofer values(null,'Raul Ortiz','7562523654','1979-01-01',8);


Query OK, 1 row affected (0.01 sec)

mysql> select * from chofer;


+----------+-------------------+------------+-----------------+----------+
| idChofer | nombre | telefono | fechaNacimiento | idCiudad |
+----------+-------------------+------------+-----------------+----------+
| 1 | Antonio Hernandez | 2281111111 | 1960-08-20 | 3|
| 2 | Miguel Rebolledo | 2292222222 | 1975-03-05 | 3|
| 3 | Rafael Jimenez | 2282222222 | 1983-04-06 | 4|
| 4 | Raul Ortiz | 7562523654 | 1979-01-01 | 8|
+----------+-------------------+------------+-----------------+----------+
4 rows in set (0.00 sec)

mysql> insert chofer values(null,'Andrea Gonzalez','2283333333','1983-08-


24',7);
Query OK, 1 row affected (0.00 sec)

mysql> insert chofer values(null,'Carla Lopez','6534785962','1980-09-24',4);


Query OK, 1 row affected (0.01 sec)

mysql> select * from chofer;


+----------+-------------------+------------+-----------------+----------+
| idChofer | nombre | telefono | fechaNacimiento | idCiudad |
+----------+-------------------+------------+-----------------+----------+
| 1 | Antonio Hernandez | 2281111111 | 1960-08-20 | 3|
| 2 | Miguel Rebolledo | 2292222222 | 1975-03-05 | 3|
| 3 | Rafael Jimenez | 2282222222 | 1983-04-06 | 4|
| 4 | Raul Ortiz | 7562523654 | 1979-01-01 | 8|
| 5 | Andrea Gonzalez | 2283333333 | 1983-08-24 | 7|
| 6 | Carla Lopez | 6534785962 | 1980-09-24 | 4|
+----------+-------------------+------------+-----------------+----------+
6 rows in set (0.00 sec)

mysql> describe autobus;


+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| placa | varchar(9) | NO | PRI | NULL | |
| modelo | varchar(50) | NO | | NULL | |
| noAsientos | int(11) | NO | | NULL | |
| idChofer | int(11) | YES | MUL | NULL | |
+------------+-------------+------+-----+---------+-------+
4 rows in set (0.47 sec)

mysql> insert into Autobus('A00000045','2000',25,2);


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 ''A00000045','2000',25,2)' at line 1
mysql> insert into Autobus('A00000045','2000',25,2);
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 ''A00000045','2000',25,2)' at line 1
mysql> insert into Autobus values('A00000045','2000',25,2);
Query OK, 1 row affected (0.31 sec)

mysql> insert into Autobus values('A00000046','2004',25,5);


Query OK, 1 row affected (0.02 sec)

mysql> insert into Autobus values('B00000084','2006',28,1);


Query OK, 1 row affected (0.04 sec)

mysql> insert into Autobus values('B00000085','2006',30,3);


Query OK, 1 row affected (0.00 sec)

mysql> insert into Autobus values('C00000152','2012',38,6);


Query OK, 1 row affected (0.03 sec)

mysql> insert into Autobus values('C00000153','2013',38,4);


Query OK, 1 row affected (0.01 sec)

mysql> describe rutas;


ERROR 1146 (42S02): Table 'rutas.rutas' doesn't exist
mysql> describe ruta;
+-----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+----------------+
| idRuta | int(11) | NO | PRI | NULL | auto_increment |
| nombre | varchar(50) | NO | | NULL | |
| idCiudadSalida | int(11) | NO | MUL | NULL | |
| idCiudadLlegada | int(11) | NO | MUL | NULL | |
+-----------------+-------------+------+-----+---------+----------------+
4 rows in set (0.05 sec)

mysql> insert into ruta values(null,'Ruta 1','Xalapa','Banderilla');


ERROR 1366 (HY000): Incorrect integer value: 'Xalapa' for column
'idCiudadSalida' at row 1
mysql> select *from ciudad;
+----------+------------+
| idCiudad | nombre |
+----------+------------+
| 3 | Xalapa |
| 4 | Veracruz |
| 5 | Coatepec |
| 6 | Xico |
| 7 | Banderilla |
| 8 | Cordoba |
| 9 | Actopan |
+----------+------------+
7 rows in set (0.05 sec)

mysql> insert into ruta values(null,'Ruta 1',3,7);


Query OK, 1 row affected (0.06 sec)

mysql> insert into ruta values(null,'Ruta 55',4,5);


Query OK, 1 row affected (0.00 sec)

mysql> insert into ruta values(null,'Ruta 12',6,9);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ruta values(null,'Ruta 23',8,3);


Query OK, 1 row affected (0.02 sec)

mysql> insert into ruta values(null,'Ruta 52',4,6);


Query OK, 1 row affected (0.00 sec)

mysql> insert into ruta values(null,'Ruta 8',9,3);


Query OK, 1 row affected (0.01 sec)

mysql> insert into ruta values(null,'Ruta 6',3,6);


Query OK, 1 row affected (0.00 sec)

mysql> insert into ruta values(null,'Ruta 44',7,5);


Query OK, 1 row affected (0.02 sec)

mysql> describe autobus_ruta;


+---------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------+------+-----+---------+-------+
| idRuta | int(11) | NO | PRI | NULL | |
| placa | varchar(9) | NO | PRI | NULL | |
| tiempoSalida | datetime | YES | | NULL | |
| tiempoLlegada | datetime | YES | | NULL | |
+---------------+------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql> select * from ruta;


+--------+---------+----------------+-----------------+
| idRuta | nombre | idCiudadSalida | idCiudadLlegada |
+--------+---------+----------------+-----------------+
| 1 | Ruta 1 | 3| 7|
| 2 | Ruta 55 | 4| 5|
| 3 | Ruta 12 | 6| 9|
| 4 | Ruta 23 | 8| 3|
| 5 | Ruta 52 | 4| 6|
| 6 | Ruta 8 | 9| 3|
| 7 | Ruta 6 | 3| 6|
| 8 | Ruta 44 | 7| 5|
+--------+---------+----------------+-----------------+
8 rows in set (0.00 sec)

mysql> insert into autobus_ruta values(1,'A00000045','2015-05-07


14:00','2015-05-07 16:00');
Query OK, 1 row affected (0.05 sec)

mysql> insert into autobus_ruta values(1,'A00000045','2015-05-07


14:00','2015-05-07 16:00');
ERROR 1062 (23000): Duplicate entry '1-A00000045' for key 'PRIMARY'
mysql> insert into autobus_ruta values(2,'A00000046','2015-05-08
16:00','2015-05-08 17:00');
Query OK, 1 row affected (0.04 sec)

mysql> insert into autobus_ruta values(3,'B00000084','2015-05-09


18:00','2015-05-09 19:00');
Query OK, 1 row affected (0.00 sec)

mysql> insert into autobus_ruta values(4,'B00000085','2015-05-10


20:00','2015-05-10 22:00');
Query OK, 1 row affected (0.03 sec)

mysql> insert into autobus_ruta values(5,'C00000152','2015-05-11


22:00','2015-05-11 23:50');
Query OK, 1 row affected (0.01 sec)

mysql> insert into autobus_ruta values(6,'C00000153','2015-05-12


00:22','2015-05-12 03:00');
Query OK, 1 row affected (0.03 sec)
mysql> insert into autobus_ruta values(7,'B00000085','2015-05-14
02:00','2015-05-14 02:40');
Query OK, 1 row affected (0.04 sec)

mysql> insert into autobus_ruta values(8,'C00000152','2015-05-15


04:10','2015-05-15 05:20');
Query OK, 1 row affected (0.04 sec)

mysql> exit;
Bye

You might also like