sqlite3.1 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. .\" Hey, EMACS: -*- nroff -*-
  2. .\" First parameter, NAME, should be all caps
  3. .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
  4. .\" other parameters are allowed: see man(7), man(1)
  5. .TH SQLITE3 1 "Fri Oct 31 10:41:31 EDT 2014"
  6. .\" Please adjust this date whenever revising the manpage.
  7. .\"
  8. .\" Some roff macros, for reference:
  9. .\" .nh disable hyphenation
  10. .\" .hy enable hyphenation
  11. .\" .ad l left justify
  12. .\" .ad b justify to both left and right margins
  13. .\" .nf disable filling
  14. .\" .fi enable filling
  15. .\" .br insert line break
  16. .\" .sp <n> insert n+1 empty lines
  17. .\" for manpage-specific macros, see man(7)
  18. .SH NAME
  19. .B sqlite3
  20. \- A command line interface for SQLite version 3
  21. .SH SYNOPSIS
  22. .B sqlite3
  23. .RI [ options ]
  24. .RI [ databasefile ]
  25. .RI [ SQL ]
  26. .SH SUMMARY
  27. .PP
  28. .B sqlite3
  29. is a terminal-based front-end to the SQLite library that can evaluate
  30. queries interactively and display the results in multiple formats.
  31. .B sqlite3
  32. can also be used within shell scripts and other applications to provide
  33. batch processing features.
  34. .SH DESCRIPTION
  35. To start a
  36. .B sqlite3
  37. interactive session, invoke the
  38. .B sqlite3
  39. command and optionally provide the name of a database file. If the
  40. database file does not exist, it will be created. If the database file
  41. does exist, it will be opened.
  42. For example, to create a new database file named "mydata.db", create
  43. a table named "memos" and insert a couple of records into that table:
  44. .sp
  45. $
  46. .B sqlite3 mydata.db
  47. .br
  48. SQLite version 3.8.8
  49. .br
  50. Enter ".help" for instructions
  51. .br
  52. sqlite>
  53. .B create table memos(text, priority INTEGER);
  54. .br
  55. sqlite>
  56. .B insert into memos values('deliver project description', 10);
  57. .br
  58. sqlite>
  59. .B insert into memos values('lunch with Christine', 100);
  60. .br
  61. sqlite>
  62. .B select * from memos;
  63. .br
  64. deliver project description|10
  65. .br
  66. lunch with Christine|100
  67. .br
  68. sqlite>
  69. .sp
  70. If no database name is supplied, the ATTACH sql command can be used
  71. to attach to existing or create new database files. ATTACH can also
  72. be used to attach to multiple databases within the same interactive
  73. session. This is useful for migrating data between databases,
  74. possibly changing the schema along the way.
  75. Optionally, a SQL statement or set of SQL statements can be supplied as
  76. a single argument. Multiple statements should be separated by
  77. semi-colons.
  78. For example:
  79. .sp
  80. $
  81. .B sqlite3 -line mydata.db 'select * from memos where priority > 20;'
  82. .br
  83. text = lunch with Christine
  84. .br
  85. priority = 100
  86. .br
  87. .sp
  88. .SS SQLITE META-COMMANDS
  89. .PP
  90. The interactive interpreter offers a set of meta-commands that can be
  91. used to control the output format, examine the currently attached
  92. database files, or perform administrative operations upon the
  93. attached databases (such as rebuilding indices). Meta-commands are
  94. always prefixed with a dot (.).
  95. A list of available meta-commands can be viewed at any time by issuing
  96. the '.help' command. For example:
  97. .sp
  98. sqlite>
  99. .B .help
  100. .nf
  101. .tr %.
  102. %backup ?DB? FILE Backup DB (default "main") to FILE
  103. %bail on|off Stop after hitting an error. Default OFF
  104. %clone NEWDB Clone data into NEWDB from the existing database
  105. %databases List names and files of attached databases
  106. %dump ?TABLE? ... Dump the database in an SQL text format
  107. If TABLE specified, only dump tables matching
  108. LIKE pattern TABLE.
  109. %echo on|off Turn command echo on or off
  110. %eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN
  111. %exit Exit this program
  112. %explain ?on|off? Turn output mode suitable for EXPLAIN on or off.
  113. With no args, it turns EXPLAIN on.
  114. %fullschema Show schema and the content of sqlite_stat tables
  115. %headers on|off Turn display of headers on or off
  116. %help Show this message
  117. %import FILE TABLE Import data from FILE into TABLE
  118. %indices ?TABLE? Show names of all indices
  119. If TABLE specified, only show indices for tables
  120. matching LIKE pattern TABLE.
  121. %load FILE ?ENTRY? Load an extension library
  122. %log FILE|off Turn logging on or off. FILE can be stderr/stdout
  123. %mode MODE ?TABLE? Set output mode where MODE is one of:
  124. csv Comma-separated values
  125. column Left-aligned columns. (See .width)
  126. html HTML <table> code
  127. insert SQL insert statements for TABLE
  128. line One value per line
  129. list Values delimited by .separator string
  130. tabs Tab-separated values
  131. tcl TCL list elements
  132. %nullvalue STRING Use STRING in place of NULL values
  133. %once FILENAME Output for the next SQL command only to FILENAME
  134. %open ?FILENAME? Close existing database and reopen FILENAME
  135. %output ?FILENAME? Send output to FILENAME or stdout
  136. %print STRING... Print literal STRING
  137. %prompt MAIN CONTINUE Replace the standard prompts
  138. %quit Exit this program
  139. %read FILENAME Execute SQL in FILENAME
  140. %restore ?DB? FILE Restore content of DB (default "main") from FILE
  141. %save FILE Write in-memory database into FILE
  142. %schema ?TABLE? Show the CREATE statements
  143. If TABLE specified, only show tables matching
  144. LIKE pattern TABLE.
  145. %separator STRING ?NL? Change separator used by output mode and .import
  146. NL is the end-of-line mark for CSV
  147. %shell CMD ARGS... Run CMD ARGS... in a system shell
  148. %show Show the current values for various settings
  149. %stats on|off Turn stats on or off
  150. %system CMD ARGS... Run CMD ARGS... in a system shell
  151. %tables ?TABLE? List names of tables
  152. If TABLE specified, only list tables matching
  153. LIKE pattern TABLE.
  154. %timeout MS Try opening locked tables for MS milliseconds
  155. %timer on|off Turn SQL timer on or off
  156. %trace FILE|off Output each SQL statement as it is run
  157. %vfsname ?AUX? Print the name of the VFS stack
  158. %width NUM1 NUM2 ... Set column widths for "column" mode
  159. Negative values right-justify
  160. sqlite>
  161. .sp
  162. .fi
  163. .SH OPTIONS
  164. .B sqlite3
  165. has the following options:
  166. .TP
  167. .B \-bail
  168. Stop after hitting an error.
  169. .TP
  170. .B \-batch
  171. Force batch I/O.
  172. .TP
  173. .B \-column
  174. Query results will be displayed in a table like form, using
  175. whitespace characters to separate the columns and align the
  176. output.
  177. .TP
  178. .BI \-cmd\ command
  179. run
  180. .I command
  181. before reading stdin
  182. .TP
  183. .B \-csv
  184. Set output mode to CSV (comma separated values).
  185. .TP
  186. .B \-echo
  187. Print commands before execution.
  188. .TP
  189. .BI \-init\ file
  190. Read and execute commands from
  191. .I file
  192. , which can contain a mix of SQL statements and meta-commands.
  193. .TP
  194. .B \-[no]header
  195. Turn headers on or off.
  196. .TP
  197. .B \-help
  198. Show help on options and exit.
  199. .TP
  200. .B \-html
  201. Query results will be output as simple HTML tables.
  202. .TP
  203. .B \-interactive
  204. Force interactive I/O.
  205. .TP
  206. .B \-line
  207. Query results will be displayed with one value per line, rows
  208. separated by a blank line. Designed to be easily parsed by
  209. scripts or other programs
  210. .TP
  211. .B \-list
  212. Query results will be displayed with the separator (|, by default)
  213. character between each field value. The default.
  214. .TP
  215. .BI \-mmap\ N
  216. Set default mmap size to
  217. .I N
  218. \.
  219. .TP
  220. .BI \-nullvalue\ string
  221. Set string used to represent NULL values. Default is ''
  222. (empty string).
  223. .TP
  224. .BI \-separator\ separator
  225. Set output field separator. Default is '|'.
  226. .TP
  227. .B \-stats
  228. Print memory stats before each finalize.
  229. .TP
  230. .B \-version
  231. Show SQLite version.
  232. .TP
  233. .BI \-vfs\ name
  234. Use
  235. .I name
  236. as the default VFS.
  237. .SH INIT FILE
  238. .B sqlite3
  239. reads an initialization file to set the configuration of the
  240. interactive environment. Throughout initialization, any previously
  241. specified setting can be overridden. The sequence of initialization is
  242. as follows:
  243. o The default configuration is established as follows:
  244. .sp
  245. .nf
  246. .cc |
  247. mode = LIST
  248. separator = "|"
  249. main prompt = "sqlite> "
  250. continue prompt = " ...> "
  251. |cc .
  252. .sp
  253. .fi
  254. o If the file
  255. .B ~/.sqliterc
  256. exists, it is processed first.
  257. can be found in the user's home directory, it is
  258. read and processed. It should generally only contain meta-commands.
  259. o If the -init option is present, the specified file is processed.
  260. o All other command line options are processed.
  261. .SH SEE ALSO
  262. http://www.sqlite.org/cli.html
  263. .br
  264. The sqlite3-doc package.
  265. .SH AUTHOR
  266. This manual page was originally written by Andreas Rottmann
  267. <rotty@debian.org>, for the Debian GNU/Linux system (but may be used
  268. by others). It was subsequently revised by Bill Bumgarner <bbum@mac.com> and
  269. further updated by Laszlo Boszormenyi <gcs@debian.hu> .