Sometimes for scripting purposes is good to produce a table insertion/deletion order for a MySQL schema. For InnoDB schemas this is important to satisfy constraints without the need of disabling foreign key checks.

Working out a table insertion/deletion order in MySQL is no so straight forward because MySQL does not store anywhere a position or index in which a table was created. The order must be collected from the relationships stored in the information schema.

The following snippet in C++ with Qt generates an insertion order.

[prism url=http://www.qlands.com/snippets/order.cpp language=cpp class=line-numbers]