Bigger
Bigger

Reputation: 1970

sqlite get name of attached databases

How do I get the name of the Attached databases in SQLite?

I've tried looking into:

SELECT name FROM sqlite_master

But there doesn't seem to be any information there about the attached databases.

I attach the databases with the command:

ATTACH DATABASE <fileName> AS <DBName>

It would be nice to be able to retrieve a list of the FileNames or DBNames attached.

I'm trying to verify if a database was correctly attached without knowing its schema beforehand.

Upvotes: 21

Views: 25444

Answers (3)

This query below can get the name of attached databases:

SELECT * FROM pragma_database_list;

Upvotes: 3

prageeth
prageeth

Reputation: 7395

You can use .database command.

Upvotes: 12

peterm
peterm

Reputation: 92795

Are you looking for this?

PRAGMA database_list;

PRAGMA database_list;
This pragma works like a query to return one row for each database attached to the current database connection. The second column is the "main" for the main database file, "temp" for the database file used to store TEMP objects, or the name of the ATTACHed database for other database files. The third column is the name of the database file itself, or an empty string if the database is not associated with a file.

Upvotes: 42

Related Questions