你可以用一点脚本来做到这一点。假设我的数据库结构是:
CREATE TABLE a (personID text, name text);
CREATE TABLE b (personID text, address text);
以下 shell 命令将按计数聚合列名(将 foo.sqlite 替换为您的数据库文件):
sqlite3 foo.sqlite "select name from sqlite_master where type = 'table'" | while read tableName; do sqlite3 foo.sqlite "pragma table_info($tableName)"; done | awk -F\| '{print $2}' | sort | uniq -c
给出输出:
1 address
1 name
2 personID
以下是它正在做的逐步分解:
打印所有表的名称 - 每行一个
sqlite3 foo.sqlite "select name from sqlite_master where type = 'table'"
Output
a
b
读取每个表名,并执行PRAGMA table_name()
打印出表模式:
while read tableName; do sqlite3 foo.sqlite "pragma table_info($tableName)"; done
Output
0|personID|text|0||0
1|name|text|0||0
0|personID|text|0||0
1|address|text|0||0
用作|
分隔符并抓取第二列:
awk -F\| '{print $2}'
Output
personID
name
personID
address
对结果进行排序:
sort
Output
address
name
personID
personID
合并唯一结果,-c 显示出现的项目数。
uniq -c
Output
1 address
1 name
2 personID