sqlite查看表结构的方法:sqlite的”show tables” & “describe table”
- show tables in sqlite
命令行模式
.schema
抓出数据库中所有的表
.tables
抓出数据库中所有的表和索引
都可以使用LIKE来匹配
程序中
使用sqlite中的sqlite_master表来查询
sqlite_master表结构
CREATE TABLE sqlite_master (
type TEXT,
name TEXT,
tbl_name TEXT,
rootpage INTEGER,
sql TEXT
);
查询table,type 段是’table’,name段是table的名字, so:
select name from sqlite_master where type='table' order by name;
查询indices,type段是’index’, name 是index的名字,tbl_name是index所拥有的table的名字
2.describe table
两种方法
1.
cursor.execute("PRAGMA table_info(tablename)")
print cursor.fetchall()
2.
from sqlite3 import dbapi2 as sqlite
cur.execute("SELECT * FROM SomeTable")
col_name_list = [tuple[0] for tuple in cur.description]