天天看點

SQLite 指令(http://www.w3cschool.cc/sqlite/sqlite-commands.html)SQLite 指令

本章将向您講解 sqlite 程式設計人員所使用的簡單卻有用的指令。些指令被稱為 sqlite 的點指令,這些指令的不同之處在于它們不以分号(;)結束。

讓我們在指令提示符下鍵入一個簡單的 sqlite3 指令,在 sqlite 指令提示符下,您可以使用各種 sqlite 指令。

如需擷取可用的點指令的清單,可以在任何時候輸入 ".help"。例如:

上面的指令會顯示各種重要的 sqlite 點指令的清單,如下所示:

指令

描述

.backup ?db? file

備份 db 資料庫(預設是 "main")到 file 檔案。

.bail on|off

發生錯誤後停止。預設為 off。

.databases

列出附加資料庫的名稱和檔案。

.dump ?table?

以 sql 文本格式轉儲資料庫。如果指定了 table 表,則隻轉儲比對 like 模式的 table 表。

.echo on|off

開啟或關閉 echo 指令。

.exit

退出 sqlite 提示符。

.explain on|off

開啟或關閉适合于 explain 的輸出模式。如果沒有帶參數,則為 explain on,及開啟 explain。

.header(s) on|off

開啟或關閉頭部顯示。

.help

顯示消息。

.import file table

導入來自 file 檔案的資料到 table 表中。

.indices ?table?

顯示所有索引的名稱。如果指定了 table 表,則隻顯示比對 like 模式的 table 表的索引。

.load file ?entry?

加載一個擴充庫。

.log file|off

開啟或關閉日志。file 檔案可以是 stderr(标準錯誤)/stdout(标準輸出)。

.mode mode

設定輸出模式,mode 可以是下列之一:

csv 逗号分隔的值

column 左對齊的列

html html 的 <table> 代碼

insert table 表的 sql 插入(insert)語句

line 每行一個值

list 由 .separator 字元串分隔的值

tabs 由 tab 分隔的值

tcl tcl 清單元素

.nullvalue string

在 null 值的地方輸出 string 字元串。

.output filename

發送輸出到 filename 檔案。

.output stdout

發送輸出到螢幕。

.print string...

逐字地輸出 string 字元串。

.prompt main continue

替換标準提示符。

.quit

.read filename

執行 filename 檔案中的 sql。

.schema ?table?

顯示 create 語句。如果指定了 table 表,則隻顯示比對 like 模式的 table 表。

.separator string

改變輸出模式和 .import 所使用的分隔符。

.show

顯示各種設定的目前值。

.stats on|off

開啟或關閉統計。

.tables ?pattern?

列出比對 like 模式的表的名稱。

.timeout ms

嘗試打開鎖定的表 ms 微秒。

.width num num

為 "column" 模式設定列寬度。

.timer on|off

開啟或關閉 cpu 定時器測量。

讓我們嘗試使用 .show 指令,來檢視 sqlite 指令提示符的預設設定。

確定 sqlite> 提示符與點指令之間沒有空格,否則将無法正常工作。

您可以使用下列的點指令來格式化輸出為本教程下面所列出的格式:

上面設定将産生如下格式的輸出:

主表中儲存資料庫表的關鍵資訊,并把它命名為 sqlite_master。如要檢視表概要,可按如下操作:

這将産生如下結果: