This SQLite post explains how to use the SQLite DETACH DATABASE command with syntax and examples.
The SQLite DETACH DATABASE command is used to detach an attached database from your current database connection.
The syntax for the DETACH DATABASE command in SQLite is:
Optional. The command can be run as either DETACH DATABASE or DETACH.
The logical name for the database that you wish to detach from the current database connection.
Let's look at an example of how to detach an attached database in SQLite.
First, we'll use the .database command to show all the databases in our current connection:
As you can see, we have our primary database called main that can be found in the location /AODBA/test.sqlite as well as an attached database called example that is located at /AODBA/example.sqlite. Next, let's detach the example database with the following command:
Now that we have detached the example database, let's re-run the .database command to show all of the databases in our current connection:
Now you can see that the example database has been detached and only the main database is available in the current database connection.
To attach a database, use the ATTACH DATABASE command.