SQLite 中的 sqlite_master 表

需求:有一个 SQLite 的 db 数据库文件,现在需要列出这个数据库文件的所有表的信息。

SQLite 的数据库中有一个自动生成的 sqlite_master 表,表中保存数据库表的关键信息。如要查看表概要,可按如下操作:
这个表的结构如下:

1
2
3
4
5
6
7
CREATE TABLE sqlite_master (
type text,
name text,
tbl_name text,
rootpage integer,
sql text
);

type 字段的值是 tablename 字段是表的名字,sql 字段是表的创建语句。
所以想要查看数据库中所有表的信息可以执行以下语句:

1
2
3
SELECT name FROM sqlite_master 
WHERE type = 'table'
ORDER BY name;

文章来自: https://hanks.pub