When using the SQLite command line interface, you can use the .databases
command to return a list of attached databases. More specifically, it returns the names and file names/location of each attached database.
You can also use the PRAGMA database_list
statement to return a list of databases attached to the current database connection.
The .databases Command
Here’s an example of using the .databases
command:
.databases
Result:
main: /Users/Shared/sqlite/Chinook.db
In this case, I’ve only attached one database.
Here’s another example where I attached another database, then run the command again.
ATTACH DATABASE 'Pets.db' AS Pets;
.databases
Result:
main: /Users/Shared/sqlite/Chinook.db Pets: /Users/Shared/sqlite/Pets.db
The PRAGMA database_list Statement
Here’s an example of using the PRAGMA database_list
statement:
PRAGMA database_list;
Result:
seq name file ---------- ---------- ------------------------------- 0 main /Users/Shared/sqlite/Chinook.db 2 Pets /Users/Shared/sqlite/Pets.db