0

Is there any way to delete all the tables from sqlite database or clean the specific database storage in python?

We have a database - myproject.db in sqlite, and have 13 tables in it. We have to clean the storage as after the tables data is processed , we want new data to be stored in it.

pp45
  • 17
  • 5
  • 2
    https://stackoverflow.com/questions/27606518/how-to-drop-all-tables-from-a-database-with-one-sql-query – Sembei Norimaki May 02 '23 at 12:39
  • Please suggest in python @SembeiNorimaki – pp45 May 02 '23 at 13:57
  • 1
    Can't you run SQL queries in python? The answer will vary depending which libraries you use. Are you using SQLAlchemy or some other library in python? – Sembei Norimaki May 02 '23 at 14:07
  • we can't delete db in sqlite, how can we delete file in sqlite , using sqlite3 library in python? – pp45 May 02 '23 at 14:38
  • "We have to clean the storage as after the tables data is processed , we want new data to be stored in it" it looks like you don't want to delete the tables but empty them instead. Those are very different things. Do you want this tables to be deleted or emptied? My link and the answer you got are about how to delete (drop) tables, which might not be what you want at all. – Sembei Norimaki May 02 '23 at 14:50
  • I want to remove all the tables, or can we empty the myproject.db ? – pp45 May 02 '23 at 15:13
  • The logical thing would be to empty the tables, so new data can be inserted, but maybe the script that inserts the data first creates it, so I don't know. I think if you already have some process that introduces data in the tables, you should use the same processes to clean this data afterwards. We don't know what library are you using to insert this data. If you know the name of the library you can then search how to delete data or table with this same library – Sembei Norimaki May 02 '23 at 15:20

1 Answers1

-1

Try with this DROP TABLE IF EXISTS table_name

  • 1
    That doens't answer the question: OP asked a way to delete all the tables without specifying them one by one – Lorenzo Mogicato May 02 '23 at 14:35
  • we want to drop database or all the tables from it insqlite? – pp45 May 02 '23 at 14:39
  • @pp45 Do your really want to drop those tables and create them again? Or you just want to delete the data inside this tables? – Sembei Norimaki May 02 '23 at 14:52
  • To add to the comments already made, this answer also is not how to do it in python, which is part of the question above. Suggest you read the question more thoroughly to make sure you are answering it exactly. Also FWIW seems like this question could have been answered by linking existing answers to how to execute sql commands from python and how to drop all tables in sql. – Matt C. May 03 '23 at 17:24
  • To add to the comments already made, this answer also is not how to do it in python, which is part of the question above. Suggest you read the question more thoroughly to make sure you are answering it exactly. Also FWIW seems like this question could have been answered by linking existing answers to how to execute sql commands from python and how to drop all tables in sql. – Matt C. May 03 '23 at 17:24