遇有未知結(jié)構(gòu)的數(shù)據(jù)庫時(shí),可以通過以下方法來或許數(shù)據(jù)庫中詳細(xì)信息。
1. .table命令 可以查詢當(dāng)前數(shù)據(jù)庫中所有的表名
2. select * from sqlite_master WHERE type = "table"; 可以查詢到當(dāng)前數(shù)據(jù)庫中所有表的詳細(xì)結(jié)構(gòu)信息
[test@localhost ~]$ sqlite3 py.db
SQLite version 3.6.17
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .table
py_phrase py_pinyin py_shengmu
sqlite> select * from sqlite_master WHERE type = "table";
table|py_pinyin|py_pinyin|2|CREATE TABLE py_pinyin (pinyin TEXT PREMARY KEY)
table|py_shengmu|py_shengmu|3|CREATE TABLE py_shengmu (shengmu TEXT PREMARY KEY)
table|py_phrase|py_phrase|4|CREATE TABLE py_phrase (
ylen INTEGER,
y0 INTEGER, y1 INTEGER, y2 INTEGER, y3 INTEGER, yx TEXT,
s0 INTEGER, s1 INTEGER, s2 INTEGER, s3 INTEGER,
phrase TEXT,
freq INTEGER, user_freq INTEGER)
sqlite>
1)創(chuàng)建數(shù)據(jù)庫文件:
>SQLite3 d:\test.db 回車
就生成了一個(gè)test.db在d盤。
這樣同時(shí)也SQLite3掛上了這個(gè)test.db
2)
用.help可以看看有什么命令
>.help 回車即可
3)可以在這里直接輸入SQL語句創(chuàng)建表格 用;結(jié)束,然后回車就可以看到了
4)看看有創(chuàng)建了多少表
>.tables
5)看表結(jié)構(gòu)
>.schema 表名
6)看看目前掛的數(shù)據(jù)庫
>.database
7)如果要把查詢輸出到文件
>.output 文件名
> 查詢語句;
查詢結(jié)果就輸出到了文件c:\query.txt
把查詢結(jié)果用屏幕輸出
>.output stdout
8)把表結(jié)構(gòu)輸出,同時(shí)索引也會(huì)輸出
.dump 表名
9)退出
>.exit 或者.quit
普通SQL操作,通用標(biāo)準(zhǔn)SQL語句。