Bug #39050 DROP TABLE don't stop after an error
Submitted: 26 Aug 2008 16:27 Modified: 27 Aug 2008 8:44
Reporter: Susanne Ebrecht Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.0, 5.1, 6.0 OS:Any
Assigned to: CPU Architecture:Any
Tags: DDL

[26 Aug 2008 16:27] Susanne Ebrecht
Description:
CREATE TABLE t(i INTEGER, PRIMARY KEY(i)) engine=innodb;
CREATE TABLE t1(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(j) REFERENCES t(i))engine=innodb;

DROP TABLE t, t1;

ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
mysql> show tables;
+-------------------+
| Tables_in_miracee |
+-------------------+
| t                 | 
+-------------------+

As you can see table t1 was dropped.

Usually, Innodb should recognise that it can't drop table t and then stop dropping. It should not drop the following tables.

Of course when you say DROP TABLE t1, t; then both tables dropped.

How to repeat:
CREATE TABLE t(i INTEGER, PRIMARY KEY(i)) engine=innodb;
CREATE TABLE t1(i INTEGER, j INTEGER, PRIMARY KEY(i), FOREIGN KEY(j) REFERENCES t(i))engine=innodb;

DROP TABLE t, t1;

Suggested fix:
Exit when the first table through an error.
[27 Aug 2008 8:44] Sergei Golubchik
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

See the manual for DROP TABLE