All pastes #427012 Raw Edit

snoyes

public sql v1 · immutable
·published 2007-04-06 15:21 UTC
rendered paste body
mysql> CREATE TABLE t1 (id int, index(id)) ENGINE=INNODB;Query OK, 0 rows affected (0.08 sec)mysql> CREATE TABLE t2 (id int, index(id), FOREIGN KEY (id) REFERENCES t1 (id)) ENGINE=InnoDB;Query OK, 0 rows affected (0.09 sec)mysql> INSERT INTO t1 VALUES (1), (1);Query OK, 2 rows affected (0.05 sec)Records: 2  Duplicates: 0  Warnings: 0mysql> INSERT INTO t2 VALUES (1), (1);Query OK, 2 rows affected (0.03 sec)Records: 2  Duplicates: 0  Warnings: 0mysql> SELECT * FROM t1; SELECT * FROM t2;+------+| id   |+------+|    1 ||    1 |+------+2 rows in set (0.00 sec)+------+| id   |+------+|    1 ||    1 |+------+2 rows in set (0.00 sec)mysql> DELETE FROM t1 LIMIT 1;ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`test/t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))