blob: 02df7f44c7528e99bd139f7e8c10d0ef829f833b [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)
drhd49c5452014-01-31 11:50:20 +00005.TH SQLITE3 1 "Mon Jan 31 11:14:00 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
drhd49c5452014-01-31 11:50:20 +000052SQLite version 3.8.3
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
110.cc |
drhd49c5452014-01-31 11:50:20 +0000111.backup ?DB? FILE Backup DB (default "main") to FILE
112.bail ON|OFF Stop after hitting an error. Default OFF
drh75308732005-02-24 04:51:51 +0000113.databases List names and files of attached databases
114.dump ?TABLE? ... Dump the database in an SQL text format
drhd49c5452014-01-31 11:50:20 +0000115 If TABLE specified, only dump tables matching
116 LIKE pattern TABLE.
persicom45698a32002-04-18 02:53:54 +0000117.echo ON|OFF Turn command echo on or off
drh3a88fbd2002-01-07 19:58:43 +0000118.exit Exit this program
drhd49c5452014-01-31 11:50:20 +0000119.explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.
120 With no args, it turns EXPLAIN on.
persicom45698a32002-04-18 02:53:54 +0000121.header(s) ON|OFF Turn display of headers on or off
drh3a88fbd2002-01-07 19:58:43 +0000122.help Show this message
drh75308732005-02-24 04:51:51 +0000123.import FILE TABLE Import data from FILE into TABLE
drhd49c5452014-01-31 11:50:20 +0000124.indices ?TABLE? Show names of all indices
125 If TABLE specified, only show indices for tables
126 matching LIKE pattern TABLE.
127.load FILE ?ENTRY? Load an extension library
128.log FILE|off Turn logging on or off. FILE can be stderr/stdout
drh75308732005-02-24 04:51:51 +0000129.mode MODE ?TABLE? Set output mode where MODE is one of:
130 csv Comma-separated values
131 column Left-aligned columns. (See .width)
132 html HTML <table> code
133 insert SQL insert statements for TABLE
134 line One value per line
135 list Values delimited by .separator string
136 tabs Tab-separated values
137 tcl TCL list elements
drhd49c5452014-01-31 11:50:20 +0000138.nullvalue STRING Use STRING in place of NULL values
139.open ?FILENAME? Close existing database and reopen FILENAME
drh3a88fbd2002-01-07 19:58:43 +0000140.output FILENAME Send output to FILENAME
141.output stdout Send output to the screen
drhd49c5452014-01-31 11:50:20 +0000142.print STRING... Print literal STRING
persicom45698a32002-04-18 02:53:54 +0000143.prompt MAIN CONTINUE Replace the standard prompts
persicom45698a32002-04-18 02:53:54 +0000144.quit Exit this program
145.read FILENAME Execute SQL in FILENAME
drhd49c5452014-01-31 11:50:20 +0000146.restore ?DB? FILE Restore content of DB (default "main") from FILE
drh3a88fbd2002-01-07 19:58:43 +0000147.schema ?TABLE? Show the CREATE statements
drhd49c5452014-01-31 11:50:20 +0000148 If TABLE specified, only show tables matching
149 LIKE pattern TABLE.
drh75308732005-02-24 04:51:51 +0000150.separator STRING Change separator used by output mode and .import
151.show Show the current values for various settings
drhd49c5452014-01-31 11:50:20 +0000152.stats ON|OFF Turn stats on or off
153.tables ?TABLE? List names of tables
154 If TABLE specified, only list tables matching
155 LIKE pattern TABLE.
drh3a88fbd2002-01-07 19:58:43 +0000156.timeout MS Try opening locked tables for MS milliseconds
drhd49c5452014-01-31 11:50:20 +0000157.trace FILE|off Output each SQL statement as it is run
158.vfsname ?AUX? Print the name of the VFS stack
159.width NUM1 NUM2 ... Set column widths for "column" mode
160.timer ON|OFF Turn the CPU timer measurement on or off
drh3a88fbd2002-01-07 19:58:43 +0000161sqlite>
162|cc .
163.sp
164.fi
drh3a88fbd2002-01-07 19:58:43 +0000165.SH OPTIONS
drh75308732005-02-24 04:51:51 +0000166.B sqlite3
167has the following options:
drh3a88fbd2002-01-07 19:58:43 +0000168.TP
drhd49c5452014-01-31 11:50:20 +0000169.B \-bail
170Stop after hitting an error.
persicom45698a32002-04-18 02:53:54 +0000171.TP
drhd49c5452014-01-31 11:50:20 +0000172.B \-batch
173Force batch I/O.
drh75308732005-02-24 04:51:51 +0000174.TP
175.B \-column
176Query results will be displayed in a table like form, using
177whitespace characters to separate the columns and align the
178output.
179.TP
drhd49c5452014-01-31 11:50:20 +0000180.BI \-cmd\ command
181run
182.I command
183before reading stdin
184.TP
185.B \-csv
186Set output mode to CSV (comma separated values).
187.TP
188.B \-echo
189Print commands before execution.
190.TP
191.BI \-init\ file
192Read and execute commands from
193.I file
194, which can contain a mix of SQL statements and meta-commands.
195.TP
196.B \-[no]header
197Turn headers on or off.
198.TP
199.B \-help
200Show help on options and exit.
201.TP
drh75308732005-02-24 04:51:51 +0000202.B \-html
203Query results will be output as simple HTML tables.
204.TP
drhd49c5452014-01-31 11:50:20 +0000205.B \-interactive
206Force interactive I/O.
207.TP
drh75308732005-02-24 04:51:51 +0000208.B \-line
209Query results will be displayed with one value per line, rows
210separated by a blank line. Designed to be easily parsed by
211scripts or other programs
212.TP
213.B \-list
214Query results will be displayed with the separator (|, by default)
215character between each field value. The default.
216.TP
drhd49c5452014-01-31 11:50:20 +0000217.BI \-mmap\ N
218Set default mmap size to
219.I N
220\.
drh75308732005-02-24 04:51:51 +0000221.TP
222.BI \-nullvalue\ string
223Set string used to represent NULL values. Default is ''
224(empty string).
225.TP
drhd49c5452014-01-31 11:50:20 +0000226.BI \-separator\ separator
227Set output field separator. Default is '|'.
228.TP
229.B \-stats
230Print memory stats before each finalize.
231.TP
drh75308732005-02-24 04:51:51 +0000232.B \-version
233Show SQLite version.
234.TP
drhd49c5452014-01-31 11:50:20 +0000235.BI \-vfs\ name
236Use
237.I name
238as the default VFS.
persicom45698a32002-04-18 02:53:54 +0000239
drh3a88fbd2002-01-07 19:58:43 +0000240
persicom45698a32002-04-18 02:53:54 +0000241.SH INIT FILE
drh75308732005-02-24 04:51:51 +0000242.B sqlite3
243reads an initialization file to set the configuration of the
244interactive environment. Throughout initialization, any previously
245specified setting can be overridden. The sequence of initialization is
246as follows:
persicom45698a32002-04-18 02:53:54 +0000247
drh75308732005-02-24 04:51:51 +0000248o The default configuration is established as follows:
persicom45698a32002-04-18 02:53:54 +0000249
250.sp
251.nf
252.cc |
253mode = LIST
254separator = "|"
255main prompt = "sqlite> "
256continue prompt = " ...> "
257|cc .
258.sp
259.fi
260
drh75308732005-02-24 04:51:51 +0000261o If the file
262.B ~/.sqliterc
263exists, it is processed first.
264can be found in the user's home directory, it is
265read and processed. It should generally only contain meta-commands.
persicom45698a32002-04-18 02:53:54 +0000266
drh75308732005-02-24 04:51:51 +0000267o If the -init option is present, the specified file is processed.
persicom45698a32002-04-18 02:53:54 +0000268
drh75308732005-02-24 04:51:51 +0000269o All other command line options are processed.
persicom45698a32002-04-18 02:53:54 +0000270
drh3a88fbd2002-01-07 19:58:43 +0000271.SH SEE ALSO
drh75308732005-02-24 04:51:51 +0000272http://www.sqlite.org/
drh3a88fbd2002-01-07 19:58:43 +0000273.br
drhd49c5452014-01-31 11:50:20 +0000274The sqlite3-doc package.
drh3a88fbd2002-01-07 19:58:43 +0000275.SH AUTHOR
drh0fface62002-05-06 11:34:26 +0000276This manual page was originally written by Andreas Rottmann
277<rotty@debian.org>, for the Debian GNU/Linux system (but may be used
drhd49c5452014-01-31 11:50:20 +0000278by others). It was subsequently revised by Bill Bumgarner <bbum@mac.com> and
279further updated by Laszlo Boszormenyi <gcs@debian.hu> .