1SQLITE3(1) General Commands Manual SQLITE3(1)
2
3
4
6 sqlite3 - A command line interface for SQLite version 3
7
8
10 sqlite3 [options] [databasefile] [SQL]
11
12
14 sqlite3 is a terminal-based front-end to the SQLite library that can
15 evaluate queries interactively and display the results in multiple for‐
16 mats. sqlite3 can also be used within shell scripts and other applica‐
17 tions to provide batch processing features.
18
19
21 To start a sqlite3 interactive session, invoke the sqlite3 command and
22 optionally provide the name of a database file. If the database file
23 does not exist, it will be created. If the database file does exist,
24 it will be opened.
25
26 For example, to create a new database file named "mydata.db", create a
27 table named "memos" and insert a couple of records into that table:
28
29 $ sqlite3 mydata.db
30 SQLite version 3.1.3
31 Enter ".help" for instructions
32 sqlite> create table memos(text, priority INTEGER);
33 sqlite> insert into memos values('deliver project description', 10);
34 sqlite> insert into memos values('lunch with Christine', 100);
35 sqlite> select * from memos;
36 deliver project description|10
37 lunch with Christine|100
38 sqlite>
39
40
41 If no database name is supplied, the ATTACH sql command can be used to
42 attach to existing or create new database files. ATTACH can also be
43 used to attach to multiple databases within the same interactive ses‐
44 sion. This is useful for migrating data between databases, possibly
45 changing the schema along the way.
46
47 Optionally, a SQL statement or set of SQL statements can be supplied as
48 a single argument. Multiple statements should be separated by semi-
49 colons.
50
51 For example:
52
53 $ sqlite3 -line mydata.db 'select * from memos where priority > 20;'
54 text = lunch with Christine
55 priority = 100
56
57
58
59 SQLITE META-COMMANDS
60 The interactive interpreter offers a set of meta-commands that can be
61 used to control the output format, examine the currently attached data‐
62 base files, or perform administrative operations upon the attached
63 databases (such as rebuilding indices). Meta-commands are always pre‐
64 fixed with a dot (.).
65
66 A list of available meta-commands can be viewed at any time by issuing
67 the '.help' command. For example:
68
69 sqlite> .help
70 .databases List names and files of attached databases
71 .dump ?TABLE? ... Dump the database in an SQL text format
72 .echo ON|OFF Turn command echo on or off
73 .exit Exit this program
74 .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
75 .header(s) ON|OFF Turn display of headers on or off
76 .help Show this message
77 .import FILE TABLE Import data from FILE into TABLE
78 .indices TABLE Show names of all indices on TABLE
79 .mode MODE ?TABLE? Set output mode where MODE is one of:
80 csv Comma-separated values
81 column Left-aligned columns. (See .width)
82 html HTML <table> code
83 insert SQL insert statements for TABLE
84 line One value per line
85 list Values delimited by .separator string
86 tabs Tab-separated values
87 tcl TCL list elements
88 .nullvalue STRING Print STRING in place of NULL values
89 .output FILENAME Send output to FILENAME
90 .output stdout Send output to the screen
91 .prompt MAIN CONTINUE Replace the standard prompts
92 .quit Exit this program
93 .read FILENAME Execute SQL in FILENAME
94 .schema ?TABLE? Show the CREATE statements
95 .separator STRING Change separator used by output mode and .import
96 .show Show the current values for various settings
97 .tables ?PATTERN? List names of tables matching a LIKE pattern
98 .timeout MS Try opening locked tables for MS milliseconds
99 .width NUM NUM ... Set column widths for "column" mode
100 sqlite>
101
102
103
105 sqlite3 has the following options:
106
107 -init file
108 Read and execute commands from file , which can contain a mix of
109 SQL statements and meta-commands.
110
111 -echo Print commands before execution.
112
113 -[no]header
114 Turn headers on or off.
115
116 -bail Stop after hitting an error.
117
118 -interactive
119 Force interactive I/O.
120
121 -batch Force batch I/O.
122
123 -column
124 Query results will be displayed in a table like form, using
125 whitespace characters to separate the columns and align the out‐
126 put.
127
128 -cmd command
129 Run command before reading stdin.
130
131 -csv Set output mode to CSV (comma separated values).
132
133 -html Query results will be output as simple HTML tables.
134
135 -line Query results will be displayed with one value per line, rows
136 separated by a blank line. Designed to be easily parsed by
137 scripts or other programs
138
139 -list Query results will be displayed with the separator (|, by
140 default) character between each field value. The default.
141
142 -separator separator
143 Set output field separator. Default is '|'.
144
145 -nullvalue string
146 Set string used to represent NULL values. Default is '' (empty
147 string).
148
149 -stats Print memory stats before each finalize.
150
151 -version
152 Show SQLite version.
153
154 -vfs name
155 Use name as the default VFS.
156
157 -help Show help on options and exit.
158
159
160
162 sqlite3 reads an initialization file to set the configuration of the
163 interactive environment. Throughout initialization, any previously
164 specified setting can be overridden. The sequence of initialization is
165 as follows:
166
167 o The default configuration is established as follows:
168
169
170 mode = LIST
171 separator = "|"
172 main prompt = "sqlite> "
173 continue prompt = " ...> "
174
175
176 o If the file ~/.sqliterc exists, it is processed first. can be found
177 in the user's home directory, it is read and processed. It should gen‐
178 erally only contain meta-commands.
179
180 o If the -init option is present, the specified file is processed.
181
182 o All other command line options are processed.
183
184
186 http://www.sqlite.org/
187 The sqlite-doc package
188
190 This manual page was originally written by Andreas Rottmann
191 <rotty@debian.org>, for the Debian GNU/Linux system (but may be used by
192 others). It was subsequently revised by Bill Bumgarner
193 <bbum@mac.com>.
194
195
196
197 Mon Apr 15 23:49:17 2002 SQLITE3(1)