0

I want to remove all entered data into my SQL database. I am using Python to handle all of the SQL statements from the program - however I did not make a backup of the clean database, and I want to clear all the records and reset primary IDs etc without affecting the structure of the database so it is ready to ship with my code.

I am using Python and SQLiteStudio.

Thanks.

CrhonamO
  • 25
  • 4

1 Answers1

1

In SQLiteStudio's SQL editor execute this command:

DELETE FROM table_name;

If you have multiple tables then the command is:

DELETE FROM table_name_1, table_name_2,...;

Instead of table_name you put the name of your table(s).

doru
  • 9,022
  • 2
  • 33
  • 43
  • 1
    I'd also suggest to execute a `VACUUM;` afterwards (or click "Vacuum" from SQLiteStudio context menu after right-click on the database), so the database file size is shrinked to minimum, making it ready for shipment. – Googie Apr 10 '15 at 06:45
  • This didn't work as I had foreign keys all over the place (not in an inefficient way - I know my normalization). I managed to copy the DDL and drop each table and reinstate each one - this worked just fine. – CrhonamO Apr 10 '15 at 10:17
  • In future you can do it more automatically - right-click on a database, pick "Export database", select all items to export, then **uncheck** the "Export data" option and finally (on last step page) pick SQL format for export and export to file. You should get whole database (all object DLLs) in a single file, excluding table data. – Googie Apr 10 '15 at 10:38