You are on page 1of 4

Enter password:

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


Your MySQL connection id is 19
Server version: 5.5.8-log MySQL Community Server (GPL)

Copyright (c) 2000, 2010, 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 relaciones;


Query OK, 1 row affected (0.00 sec)

mysql> create table clientes (id_clientes int(8) not null auto_increment, nombre
varchar(255) not null, primary key (id_clientes)) type = innodb;
ERROR 1046 (3D000): No database selected
mysql> use relaciones;
Database changed
mysql> create table clientes (id_clientes int(8) not null auto_increment, nombre
varchar(255) not null, primary key (id_clientes)) type = innodb;
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 'type
= innodb' at line 1
mysql> create table clientes (id_clientes int(8) not null auto_increment, nombre
varchar(255) not null, primary key (id_clientes)) type=innodb;
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 'type=
innodb' at line 1
mysql> create table clientes (id_clientes int(8) not null auto_increment, nombre
varchar(255) not null, primary key (id_clientes));
Query OK, 0 rows affected (0.07 sec)

mysql> create table privilegios (id_privilegios int(8) not null auto_increment,


id_cliente int(8) not null, privilegios int(8) not null, primary key (id_privile
gios), index (id_cliente)
-> , foreign key (id_cliente) references clientes(id_clientes));
Query OK, 0 rows affected (0.08 sec)

mysql> insert into clientes values(1, "Pedro Picapiedra");


Query OK, 1 row affected (0.04 sec)

mysql> insert into clientes values(2, "Pablo Marmol");


Query OK, 1 row affected (0.04 sec)

mysql> insert into clientes values(3, "Ana Botella");


Query OK, 1 row affected (0.05 sec)

mysql> insert into privilegios values(1,2,10);


Query OK, 1 row affected (0.04 sec)

mysql> insert into privilegios values(2,3,05);


Query OK, 1 row affected (0.09 sec)

mysql> insert into privilegios values(3,2,01);


Query OK, 1 row affected (0.05 sec)
mysql> selct * from clientes;
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 'selct
* from clientes' at line 1
mysql> select * from clientes;
+-------------+------------------+
| id_clientes | nombre |
+-------------+------------------+
| 1 | Pedro Picapiedra |
| 2 | Pablo Marmol |
| 3 | Ana Botella |
+-------------+------------------+
3 rows in set (0.00 sec)

mysql> select * from privilegios;


+----------------+------------+-------------+
| id_privilegios | id_cliente | privilegios |
+----------------+------------+-------------+
| 1 | 2 | 10 |
| 2 | 3 | 5 |
| 3 | 2 | 1 |
+----------------+------------+-------------+
3 rows in set (0.00 sec)

mysql> describe clientes;


+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id_clientes | int(8) | NO | PRI | NULL | auto_increment |
| nombre | varchar(255) | NO | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

mysql> describe privilegios;


+----------------+--------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------+------+-----+---------+----------------+
| id_privilegios | int(8) | NO | PRI | NULL | auto_increment |
| id_cliente | int(8) | NO | MUL | NULL | |
| privilegios | int(8) | NO | | NULL | |
+----------------+--------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

mysql> insert into privilegios values(4,8,20);


ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`relaciones`.`privilegios`, CONSTRAINT `privilegios_ibfk_1` FOREIGN KEY (`
id_cliente`) REFERENCES `clientes` (`id_clientes`))
mysql>
mysql> insert into privilegios values(4, 8,20);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`relaciones`.`privilegios`, CONSTRAINT `privilegios_ibfk_1` FOREIGN KEY (`
id_cliente`) REFERENCES `clientes` (`id_clientes`))
mysql> insert into clientes values(4, "Juan Escutia");
Query OK, 1 row affected (0.04 sec)

mysql> select * from clientes;


+-------------+------------------+
| id_clientes | nombre |
+-------------+------------------+
| 1 | Pedro Picapiedra |
| 2 | Pablo Marmol |
| 3 | Ana Botella |
| 4 | Juan Escutia |
+-------------+------------------+
4 rows in set (0.00 sec)

mysql> select * from privilegios;


+----------------+------------+-------------+
| id_privilegios | id_cliente | privilegios |
+----------------+------------+-------------+
| 1 | 2 | 10 |
| 2 | 3 | 5 |
| 3 | 2 | 1 |
+----------------+------------+-------------+
3 rows in set (0.00 sec)

mysql> insert into privilegios values(4, 5,20);


ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`relaciones`.`privilegios`, CONSTRAINT `privilegios_ibfk_1` FOREIGN KEY (`
id_cliente`) REFERENCES `clientes` (`id_clientes`))
mysql> insert into privilegios values(4, 5,2);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`relaciones`.`privilegios`, CONSTRAINT `privilegios_ibfk_1` FOREIGN KEY (`
id_cliente`) REFERENCES `clientes` (`id_clientes`))
mysql> insert into privilegios values(4, 2);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into privilegios values(4, 2,2);
Query OK, 1 row affected (0.04 sec)

mysql> select * from privilegios;


+----------------+------------+-------------+
| id_privilegios | id_cliente | privilegios |
+----------------+------------+-------------+
| 1 | 2 | 10 |
| 2 | 3 | 5 |
| 3 | 2 | 1 |
| 4 | 2 | 2 |
+----------------+------------+-------------+
4 rows in set (0.00 sec)

mysql>
mysql> insert into privilegios values(5 ,6,20);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`relaciones`.`privilegios`, CONSTRAINT `privilegios_ibfk_1` FOREIGN KEY (`
id_cliente`) REFERENCES `clientes` (`id_clientes`))
mysql> insert into clientes values(5, "Yael Gutierrez");
Query OK, 1 row affected (0.04 sec)

mysql> select * from clientes;


+-------------+------------------+
| id_clientes | nombre |
+-------------+------------------+
| 1 | Pedro Picapiedra |
| 2 | Pablo Marmol |
| 3 | Ana Botella |
| 4 | Juan Escutia |
| 5 | Yael Gutierrez |
+-------------+------------------+
5 rows in set (0.00 sec)

mysql> insert into privilegios values(5, 4,21);


Query OK, 1 row affected (0.03 sec)

mysql> select * from privilegios);


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 ')' at
line 1
mysql> select * from privilegios;
+----------------+------------+-------------+
| id_privilegios | id_cliente | privilegios |
+----------------+------------+-------------+
| 1 | 2 | 10 |
| 2 | 3 | 5 |
| 3 | 2 | 1 |
| 4 | 2 | 2 |
| 5 | 4 | 21 |
+----------------+------------+-------------+
5 rows in set (0.00 sec)

mysql> insert into privilegios values(4, 2);

You might also like