Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 607
マルちゃん だよ Avatar asked Aug 06 '13 05:08

マルちゃん だよ


People also ask

How do I find my SQLite database name?

You can use . database command. Aren't these dot commands like . database , .

How can I see all SQLite databases?

To show all databases in the current connection, you use the . databases command. The . databases command displays at least one database with the name: main .

What is Attach database in SQLite?

The ATTACH DATABASE statement adds another database file to the current database connection. Database files that were previously attached can be removed using the DETACH DATABASE command.


2 Answers

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.

like image 154
peterm Avatar answered Oct 01 '22 12:10

peterm


You can use .database command.

like image 24
prageeth Avatar answered Oct 01 '22 12:10

prageeth