1 .\" $NetBSD: sqlite3.1,v 1.5 2012/12/21 19:26:39 njoly Exp $
7 .Nd A command line interface for SQLite version 3
15 is a terminal-based front-end to the SQLite library that can evaluate
16 queries interactively and display the results in multiple formats.
18 can also be used within shell scripts and other applications to provide
19 batch processing features.
23 interactive session, invoke the
25 command and optionally provide the name of a database file.
26 If the database file does not exist, it will be created.
27 If the database file does exist, it will be opened.
29 For example, to create a new database file named "mydata.db", create
30 a table named "memos" and insert a couple of records into that table:
31 .Bd -literal -offset indent
34 Enter ".help" for instructions
35 sqlite> create table memos(text, priority INTEGER);
36 sqlite> insert into memos values('deliver project description', 10);
37 sqlite> insert into memos values('lunch with Christine', 100);
38 sqlite> select * from memos;
39 deliver project description|10
40 lunch with Christine|100
44 If no database name is supplied, the
46 sql command can be used
47 to attach to existing or create new database files.
49 can also be used to attach to multiple databases within the same
51 This is useful for migrating data between databases,
52 possibly changing the schema along the way.
54 Optionally, a SQL statement or set of SQL statements can be supplied as
56 Multiple statements should be separated by semi-colons.
59 .Bd -literal -offset indent
60 $ sqlite3 -line mydata.db 'select * from memos where priority > 20;'
61 text = lunch with Christine
64 .Ss SQLITE META-COMMANDS
65 The interactive interpreter offers a set of meta-commands that can be
66 used to control the output format, examine the currently attached
67 database files, or perform administrative operations upon the
68 attached databases (such as rebuilding indices).
69 Meta-commands are always prefixed with a dot
72 A list of available meta-commands can be viewed at any time by issuing
75 .Bd -literal -offset indent
77 \&.databases List names and files of attached databases
78 \&.dump ?TABLE? ... Dump the database in an SQL text format
79 \&.echo ON|OFF Turn command echo on or off
80 \&.exit Exit this program
81 \&.explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
82 \&.header(s) ON|OFF Turn display of headers on or off
83 \&.help Show this message
84 \&.import FILE TABLE Import data from FILE into TABLE
85 \&.indices TABLE Show names of all indices on TABLE
86 \&.mode MODE ?TABLE? Set output mode where MODE is one of:
87 csv Comma-separated values
88 column Left-aligned columns. (See .width)
89 html HTML <table> code
90 insert SQL insert statements for TABLE
91 line One value per line
92 list Values delimited by .separator string
93 tabs Tab-separated values
95 \&.nullvalue STRING Print STRING in place of NULL values
96 \&.output FILENAME Send output to FILENAME
97 \&.output stdout Send output to the screen
98 \&.prompt MAIN CONTINUE Replace the standard prompts
99 \&.quit Exit this program
100 \&.read FILENAME Execute SQL in FILENAME
101 \&.schema ?TABLE? Show the CREATE statements
102 \&.separator STRING Change separator used by output mode and .import
103 \&.show Show the current values for various settings
104 \&.tables ?PATTERN? List names of tables matching a LIKE pattern
105 \&.timeout MS Try opening locked tables for MS milliseconds
106 \&.width NUM NUM ... Set column widths for "column" mode
111 has the following options:
112 .Bl -tag -width abcdefghij
114 Read and execute commands from
116 which can contain a mix of SQL statements and meta-commands.
118 Print commands before execution.
124 Query results will be displayed in a table like form, using
125 whitespace characters to separate the columns and align the
128 Query results will be output as simple HTML tables.
130 Query results will be displayed with one value per line, rows
131 separated by a blank line.
132 Designed to be easily parsed by scripts or other programs
134 Query results will be displayed with the separator (|, by default)
135 character between each field value.
136 .It Fl separator Ar separator
137 Set output field separator.
140 .It Fl nullvalue Ar string
152 Show help on options and exit.
156 reads an initialization file to set the configuration of the
157 interactive environment.
158 Throughout initialization, any previously specified setting can be overridden.
159 The sequence of initialization is as follows:
162 The default configuration is established as follows:
163 .Bd -literal -offset indent
166 main prompt = "sqlite> "
167 continue prompt = " ...> "
172 exists, it is processed first.
173 can be found in the user's home directory, it is
175 It should generally only contain meta-commands.
179 option is present, the specified file is processed.
181 All other command line options are processed.
184 .Lk http://www.sqlite.org/
186 This manual page was originally written by Andreas Rottmann
187 .Aq rotty@debian.org ,
188 for the Debian GNU/Linux system (but may be used by others).
189 It was subsequently revised by Bill Bumgarner