7

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?

1 Answer 1

16

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

Sign up to request clarification or add additional context in comments.

1 Comment

However the database may reference temporary files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.