sqlite get name of attached databases
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.
List Attached Databases using a SELECT command in SQLite
You cannot do this with a SELECT statement that I know of (though you might want to look around in the main
database, this data might be stored there). However, there is a solution. If you execute the following statement it will return the databases attached for the current connection:
PRAGMA database_list;
The first row will always be the main database, the second will always be the temp database. Any further databases are after these first two. You can run this statement against your database the same way you would a SELECT statement from your code in c# (or anything else for that matter).
Here is a good reference:
SQLite PRAGMA statement reference
Good luck!
How can I list the tables in a SQLite database file that was opened with ATTACH?
The .tables
, and .schema
"helper" functions don't look into ATTACHed databases: they just query the SQLITE_MASTER
table for the "main" database. Consequently, if you used
ATTACH some_file.db AS my_db;
then you need to do
SELECT name FROM my_db.sqlite_master WHERE type='table';
Note that temporary tables don't show up with .tables
either: you have to list sqlite_temp_master
for that:
SELECT name FROM sqlite_temp_master WHERE type='table';
SQLite / .NET: Get table names for attached database
GetSchema
does not support attached databases.
You have read the table names directly from the system table:
SELECT name FROM MyOtherDB.sqlite_master WHERE type = 'table'
Related Topics
Mssql: Update Statement Avoiding the Check Constraint
Datareader Ordinal-Based Lookups VS Named Lookups
What Is the Default SQL Result Sort Order with 'Select *'
Split Comma Separated String Table Row into Separate Rows Using Tsql
How to Have a Foreign Key Pointing to Two Primary Keys
Distance Between Two Coordinates, How to Simplify This And/Or Use a Different Technique
Using Variables in Classic Asp Parameterized SQL
Is There Better Oracle Operator to Do Null-Safe Equality Check
Postgres Trigger-Based Insert Redirection Without Breaking Returning
SQL Server Fuzzy Search with Percentage of Match
Ssrs - Group_Concat Equivalent Using an Expression
Tally Table to Insert Missing Dates Between Two Dates? SQL
Complicated SQL Query--Finding Items Matching Multiple Different Foreign Keys
Efficient Query to Split a Delimited Column into Separate Rows in Another Table
How to Concatenate Multiple Rows
Oracle SQL: the Insert Query with Regexp_Substr Expression Is Very Long ( Split String )