How to list the tables in an SQLite database file that was opened with ATTACH?
在SQLite数据库文件中,可以使用什么SQL来列出这些表以及这些表中的行 - 使用SQLite 3命令行工具上的ATTACH
命令将其附加到SQLite数据库文件中?
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';
There are a few steps to see the tables in an SQLite database:
List the tables in your database:
.tables
List how the table looks:
.schema tablename
Print the entire table:
SELECT * FROM tablename;
List all of the available SQLite prompt commands:
.help
It appears you need to go through the sqlite_master table, like this:
SELECT * FROM dbname.sqlite_master WHERE type='table';
And then manually go through each table with a SELECT
or similar to look at the rows.
The .DUMP
and .SCHEMA
commands doesn't appear to see the database at all.