Você está na página 1de 6

mysql> describe programa;

+---------------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
| id_programa_materia | int(11) | YES | | NULL | |
+---------------------+----------+------+-----+---------+----------------+
3 rows in set (0.02 sec)
mysql> alter table programa drop column id_programa_materia;
Query OK, 0 rows affected (0.31 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe programa
-> ;
+--------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
+--------+----------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
mysql> describe programa_materia;
+-------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| id_programa | int(11) | YES | | NULL | |
| id_materia | int(11) | YES | | NULL | |
| semestre | int(11) | YES | | NULL | |
+-------------+---------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> alter table programa_materia drop column id_materia;
Query OK, 0 rows affected (0.28 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table programa_materia
-> add foreign key(id_programa)references programa(id)
-> ;
Query OK, 0 rows affected (0.62 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table programa_materia
-> add foreign key(id_programa)references programa(id)
-> on update cascade;
Query OK, 0 rows affected (0.36 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe materia
-> ;
+---------------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| id_usomateria | int(11) | YES | | NULL | |
| id_programa_materia | int(11) | YES | | NULL | |
| nombre | char(20) | YES | | NULL | |
+---------------------+----------+------+-----+---------+----------------+
4 rows in set (0.02 sec)
mysql> alter table materia
-> add foreign key(id_usomateria)references usomateria(id)
-> on update cascade;
Query OK, 0 rows affected (0.23 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table programa_materia
-> add foreign key(id_programa_materia)references programa(id)dsd
-> ;
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 'ds
d' at line 2
mysql> alter table materia
-> add foreign key(id_programa_materia)references programa_materia(id)
-> on update cascade;
Query OK, 0 rows affected (0.62 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe tipousuario;
+------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
| id_usuario | int(11) | YES | MUL | NULL | |
+------------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> insert into (nombre,id_usuario)values("miguel",1);
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 '(n
ombre,id_usuario)values("miguel",1)' at line 1
mysql> insert into tipousuario(nombre,id_usuario)values("miguel",1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`db/tipousuario`, CONSTRAINT `tipousuario_ibfk_1` FOREIGN KEY (`id_usua
rio`) REFERENCES `usuario` (`id`) ON UPDATE CASCADE)
mysql> insert into tipousuario(nombre,id_usuario)values("miguel",1);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
ails (`db/tipousuario`, CONSTRAINT `tipousuario_ibfk_1` FOREIGN KEY (`id_usua
rio`) REFERENCES `usuario` (`id`) ON UPDATE CASCADE)
mysql> describe usuario;}
+--------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
+--------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
-> insert into usuario (nombre)values ("miguel")
-> ;
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 '}
insert into usuario (nombre)values ("miguel")' at line 1
mysql> insert into usuario (nombre)values ("miguel");
Query OK, 1 row affected (0.06 sec)
mysql> insert into usuario (nombre)values ("jorge");
Query OK, 1 row affected (0.08 sec)
mysql> insert into usuario (nombre)values ("alan");
Query OK, 1 row affected (0.06 sec)
mysql> insert into usuario (nombre)values ("angel");
Query OK, 1 row affected (0.06 sec)
mysql> insert into usuario (nombre)values ("roberto");
Query OK, 1 row affected (0.06 sec)
mysql> describe tipousuario;
+------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
| id_usuario | int(11) | YES | MUL | NULL | |
+------------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> insert into tipousuario(nombre,id_usuario)values("miguel",1);
Query OK, 1 row affected (0.08 sec)
mysql> insert into tipousuario(nombre,id_usuario)values("manuel",2);
Query OK, 1 row affected (0.06 sec)
mysql> insert into tipousuario(nombre,id_usuario)values("humberto",3);
Query OK, 1 row affected (0.06 sec)
mysql> insert into tipousuario(nombre,id_usuario)values("jorge",4);
Query OK, 1 row affected (0.08 sec)
mysql> insert into tipousuario(nombre,id_usuario)values("raul",5);
Query OK, 1 row affected (0.06 sec)
mysql> describe usomateria;
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| id_usuario | int(11) | YES | MUL | NULL | |
+------------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> insert into usomateria(id_usuario)values(1);
Query OK, 1 row affected (0.06 sec)
mysql> insert into usomateria(id_usuario)values(2);
Query OK, 1 row affected (0.06 sec)
mysql> insert into usomateria(id_usuario)values(3);
Query OK, 1 row affected (0.06 sec)
mysql> insert into usomateria(id_usuario)values(4);
Query OK, 1 row affected (0.08 sec)
mysql> insert into usomateria(id_usuario)values(5);
Query OK, 1 row affected (0.06 sec)
mysql> describe programa;
+--------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
+--------+----------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
mysql> insert into programa (nombre)values ("fibonaci");
Query OK, 1 row affected (0.03 sec)
mysql> insert into programa (nombre)values ("furier");
Query OK, 1 row affected (0.06 sec)
mysql> insert into programa (nombre)values ("factorial");
Query OK, 1 row affected (0.06 sec)
mysql> insert into programa (nombre)values ("puntero");
Query OK, 1 row affected (0.11 sec)
mysql> insert into programa (nombre)values ("c");
Query OK, 1 row affected (0.06 sec)
mysql> insert into programa_materia (id_programa,semestre)values (1,5);
Query OK, 1 row affected (0.06 sec)
mysql> insert into programa_materia (id_programa,semestre)values (2,6);
Query OK, 1 row affected (0.08 sec)
mysql> insert into programa_materia (id_programa,semestre)values (3,7);
Query OK, 1 row affected (0.06 sec)
mysql> insert into programa_materia (id_programa,semestre)values (4,8);
Query OK, 1 row affected (0.06 sec)
mysql> insert into programa_materia (id_programa,semestre)values (5,1);
Query OK, 1 row affected (0.06 sec)
mysql> describe materia;
+---------------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| id_usomateria | int(11) | YES | MUL | NULL | |
| id_programa_materia | int(11) | YES | MUL | NULL | |
| nombre | char(20) | YES | | NULL | |
+---------------------+----------+------+-----+---------+----------------+
4 rows in set (0.02 sec)
mysql> insert into materia(id_programa_materia,id_usomateria,nombre)values (1,1,
"biologia");
Query OK, 1 row affected (0.36 sec)
mysql> insert into materia(id_programa_materia,id_usomateria,nombre)values (2,2,
"fisica");
Query OK, 1 row affected (0.05 sec)
mysql> insert into materia(id_programa_materia,id_usomateria,nombre)values (3,3,
"algebra");
Query OK, 1 row affected (0.08 sec)
mysql> insert into materia(id_programa_materia,id_usomateria,nombre)values (4,4,
"programacion");
Query OK, 1 row affected (0.44 sec)
mysql> insert into materia(id_programa_materia,id_usomateria,nombre)values (5,5,
"ecuaciones");
Query OK, 1 row affected (0.06 sec)
mysql> describe tipousuario;
+------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
| id_usuario | int(11) | YES | MUL | NULL | |
+------------+----------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> describe usuario;
+--------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
+--------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> describe usomateria;
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| id_usuario | int(11) | YES | MUL | NULL | |
+------------+---------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> describe programa;
+--------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| nombre | char(20) | YES | | NULL | |
+--------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> describe programa_materia;
+-------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| id_programa | int(11) | YES | MUL | NULL | |
| semestre | int(11) | YES | | NULL | |
+-------------+---------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
mysql> describe materia;
+---------------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| id_usomateria | int(11) | YES | MUL | NULL | |
| id_programa_materia | int(11) | YES | MUL | NULL | |
| nombre | char(20) | YES | | NULL | |
+---------------------+----------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> on update cascade;

Você também pode gostar