sqlite get name of attached databases
Asked Answered
P

3

19

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.

Priapus answered 6/8, 2013 at 5:43 Comment(0)
M
39

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.

Maximo answered 6/8, 2013 at 6:4 Comment(0)
A
10

You can use .database command.

Argillaceous answered 6/8, 2013 at 6:7 Comment(1)
Aren't these dot commands like .database, .open xyz etc. proprietary to the command line interface from SQLite Tools?Fess
F
3

This query below can get the name of attached databases:

SELECT * FROM pragma_database_list;
Fornix answered 15/10, 2022 at 2:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.