--创建含自增id和索引字段的表word_list
-- 创建表 word_list,包含自增 id 字段
CREATE TABLE word_list (
id INTEGER PRIMARY KEY AUTOINCREMENT,
word TEXT NOT NULL,
frequency INTEGER,
description TEXT
);
--查看表结构
PRAGMA table_info(your_table_name)
--查看表索引
-- 查看表 word_list 的所有索引
SELECT name, tbl_name, sql
FROM sqlite_master
WHERE type = 'index' AND tbl_name = 'your_table_name';
-- 为 word 字段添加索引
CREATE INDEX idx_word ON word_list(word);
--分析sql
EXPLAIN QUERY PLAN SELECT * FROM word_list WHERE word = 123;
--查看索引情况
SELECT name, tbl_name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = 'word_list';