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.

    链接地址: http://www.djcxy.com/p/3334.html

    上一篇: UPSERT *不是* INSERT或REPLACE

    下一篇: 如何列出使用ATTACH打开的SQLite数据库文件中的表?