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

前端 未结 17 2272
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 11:33

What SQL can be used to list the tables, and the rows within those tables in an SQLite database file - once I have attached it with the

相关标签:
17条回答
  • 2020-11-22 12:18

    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';
    
    0 讨论(0)
  • 2020-11-22 12:21

    Use .help to check for available commands.

    .table
    

    This command would show all tables under your current database.

    0 讨论(0)
  • 2020-11-22 12:28

    As of the latest versions of SQLite 3 you can issue:

    .fullschema
    

    to see all of your create statements.

    0 讨论(0)
  • 2020-11-22 12:29

    There are a few steps to see the tables in an SQLite database:

    1. List the tables in your database:

      .tables
      
    2. List how the table looks:

      .schema tablename
      
    3. Print the entire table:

      SELECT * FROM tablename;
      
    4. List all of the available SQLite prompt commands:

      .help
      
    0 讨论(0)
  • 2020-11-22 12:30

    Via a union all, combine all tables into one list.

    select name
    from sqlite_master 
    where type='table'
    
    union all 
    
    select name 
    from sqlite_temp_master 
    where type='table'
    
    0 讨论(0)
提交回复
热议问题