Wednesday, October 30, 2019

sql - How to list the tables in a SQLite database file that was opened with ATTACH?



What SQL can be used to list the tables, and the rows within those tables in a SQLite database file - once I have attached it with the ATTACH command on the SQLite 3 command line tool?


Answer



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';

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...