How do I list all tables/indices contained in an SQLite database

How do I list all tables/indices contained in an SQLite database

If you are running the sqlite3 command-line access program you can type ".tables" to get a list of all tables. Or you can type ".schema" to see the complete database schema including all tables and indices. Either of these commands can be followed by a LIKE pattern that will restrict the tables that are displayed.

From within a C/C++ program (or a script using Tcl/Ruby/Perl/Python bindings) you can get access to table and index names by doing a SELECT on a special table named "SQLITE_MASTER". Every SQLite database has an SQLITE_MASTER table that defines the schema for the database. The SQLITE_MASTER table looks like this:

CREATE TABLE sqlite_master (
  type TEXT,
  name TEXT,
  tbl_name TEXT,
  rootpage INTEGER,
  sql TEXT
);

For tables, the type field will always be ‘table‘ and the name field will be the name of the table. So to get a list of all tables in the database, use the following SELECT command:

SELECT name FROM sqlite_master
WHERE type=‘table‘
ORDER BY name;

For indices, type is equal to ‘index‘, name is the name of the index and tbl_name is the name of the table to which the index belongs. For both tables and indices, the sql field is the text of the original CREATE TABLE or CREATE INDEX statement that created the table or index. For automatically created indices (used to implement the PRIMARY KEY or UNIQUE constraints) the sql field is NULL.

The SQLITE_MASTER table is read-only. You cannot change this table using UPDATE, INSERT, or DELETE. The table is automatically updated by CREATE TABLE, CREATE INDEX, DROP TABLE, and DROP INDEX commands.

Temporary tables do not appear in the SQLITE_MASTER table. Temporary tables and their indices and triggers occur in another special table named SQLITE_TEMP_MASTER. SQLITE_TEMP_MASTER works just like SQLITE_MASTER except that it is only visible to the application that created the temporary tables. To get a list of all tables, both permanent and temporary, one can use a command similar to the following:

SELECT name FROM
   (SELECT * FROM sqlite_master UNION ALL
    SELECT * FROM sqlite_temp_master)
WHERE type=‘table‘
ORDER BY name
时间: 2024-10-08 16:00:26

How do I list all tables/indices contained in an SQLite database的相关文章

[转]Android Studio SQLite Database Multiple Tables Example

本文转自:http://instinctcoder.com/android-studio-sqlite-database-multiple-tables-example/ BY TAN WOON HOW · PUBLISHED JANUARY 29, 2016 · UPDATED MAY 6, 2016 In this tutorial we going to do a little complex SQL statement which I think will help you to fur

About SQLite

About SQLite See Also... Features When to use SQLite Frequently Asked Questions Well-known Users Books About SQLite Getting Started SQL Syntax Pragmas SQL functions Date & time functions Aggregate functions C/C++ Interface Spec Introduction List of C

[转]Android Studio SQLite Database Example

本文转自:http://instinctcoder.com/android-studio-sqlite-database-example/ BY TAN WOON HOW · PUBLISHED APRIL 9, 2014 · UPDATED JUNE 23, 2016 SQLiteDatabase is a class that allowed us to perform Create, Retrieve , Update, and Delete data (CRUD) operation.

detecting locked tables mysql (locked by LOCK TABLE)

detecting locked tables mysql (locked by LOCK TABLE) up vote15down votefavorite 7 I would like to know whether there is an option to detect locked tables in mysql or not. I mean locked by LOCK TABLE table WRITE/READ command? mysql locking share|impro

elasticSearch indices VS type

elasticSearch 的中文文档 http://es.xiaoleilu.com/010_Intro/05_What_is_it.html https://www.elastic.co/blog/index-vs-type Who has never wondered whether new data should be put into a new type of an existing index, or into a new index? This is a recurring qu

SQLite的使用详解

一.SQLite简介   SQLite是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了.它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如Tcl.PHP.Java等,还有ODBC接口,同样比起Mysql.PostgreSQL这两款开源世界著名的数据库管理系统来讲,它的处理速度比他们都快. 下面就是SQLite的

MYSQL ERROR

mysql出错了以前往往靠猜.有了这张表一查就出来了.方便不少.特共享于众 1005创建表失败 1006创建数据库失败 1007数据库已存在创建数据库失败 1008数据库不存在删除数据库失败 1009不能删除数据库文件导致删除数据库失败 1010不能删除数据目录导致删除数据库失败 1011删除数据库文件失败 1012不能读取系统表中的记录 1020记录已被其他用户修改 1021硬盘剩余空间不足请加大硬盘可用空间 1022关键字重复更改记录失败 1023关闭时发生错误 1024读文件错误 1025

所有表和动态视图列表(dict)

TABLE_NAME    COMMENTSDBA_CONS_COLUMNS    Information about accessible columns in constraint definitionsDBA_LOG_GROUP_COLUMNS    Information about columns in log group definitionsDBA_LOBS    Description of LOBs contained in all tablesDBA_CATALOG    A

【Android】Sqlite3命令详解

Sqlite3常用命令 Sqlite3命令有"."符合作为前缀. 基本操作 1.创建或者打开数据库 sqlite3 xxx.db 如果xxx.db存在则打开如果没有则新建此时执行创建表的命令后才会出现xxx.db文件. 创建xxx.db数据库 sqlite3 xxx.db CREATE TABLE record(id integer primary key autoincrement,time varchar(20),name varchar(30),count int); 2.查看表