SQLite Forum

Feature Request: consistent .dump order
Login
> Actually, the above does NOT do the trick, but results in a corrupted database

Yeah, tables should be defined before anything that refers to them.

You need a different sort order, illustrated by this script:

```sql
.mode column
.headers on
.width -5 9 32 32 -8 -6
SELECT ROWID,type,name,tbl_name,rootpage,
CASE
	WHEN type=='table' THEN 1
	WHEN type=='index' THEN 2
	WHEN type=='trigger' THEN 3
	ELSE 9
END AS srtord
FROM sqlite_master 
ORDER BY srtord,tbl_name,name;
```

In reality, things are even more complicated of you want to insert in dependency order, with
```PRAGMA foreign_keys=on```
Parent tables have to be loaded befor children.

~~~
-- 
Regards,
Kees Nuyt
~~~