SQLite命令與SQL命令類似。 有三種型別的SQLite命令:
資料定義語言中主要有三個命令:
CREATE:此命令用於建立表,資料庫中的表或其他物件的檢視。
ALTER:此命令用於修改現有的資料庫物件,如表。
DROP:DROP
命令用於刪除整個表,資料庫中的表或其他物件的檢視。
資料操作語言中主要有三個命令:
INSERT:此命令用於建立記錄。
UPDATE:用於修改記錄。
DELETE:用於刪除記錄。
以下是SQLite點(.
)命令的列表。 這些命令不會以分號(;
)終止。
.help
可在任何時候使用「.help
」檢查點命令列表。
例如:
QLite version 3.18.0 2017-03-28 18:48:43
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .help
.auth ON|OFF Show authorizer callbacks
.backup ?DB? FILE Backup DB (default "main") to FILE
.bail on|off Stop after hitting an error. Default OFF
.binary on|off Turn binary output on or off. Default OFF
.changes on|off Show number of rows changed by SQL
.check GLOB Fail if output since .testcase does not match
.clone NEWDB Clone data into NEWDB from the existing database
.databases List names and files of attached databases
.dbinfo ?DB? Show status information about the database
.dump ?TABLE? ... Dump the database in an SQL text format
If TABLE specified, only dump tables matching
LIKE pattern TABLE.
.echo on|off Turn command echo on or off
.eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN
.exit Exit this program
.explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic
.fullschema ?--indent? Show schema and the content of sqlite_stat tables
.headers on|off Turn display of headers on or off
.help Show this message
.import FILE TABLE Import data from FILE into TABLE
.imposter INDEX TABLE Create imposter table TABLE on index INDEX
.indexes ?TABLE? Show names of all indexes
If TABLE specified, only show indexes for tables
matching LIKE pattern TABLE.
.limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT
.lint OPTIONS Report potential schema issues. Options:
fkey-indexes Find missing foreign key indexes
.load FILE ?ENTRY? Load an extension library
.log FILE|off Turn logging on or off. FILE can be stderr/stdout
.mode MODE ?TABLE? Set output mode where MODE is one of:
ascii Columns/rows delimited by 0x1F and 0x1E
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML <table> code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by "|"
quote Escape answers as for SQL
tabs Tab-separated values
tcl TCL list elements
.nullvalue STRING Use STRING in place of NULL values
.once FILENAME Output for the next SQL command only to FILENAME
.open ?--new? ?FILE? Close existing database and reopen FILE
The --new starts with an empty file
.output ?FILENAME? Send output to FILENAME or stdout
.print STRING... Print literal STRING
.prompt MAIN CONTINUE Replace the standard prompts
.quit Exit this program
.read FILENAME Execute SQL in FILENAME
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.save FILE Write in-memory database into FILE
.scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off
.schema ?PATTERN? Show the CREATE statements matching PATTERN
Add --indent for pretty-printing
.selftest ?--init? Run tests defined in the SELFTEST table
.separator COL ?ROW? Change the column separator and optionally the row
separator for both the output mode and .import
.sha3sum ?OPTIONS...? Compute a SHA3 hash of database content
.shell CMD ARGS... Run CMD ARGS... in a system shell
.show Show the current values for various settings
.stats ?on|off? Show stats or turn stats on or off
.system CMD ARGS... Run CMD ARGS... in a system shell
.tables ?TABLE? List names of tables
If TABLE specified, only list tables matching
LIKE pattern TABLE.
.testcase NAME Begin redirecting output to 'testcase-out.txt'
.timeout MS Try opening locked tables for MS milliseconds
.timer on|off Turn SQL timer on or off
.trace FILE|off Output each SQL statement as it is run
.vfsinfo ?AUX? Information about the top-level VFS
.vfslist List all available VFSes
.vfsname ?AUX? Print the name of the VFS stack
.width NUM1 NUM2 ... Set column widths for "column" mode
Negative values right-justify
sqlite>
以上是各種SQLite的點(.
)命令的列表。 命令及其描述如下表所示:
命令 | 描述說明 |
---|---|
.backup ?db? file |
備份資料庫(預設「main 」)到檔案中 |
.bail on/off |
遇到錯誤後停止,預設為off |
.databases |
附件資料庫的列表名稱和檔案 |
.dump ?table? |
以sql文字格式轉儲資料庫。如果指定表,則只轉儲表匹配像模式表。 |
.echo on/off |
開啟或關閉echo 命令 |
.exit |
退出sqlite 提示符 |
.explain on/off |
轉向輸出模式適合說明on/off 。如沒有參引數,則它為on 。 |
.header(s) on/off |
開啟或關閉標題的顯示 |
.help |
顯示指定幫助訊息 |
.import file table |
將資料從檔案匯入表 |
.indices ?table? |
顯示所有索引的名稱。如果指定表,則只顯示匹配的表的索引,如模式表。 |
.load file ?entry? |
載入擴充套件庫 |
.log file/off |
開啟或關閉紀錄檔記錄。檔案可以是stderr/stdout |
.mode mode |
設定輸出模式 |
.nullvalue string |
列印字串代替空值 |
.output filename |
傳送輸出到檔案名 |
.output stdout |
傳送輸出到螢幕 |
.print string... |
列印文字字串 |
.prompt main continue |
替換標準提示 |
.quit |
退出sqlite 提示符 |
.read filename |
在檔案名中執行sql |
.schema ?table? |
顯示建立語句。如果指定表,則只顯示與模式表匹配的錶。 |
.separator string |
更改分隔符由輸出模式和.import 使用 |
.show |
顯示各種設定的當前值 |
.stats on/off |
開啟或關閉統計資訊 |
.tables ?pattern? |
列出匹配類似模式的表的名稱 |
.timeout ms |
嘗試開啟鎖定的表毫秒 |
.width num num |
設定「列」模式的列寬 |
.timer on/off |
開啟或關閉cpu定時器測量 |
.show命令
可以使用.show
命令檢視SQLite命令提示字元的預設設定。
注意:不要在
sqlite>
提示符和.
命令之間放置空格,否則將不起作用。
其它特殊點命令
有一些點(.
)命令用於格式化輸出。這些命令是:
.header on
.mode column
.timer on