Bug #74815 DROP TABLE order can be improved

Submitted: 12 Nov 2014 12:10 Modified: 19 Nov 2014 9:36
Reporter: Daniël van Eeden Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DDL Severity:S4 (Feature request)
Version:5.7 OS:Any
Assigned to: CPU Architecture:Any
Tags: drop table, usability

[12 Nov 2014 12:10] Daniël van Eeden
Description:
Page: http://dev.mysql.com/doc/refman/5.7/en/drop-table.html

The list of tables in a DROP TABLE statement have to be in the correct order. It drops as many tables as it can.

How to repeat:
mysql [test] > create table t1 (id int auto_increment primary key, name varchar(100) unique);
Query OK, 0 rows affected (0.01 sec)

mysql [test] > create table t2 (id int auto_increment primary key, name varchar(100), fname varchar(100), foreign key (fname) references t1 (name));
Query OK, 0 rows affected (0.01 sec)

mysql [test] > create table t3 (id int);
Query OK, 0 rows affected (0.01 sec)

mysql [test] > drop table t1, t2, t3;
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
mysql [test] > show tables;
+----------------+
| Tables_in_test |
+----------------+
| t1             |
+----------------+
1 row in set (0.00 sec)

mysql [test] > drop table t1;
Query OK, 0 rows affected (0.00 sec)

mysql [test] > create table t1 (id int auto_increment primary key, name varchar(100) unique);
Query OK, 0 rows affected (0.01 sec)

mysql [test] > create table t2 (id int auto_increment primary key, name varchar(100), fname varchar(100), foreign key (fname) references t1 (name));
Query OK, 0 rows affected (0.01 sec)

mysql [test] > create table t3 (id int);                                        Query OK, 0 rows affected (0.01 sec)

mysql [test] > drop table t3, t2, t1;
Query OK, 0 rows affected (0.01 sec)

Suggested fix:
Order the tables before dropping them.

Maybe also update the documentation:
 - Table order is significant
 - Tries to delete every table, doesn't stop or rollback on error (no transactional-DDL)
[19 Nov 2014 9:36] MySQL Verification Team
Hello Daniël,

Thank you for the feature request!
Indeed, useful to have this feature( of-course there is a work around for this e.g SET FOREIGN_KEY_CHECKS=0;DROP <table1>,tableN>..;SET FOREIGN_KEY_CHECKS=1; but till useful to have this feature). 

Thanks,
Umesh

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.049 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.