SQLite 命令
让我们在命令提示符下键入一个简单的 **sqlite3** 命令,在 SQLite 命令提示符下,您可以使用各种 SQLite 命令。
C:\Users\keti>sqlite3
SQLite version 3.46.1 2024-08-13 09:16:08 (UTF-16 console I/O)
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
如需获取可用的点命令的清单,可以在任何时候输入 ".help"。例如:
sqlite> .help
.archive ... Manage SQL archives
.auth ON|OFF Show authorizer callbacks
# 备份 DB 数据库(默认是 "main")到 FILE 文件。
.backup ?DB? FILE Backup DB (default "main") to FILE
# 发生错误后停止。默认为 OFF。
.bail on|off Stop after hitting an error. Default OFF
.cd DIRECTORY Change the working directory to DIRECTORY
.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
.connection [close] [#] Open or close an auxiliary database connection
.crnl on|off Translate \n to \r\n. Default ON
# 列出数据库的名称及其所依附的文件。
.databases List names and files of attached databases
.dbconfig ?op? ?val? List or change sqlite3_db_config() options
.dbinfo ?DB? Show status information about the database
.dump ?OBJECTS? Render database content as SQL
# 开启或关闭 echo 命令。
.echo on|off Turn command echo on or off
.eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN
.excel Display the output of next command in spreadsheet
# 退出 SQLite 提示符。
.exit ?CODE? Exit this program with return-code CODE
.expert EXPERIMENTAL. Suggest indexes for queries
# 开启或关闭适合于 EXPLAIN 的输出模式。如果没有带参数,则为 EXPLAIN on,即开启 EXPLAIN。
.explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto
.filectrl CMD ... Run various sqlite3_file_control() operations
.fullschema ?--indent? Show schema and the content of sqlite_stat tables
# 开启或关闭头部显示。
.headers on|off Turn display of headers on or off
.help ?-all? ?PATTERN? Show help text for PATTERN
# 导入来自 FILE 文件的数据到 TABLE 表中。
.import FILE TABLE Import data from FILE into TABLE
# 显示所有索引的名称。如果指定了 TABLE 表,则只显示匹配 LIKE 模式的 TABLE 表的索引。
.indexes ?TABLE? Show names of indexes
.intck ?STEPS_PER_UNLOCK? Run an incremental integrity check on the db
.limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT
.lint OPTIONS Report potential schema issues.
# 加载一个扩展库。
.load FILE ?ENTRY? Load an extension library
# 开启或关闭日志。FILE 文件可以是 stderr(标准错误)/stdout(标准输出)。
.log FILE|on|off Turn logging on or off. FILE can be stderr/stdout
# 设置输出模式
.mode MODE ?OPTIONS? Set output mode
.nonce STRING Suspend safe mode for one command if nonce matches
# 在 NULL 值的地方输出 STRING 字符串。
.nullvalue STRING Use STRING in place of NULL values
.once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE
.open ?OPTIONS? ?FILE? Close existing database and reopen FILE
# 发送输出到 FILENAME 文件。
.output ?FILE? Send output to FILE or stdout if FILE is omitted
.parameter CMD ... Manage SQL parameter bindings
.print STRING... Print literal STRING
.progress N Invoke progress handler after every N opcodes
.prompt MAIN CONTINUE Replace the standard prompts
.quit Stop interpreting input stream, exit if primary.
.read FILE Read input from FILE or command output
.recover Recover as much data as possible from corrupt db.
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)
.scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off
.schema ?PATTERN? Show the CREATE statements matching PATTERN
.separator COL ?ROW? Change the column and row separators
.session ?NAME? CMD ... Create or control sessions
.sha3sum ... 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 ?ARG? Show stats or turn stats on or off
.system CMD ARGS... Run CMD ARGS... in a system shell
.tables ?TABLE? List names of tables matching LIKE pattern TABLE
.timeout MS Try opening locked tables for MS milliseconds
.timer on|off Turn SQL timer on or off
.trace ?OPTIONS? Output each SQL statement as it is run
.version Show source, library and compiler versions
.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 minimum column widths for columnar output
sqlite>
让我们尝试使用 **.show** 命令,来查看 SQLite 命令提示符的默认设置。
sqlite> .show
echo: off
eqp: off
explain: auto
headers: off
mode: list
nullvalue: ""
output: stdout
colseparator: "|"
rowseparator: "\n"
stats: off
width:
filename: :memory:
sqlite>
确保 sqlite> 提示符与点命令之间没有空格,否则将无法正常工作。