Skip to content

Instantly share code, notes, and snippets.

@koturn
Last active October 29, 2025 02:48
Show Gist options
  • Select an option

  • Save koturn/53d7d2dd0bf94fc694d80f975a663a14 to your computer and use it in GitHub Desktop.

Select an option

Save koturn/53d7d2dd0bf94fc694d80f975a663a14 to your computer and use it in GitHub Desktop.
SQLiteの特殊テーブル

sqlite_schema / sqlite_master / sqlite_temp_schema / sqlite_temp_master

公式サイトの説明

内容

カラム名 説明
type TEXT The sqlite_schema.type column will be one of the following text strings: 'table', 'index', 'view', or 'trigger' according to the type of object defined. The 'table' string is used for both ordinary and virtual tables.
name TEXT The sqlite_schema.name column will hold the name of the object. UNIQUE and PRIMARY KEY constraints on tables cause SQLite to create internal indexes with names of the form "sqlite_autoindex_TABLE_N" where TABLE is replaced by the name of the table that contains the constraint and N is an integer beginning with 1 and increasing by one with each constraint seen in the table definition. In a WITHOUT ROWID table, there is no sqlite_schema entry for the PRIMARY KEY, but the "sqlite_autoindex_TABLE_N" name is set aside for the PRIMARY KEY as if the sqlite_schema entry did exist. This will affect the numbering of subsequent UNIQUE constraints. The "sqlite_autoindex_TABLE_N" name is never allocated for an INTEGER PRIMARY KEY, either in rowid tables or WITHOUT ROWID tables.
tbl_name TEXT The sqlite_schema.tbl_name column holds the name of a table or view that the object is associated with. For a table or view, the tbl_name column is a copy of the name column. For an index, the tbl_name is the name of the table that is indexed. For a trigger, the tbl_name column stores the name of the table or view that causes the trigger to fire.
rootpage INTEGER The sqlite_schema.rootpage column stores the page number of the root b-tree page for tables and indexes. For rows that define views, triggers, and virtual tables, the rootpage column is 0 or NULL.
sql TEXT The sqlite_schema.sql column stores SQL text that describes the object. This SQL text is a CREATE TABLE, CREATE VIRTUAL TABLE, CREATE INDEX, CREATE VIEW, or CREATE TRIGGER statement that if evaluated against the database file when it is the main database of a database connection would recreate the object.

SQL例

SELECT * FROM sqlite_schema;
SELECT type, name, tbl_name, rootpage, sql FROM sqlite_schema;

sqlite_parameters

公式サイトの説明

内容

カラム名 説明
key TEXT ※PK
value TEXT

SQL例

SELECT * FROM sqlite_parameters;
SELECT key, value FROM sqlite_parameters;

PRAGMA table_list / pragma_table_list

公式サイトの説明

内容

カラム名 説明
schema TEXT
name TEXT
type TEXT
ncol INTEGER
wr INTEGER
strict INTEGER

SQL例

PRAGMA table_list;
SELECT * FROM pragma_table_list;
SELECT schema, name, type, ncol, wr, strict FROM pragma_table_list;

PRAGMA collation_list / pragma_collation_list

公式サイトの説明

内容

T.B.D.

SQL例

PRAGMA collation_list;
SELECT * FROM pragma_collation_list;
SELECT seq, name FROM pragma_collation_list;

PRAGMA database_list / pragma_database_list

公式サイトの説明

内容

T.B.D.

SQL例

PRAGMA database_list;
SELECT * FROM pragma_database_list;
SELECT seq, name, file FROM pragma_database_list;

PRAGMA foreign_key_list() / pragma_foreign_key_list()

公式サイトの説明

内容

T.B.D.

SQL例

PRAGMA foreign_key_list(テーブル名);
SELECT * FROM pragma_foreign_key_list(@table_name);
SELECT id, seq, "table", "from", "to", on_update, on_delete, match FROM pragma_foreign_key_list(@table_name);
  • @table_nameTEXT 型でテーブル名
  • PRAMGA文ではパラメータ使用不可

PRAGMA function_list / pragma_function_list

公式サイトの説明

内容

T.B.D.

SQL例

PRAGMA function_list;
SELECT * FROM pragma_function_list;
SELECT name, builtin, type, enc, narg, flags FROM pragma_function_list;

PRAGMA index_list() / pragma_index_list()

公式サイトの説明

内容

カラム名 説明
seq INTEGER A sequence number assigned to each index for internal tracking purposes.
name TEXT The name of the index.
unique INTEGER "1" if the index is UNIQUE and "0" if not.
origin TEXT "c" if the index was created by a CREATE INDEX statement, "u" if the index was created by a UNIQUE constraint, or "pk" if the index was created by a PRIMARY KEY constraint.
partial INTEGER "1" if the index is a partial index and "0" if not.

