Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop a sqlite3 database in python?

Tags:

python

sqlite

I am testing some database manipulation with sqlite3 in python, but for some reason I am not able to replicate some commands from SQL in sqlite3. In my case I have a function that tests a query and it creates a sample database with some tables and data. However, I am not able to drop the database using sqlite and rather have to use the following code:

import os
os.remove(databaseName)

Would sqlite3 have any command for dropping a database, or even creating a temporary one?

like image 310
calestini Avatar asked Jul 16 '26 13:07

calestini


1 Answers

There is no command in sqlite to drop a database, as the database is saved in a file. To drop it you would just delete the file.

You can however create in-memory databases by using :memory: as the filename: conn = sqlite3.connect(':memory:'). See https://www.sqlite.org/inmemorydb.html