SQLite | Database | Checking Connected Databases

This page explains how to display information about the currently connected database in SQLite and the file where that database is stored.

Information About Connected Databases

When you are connected to a database, use the SQLite command .databases to display the current database name and the file name where the database is stored.

.databases

Now check it in practice. First, connect to the myfriend.sqlite3 database and enter .databases.

$ sqlite3 myfriend.sqlite3
SQLite version 3.19.3 2017-06-27 16:48:08
Enter ".help" for usage hints.
sqlite> .databases
main: /Users/devkuma/sqlite/myfriend.sqlite3
sqlite> 

The following information is displayed on the screen.

main is the database name, and /Users/devkuma/sqlite/myfriend.sqlite3 is the file name where the database is stored.

The term database name may be confusing here. main is the name used when you need to specify a database name in an SQL statement, in the same way that you specify table names and column names. A database connected with sqlite3 database-name is automatically assigned the database name main. In other words, the entry whose database name is main is the connected database.

The name main may seem important now, but you can ignore it for the moment. The details are not covered here, but when attached databases exist, they are also displayed in the list when you run the .databases command. The displayed database name is the name specified when the database was attached.

$ sqlite3 myfriend.sqlite3
SQLite version 3.19.3 2017-06-27 16:48:08
Enter ".help" for usage hints.
sqlite> 
sqlite> attach database 'myaddress.sqlite3' as address;
sqlite> 
main: /Users/devkuma/sqlite/myfriend.sqlite3
address: /Users/devkuma/sqlite/myaddress.sqlite3
sqlite> 

In this way, you can use the .databases command to check information about the currently connected databases.