Sometimes, during test stage, you may need to truncate or delete all your tables in a database, without droping constraints, truncating and recreating constraints (DRI). You can use the TRUNCATE TABLE statement to removes all rows from a table without logging the individual row deletes, but tables referenced by a FOREIGN KEY constraint can not be truncated. For them, you can use the DELETE statement, but you have to do it in the rigth order so you do not delete first the rows from a parent table and get an error because the DRI. This is what this script does.
This script does not check permissions, it supposes that you have sufficient to truncate or delete.
2007-10-02 (first published: 2002-06-20)
15,452 reads