blob: 80353b0eecd9848204c711d6264ca116b2d1064b [file] [log] [blame]
drh3a88fbd2002-01-07 19:58:43 +00001.\" 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)
drh0fb5dae2014-10-31 14:46:51 +00005.TH SQLITE3 1 "Fri Oct 31 10:41:31 EDT 2014"
drh3a88fbd2002-01-07 19:58:43 +00006.\" 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
drh75308732005-02-24 04:51:51 +000019.B sqlite3
20\- A command line interface for SQLite version 3
21
drh3a88fbd2002-01-07 19:58:43 +000022.SH SYNOPSIS
drh75308732005-02-24 04:51:51 +000023.B sqlite3
24.RI [ options ]
25.RI [ databasefile ]
26.RI [ SQL ]
27
28.SH SUMMARY
drh3a88fbd2002-01-07 19:58:43 +000029.PP
drh75308732005-02-24 04:51:51 +000030.B sqlite3
31is a terminal-based front-end to the SQLite library that can evaluate
32queries interactively and display the results in multiple formats.
33.B sqlite3
34can also be used within shell scripts and other applications to provide
35batch processing features.
drh3a88fbd2002-01-07 19:58:43 +000036
37.SH DESCRIPTION
drh75308732005-02-24 04:51:51 +000038To start a
39.B sqlite3
40interactive session, invoke the
41.B sqlite3
42command and optionally provide the name of a database file. If the
43database file does not exist, it will be created. If the database file
44does exist, it will be opened.
drh3a88fbd2002-01-07 19:58:43 +000045
drh75308732005-02-24 04:51:51 +000046For example, to create a new database file named "mydata.db", create
47a table named "memos" and insert a couple of records into that table:
drh3a88fbd2002-01-07 19:58:43 +000048.sp
drh75308732005-02-24 04:51:51 +000049$
50.B sqlite3 mydata.db
51.br
drh0fb5dae2014-10-31 14:46:51 +000052SQLite version 3.8.8
drh75308732005-02-24 04:51:51 +000053.br
drh3a88fbd2002-01-07 19:58:43 +000054Enter ".help" for instructions
drh75308732005-02-24 04:51:51 +000055.br
56sqlite>
57.B create table memos(text, priority INTEGER);
58.br
59sqlite>
60.B insert into memos values('deliver project description', 10);
61.br
62sqlite>
63.B insert into memos values('lunch with Christine', 100);
64.br
65sqlite>
66.B select * from memos;
67.br
68deliver project description|10
69.br
70lunch with Christine|100
71.br
drh3a88fbd2002-01-07 19:58:43 +000072sqlite>
73.sp
drh75308732005-02-24 04:51:51 +000074
75If no database name is supplied, the ATTACH sql command can be used
76to attach to existing or create new database files. ATTACH can also
77be used to attach to multiple databases within the same interactive
78session. This is useful for migrating data between databases,
79possibly changing the schema along the way.
80
81Optionally, a SQL statement or set of SQL statements can be supplied as
82a single argument. Multiple statements should be separated by
83semi-colons.
84
85For example:
86.sp
87$
88.B sqlite3 -line mydata.db 'select * from memos where priority > 20;'
89.br
90 text = lunch with Christine
91.br
92priority = 100
93.br
94.sp
drh3a88fbd2002-01-07 19:58:43 +000095
96.SS SQLITE META-COMMANDS
97.PP
drh75308732005-02-24 04:51:51 +000098The interactive interpreter offers a set of meta-commands that can be
99used to control the output format, examine the currently attached
100database files, or perform administrative operations upon the
101attached databases (such as rebuilding indices). Meta-commands are
102always prefixed with a dot (.).
drh3a88fbd2002-01-07 19:58:43 +0000103
drh75308732005-02-24 04:51:51 +0000104A list of available meta-commands can be viewed at any time by issuing
105the '.help' command. For example:
drh3a88fbd2002-01-07 19:58:43 +0000106.sp
drh75308732005-02-24 04:51:51 +0000107sqlite>
108.B .help
drh3a88fbd2002-01-07 19:58:43 +0000109.nf
drh0fb5dae2014-10-31 14:46:51 +0000110.tr %.
111%backup ?DB? FILE Backup DB (default "main") to FILE
112%bail on|off Stop after hitting an error. Default OFF
113%clone NEWDB Clone data into NEWDB from the existing database
114%databases List names and files of attached databases
115%dump ?TABLE? ... Dump the database in an SQL text format
drhd49c5452014-01-31 11:50:20 +0000116 If TABLE specified, only dump tables matching
117 LIKE pattern TABLE.
drh0fb5dae2014-10-31 14:46:51 +0000118%echo on|off Turn command echo on or off
119%eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN
120%exit Exit this program
121%explain ?on|off? Turn output mode suitable for EXPLAIN on or off.
drhd49c5452014-01-31 11:50:20 +0000122 With no args, it turns EXPLAIN on.
drh0fb5dae2014-10-31 14:46:51 +0000123%fullschema Show schema and the content of sqlite_stat tables
124%headers on|off Turn display of headers on or off
125%help Show this message
126%import FILE TABLE Import data from FILE into TABLE
127%indices ?TABLE? Show names of all indices
drhd49c5452014-01-31 11:50:20 +0000128 If TABLE specified, only show indices for tables
129 matching LIKE pattern TABLE.
drh0fb5dae2014-10-31 14:46:51 +0000130%load FILE ?ENTRY? Load an extension library
131%log FILE|off Turn logging on or off. FILE can be stderr/stdout
132%mode MODE ?TABLE? Set output mode where MODE is one of:
drh75308732005-02-24 04:51:51 +0000133 csv Comma-separated values
134 column Left-aligned columns. (See .width)
135 html HTML <table> code
136 insert SQL insert statements for TABLE
137 line One value per line
138 list Values delimited by .separator string
139 tabs Tab-separated values
140 tcl TCL list elements
drh0fb5dae2014-10-31 14:46:51 +0000141%nullvalue STRING Use STRING in place of NULL values
142%once FILENAME Output for the next SQL command only to FILENAME
143%open ?FILENAME? Close existing database and reopen FILENAME
144%output ?FILENAME? Send output to FILENAME or stdout
145%print STRING... Print literal STRING
146%prompt MAIN CONTINUE Replace the standard prompts
147%quit Exit this program
148%read FILENAME Execute SQL in FILENAME
149%restore ?DB? FILE Restore content of DB (default "main") from FILE
150%save FILE Write in-memory database into FILE
151%schema ?TABLE? Show the CREATE statements
drhd49c5452014-01-31 11:50:20 +0000152 If TABLE specified, only show tables matching
153 LIKE pattern TABLE.
drh0fb5dae2014-10-31 14:46:51 +0000154%separator STRING ?NL? Change separator used by output mode and .import
155 NL is the end-of-line mark for CSV
156%shell CMD ARGS... Run CMD ARGS... in a system shell
157%show Show the current values for various settings
158%stats on|off Turn stats on or off
159%system CMD ARGS... Run CMD ARGS... in a system shell
160%tables ?TABLE? List names of tables
drhd49c5452014-01-31 11:50:20 +0000161 If TABLE specified, only list tables matching
162 LIKE pattern TABLE.
drh0fb5dae2014-10-31 14:46:51 +0000163%timeout MS Try opening locked tables for MS milliseconds
164%timer on|off Turn SQL timer on or off
165%trace FILE|off Output each SQL statement as it is run
166%vfsname ?AUX? Print the name of the VFS stack
167%width NUM1 NUM2 ... Set column widths for "column" mode
168 Negative values right-justify
drh3a88fbd2002-01-07 19:58:43 +0000169sqlite>
drh3a88fbd2002-01-07 19:58:43 +0000170.sp
171.fi
drh3a88fbd2002-01-07 19:58:43 +0000172.SH OPTIONS
drh75308732005-02-24 04:51:51 +0000173.B sqlite3
174has the following options:
drh3a88fbd2002-01-07 19:58:43 +0000175.TP
drhd49c5452014-01-31 11:50:20 +0000176.B \-bail
177Stop after hitting an error.
persicom45698a32002-04-18 02:53:54 +0000178.TP
drhd49c5452014-01-31 11:50:20 +0000179.B \-batch
180Force batch I/O.
drh75308732005-02-24 04:51:51 +0000181.TP
182.B \-column
183Query results will be displayed in a table like form, using
184whitespace characters to separate the columns and align the
185output.
186.TP
drhd49c5452014-01-31 11:50:20 +0000187.BI \-cmd\ command
188run
189.I command
190before reading stdin
191.TP
192.B \-csv
193Set output mode to CSV (comma separated values).
194.TP
195.B \-echo
196Print commands before execution.
197.TP
198.BI \-init\ file
199Read and execute commands from
200.I file
201, which can contain a mix of SQL statements and meta-commands.
202.TP
203.B \-[no]header
204Turn headers on or off.
205.TP
206.B \-help
207Show help on options and exit.
208.TP
drh75308732005-02-24 04:51:51 +0000209.B \-html
210Query results will be output as simple HTML tables.
211.TP
drhd49c5452014-01-31 11:50:20 +0000212.B \-interactive
213Force interactive I/O.
214.TP
drh75308732005-02-24 04:51:51 +0000215.B \-line
216Query results will be displayed with one value per line, rows
217separated by a blank line. Designed to be easily parsed by
218scripts or other programs
219.TP
220.B \-list
221Query results will be displayed with the separator (|, by default)
222character between each field value. The default.
223.TP
drhd49c5452014-01-31 11:50:20 +0000224.BI \-mmap\ N
225Set default mmap size to
226.I N
227\.
drh75308732005-02-24 04:51:51 +0000228.TP
229.BI \-nullvalue\ string
230Set string used to represent NULL values. Default is ''
231(empty string).
232.TP
drhd49c5452014-01-31 11:50:20 +0000233.BI \-separator\ separator
234Set output field separator. Default is '|'.
235.TP
236.B \-stats
237Print memory stats before each finalize.
238.TP
drh75308732005-02-24 04:51:51 +0000239.B \-version
240Show SQLite version.
241.TP
drhd49c5452014-01-31 11:50:20 +0000242.BI \-vfs\ name
243Use
244.I name
245as the default VFS.
persicom45698a32002-04-18 02:53:54 +0000246
drh3a88fbd2002-01-07 19:58:43 +0000247
persicom45698a32002-04-18 02:53:54 +0000248.SH INIT FILE
drh75308732005-02-24 04:51:51 +0000249.B sqlite3
250reads an initialization file to set the configuration of the
251interactive environment. Throughout initialization, any previously
252specified setting can be overridden. The sequence of initialization is
253as follows:
persicom45698a32002-04-18 02:53:54 +0000254
drh75308732005-02-24 04:51:51 +0000255o The default configuration is established as follows:
persicom45698a32002-04-18 02:53:54 +0000256
257.sp
258.nf
259.cc |
260mode = LIST
261separator = "|"
262main prompt = "sqlite> "
263continue prompt = " ...> "
264|cc .
265.sp
266.fi
267
drh75308732005-02-24 04:51:51 +0000268o If the file
269.B ~/.sqliterc
270exists, it is processed first.
271can be found in the user's home directory, it is
272read and processed. It should generally only contain meta-commands.
persicom45698a32002-04-18 02:53:54 +0000273
drh75308732005-02-24 04:51:51 +0000274o If the -init option is present, the specified file is processed.
persicom45698a32002-04-18 02:53:54 +0000275
drh75308732005-02-24 04:51:51 +0000276o All other command line options are processed.
persicom45698a32002-04-18 02:53:54 +0000277
drh3a88fbd2002-01-07 19:58:43 +0000278.SH SEE ALSO
drh0fb5dae2014-10-31 14:46:51 +0000279http://www.sqlite.org/cli.html
drh3a88fbd2002-01-07 19:58:43 +0000280.br
drhd49c5452014-01-31 11:50:20 +0000281The sqlite3-doc package.
drh3a88fbd2002-01-07 19:58:43 +0000282.SH AUTHOR
drh0fface62002-05-06 11:34:26 +0000283This manual page was originally written by Andreas Rottmann
284<rotty@debian.org>, for the Debian GNU/Linux system (but may be used
drhd49c5452014-01-31 11:50:20 +0000285by others). It was subsequently revised by Bill Bumgarner <bbum@mac.com> and
286further updated by Laszlo Boszormenyi <gcs@debian.hu> .