mysql> ALTER TABLE cliente DROP FOREIGN KEY id_cliente;
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe prestamo;
+-----------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------+------+-----+---------+----------------+
| numero_prestamo | int(11) | NO | PRI | NULL | auto_increment |
| importe | int(11) | YES | | NULL | |
+-----------------+---------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
mysql> describe cliente;
+----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+----------------+
| id_cliente | int(11) | NO | PRI | NULL | auto_increment |
| nombre_cliente | varchar(20) | YES | | NULL | |
| calle_cliente | varchar(20) | YES | | NULL | |
| ciudad_cliente | varchar(20) | YES | | NULL | |
+----------------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql> alter table prestamo ADD CONSTRAINT key FOREIGN KEY (numerp_prestamo) REFERENCES cliente(id_cliente) ON DELETE CASCADE ON UPDATE;
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 'key FOREIGN KEY (numerp_prestamo) REFERENCES cliente(id_cliente) ON DELETE CASCA' at line 1
mysql> alter table prestamo ADD CONSTRAINT key FOREIGN KEY (numerp_prestamo) REFERENCES cliente(id_cliente) ON DELETE CASCADE ON UPDATE CASCADE;
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 'key FOREIGN KEY (numerp_prestamo) REFERENCES cliente(id_cliente) ON DELETE CASCA' at line 1
mysql> alter table prestamo ADD CONSTRAINT key FOREIGN KEY (numero_prestamo) REFERENCES cliente(id_cliente) ON DELETE CASCADE ON UPDATE CASCADE;
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 'key FOREIGN KEY (numero_prestamo) REFERENCES cliente(id_cliente) ON DELETE CASCA' at line 1
mysql> ALTER TABLE prestamo ADD FOREIGN KEY (id_cliente) REFERENCES cliente(id_cliente);
ERROR 1072 (42000): Key column 'id_cliente' doesn't exist in table
mysql> describe prestamo;
+-----------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------+------+-----+---------+----------------+
| numero_prestamo | int(11) | NO | PRI | NULL | auto_increment |
| importe | int(11) | YES | | NULL | |
+-----------------+---------+------+-----+---------+----------------+
2 rows in set (0.02 sec)
mysql> alter table prestamo add(id_cliente INT NOT NULL);
Query OK, 0 rows affected (0.05 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> ALTER TABLE prestamo ADD FOREIGN KEY (id_cliente) REFERENCES cliente(id_cliente);
Query OK, 0 rows affected (0.07 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> describe prestamo;
+-----------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------+------+-----+---------+----------------+
| numero_prestamo | int(11) | NO | PRI | NULL | auto_increment |
| importe | int(11) | YES | | NULL | |
| id_cliente | int(11) | NO | MUL | NULL | |
+-----------------+---------+------+-----+---------+----------------+
3 rows in set (0.01 sec)
mysql> describe cliente;
+----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+----------------+
| id_cliente | int(11) | NO | PRI | NULL | auto_increment |
| nombre_cliente | varchar(20) | YES | | NULL | |
| calle_cliente | varchar(20) | YES | | NULL | |
| ciudad_cliente | varchar(20) | YES | | NULL | |
+----------------+-------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
No hay comentarios:
Publicar un comentario