1

There is this particular database named temp which I want to delete which was created using SQLite on ubuntu machine. How do I delete this databse?

dmn
  • 41
  • 1
  • 1
  • 3

2 Answers2

2

The case is quite simple.

Either delete the file like this :

rm -fr filename

Or in terminal type something like :

$ sqlite3 tempfile (where tempfile is the name of the file)

sqlite> SELECT * FROM sqlite_master WHERE type='table';

You will see a list of tables like this as an example:

table|friends|friends|2|CREATE TABLE friends (id int)

then just type

sqlite> drop table friends (or the name you want to drop)

Then press ctrl-d to exit.

It is that simple

Trausti Thor
  • 3,722
  • 31
  • 41
0

SQLite saves data to a file. Leverage the methods tailored to the specific OS so you can delete the file. I.E. with Android use the System.IO.File.Delete() method.

Here is some code showing what I used to create and delete my SQLite database on an android device in C#:

public class SQLite_DB 
{
    private string databasePath;

    public SQLiteAsyncConnection GetConnection()
    {
        databasePath = Path.Combine(FileSystem.AppDataDirectory, "sqlite_db.db3");
        SQLiteAsyncConnection database = new SQLiteAsyncConnection(databasePath);
        return database;
    }

    public bool DeleteDatabase()
    {
        File.Delete(databasePath);

        if (File.Exists(databasePath))
        return false;

        return true;
    }
}

For Ubuntu, a simple rm -rf [database path/filename] should suffice.

  • Note that there can remain `databasePath + "-journal"`, `databasePath + "-wal"` and/or `databasePath + "-shm"` files left over if the application crashed or the journal/WAL is permanent. – xOneca Jul 18 '22 at 13:39