SQL例

PRAGMA table_list(テーブル名);
SELECT * FROM pragma_table_list(@table_name);
SELECT seq, name, "unique", origin, partial FROM pragma_table_list(@table_name);
  • @table_nameTEXT 型でテーブル名
  • PRAMGA文ではパラメータ使用不可

PRAGMA module_list / pragma_module_list

公式サイトの説明

内容

T.B.D.

SQL例

PRAGMA module_list;
SELECT * FROM pragma_module_list;
SELECT name FROM pragma_module_list;

PRAGMA pragma_list / pragma_pragma_list

公式サイトの説明

内容

T.B.D.

SQL例

PRAGMA pragma_list;
SELECT * FROM pragma_pragma_list;
SELECT name FROM pragma_pragma_list;

PRAGMA table_info() / pragma table_info()

公式サイトの説明

内容

カラム名 説明
cid INTEGER
name TEXT
type TEXT
notnull INTEGER
dflt_value ANY
pk INTEGER

SQL例

PRAGMA table_info(テーブル名);
SELECT * FROM pragma_table_info(@table_name);
SELECT cid, name, type, "notnull", dflt_value, pk FROM pragma_table_info(@table_name);
  • @table_nameTEXT 型でテーブル名
  • PRAMGA文ではパラメータ使用不可

PRAGMA table_xinfo() / pragma table_xinfo()

公式サイトの説明

内容

カラム名 説明
cid INTEGER
name TEXT
type TEXT
notnull INTEGER
dflt_value ANY
pk INTEGER
hiddne INTEGER

SQL例

PRAGMA table_xinfo(テーブル名);
SELECT * FROM pragma_table_xinfo(@table_name);
SELECT cid, name, type, "notnull", dflt_value, pk, hidden FROM pragma_table_xinfo(@table_name);
  • @table_nameTEXT 型でテーブル名
  • PRAMGA文ではパラメータ使用不可

PRAGMA index_info() / pragma index_info()

公式サイトの説明

内容

カラム名 説明
seqno INTEGER The rank of the column within the index. (0 means left-most.)
cid INTEGER The rank of the column within the table being indexed. A value of -1 means rowid and a value of -2 means that an expression is being used.
name TEXT The name of the column being indexed. This columns is NULL if the column is the rowid or an expression.

SQL例

PRAGMA index_info(インデックス名);
SELECT * pragma_index_info(@index_name);
SELECT seqno, cid, name FROM pragma_index_info(@index_name);
  • @index_nameTEXT 型でインデックス名
  • PRAMGA文ではパラメータ使用不可

PRAGMA index_xinfo() / pragma index_xinfo()

公式サイトの説明

内容

カラム名 説明
seqno INTEGER The rank of the column within the index. (0 means left-most. Key columns come before auxiliary columns.)
cid INTEGER The rank of the column within the table being indexed, or -1 if the index-column is the rowid of the table being indexed and -2 if the index is on an expression.
name TEXT The name of the column being indexed, or NULL if the index-column is the rowid of the table being indexed or an expression.
desc INTEGER 1 if the index-column is sorted in reverse (DESC) order by the index and 0 otherwise.
coll TEXT The name for the collating sequence used to compare values in the index-column.
key INTEGER 1 if the index-column is a key column and 0 if the index-column is an auxiliary column.

SQL例

PRAGMA index_xinfo(インデックス名);
SELECT * pragma_index_xinfo(@index_name);
SELECT seqno, cid, name, desc, coll, key FROM pragma_index_xinfo(@index_name);
  • @index_nameTEXT 型でインデックス名
  • PRAMGA文ではパラメータ使用不可

EXPLAIN

公式サイトの説明

SQLのバイトコードを取得する.

他のRDBMSと違い,実行計画の取得でないことに注意. 実行計画の取得は EXPLAIN QUERY PLAN である.

sqlite3コマンドでは特殊扱いで,通常のクエリと異なった整形表示であるが,ライブラリ等を経由して実行すると,クエリのような結果が得られる.

内容

カラム名 説明
addr INTEGER
opcode TEXT
p1 INTEGER
p2 INTEGER
p3 INTEGER
p4 TEXT
p5 INTEGER
comment COMMENT

SQL例

EXPLAIN [SQL文];
  • サブクエリ等への利用は不可

EXPLAIN QUERY PLAN

公式サイトの説明

SQLの実行計画を取得する.

sqlite3コマンドでは特殊扱いで,通常のクエリと異なったツリー形式の整形表示であるが,ライブラリ等を経由して実行すると,クエリのような結果が得られる.

内容

カラム名 説明
id INTEGER
parent INTEGER
notused INTEGER
detail TEXT

SQL例

EXPLAIN QUERY PLAN [SQL文];
  • サブクエリ等への利用は不可
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment