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 -column
117 Query results will be displayed in a table like form, using
118 whitespace characters to separate the columns and align the out‐
119 put.
120
121 -html Query results will be output as simple HTML tables.
122
123 -line Query results will be displayed with one value per line, rows
124 separated by a blank line. Designed to be easily parsed by
125 scripts or other programs
126
127 -list Query results will be displayed with the separator (|, by
128 default) character between each field value. The default.
129
130 -separator separator
131 Set output field separator. Default is '|'.
132
133 -nullvalue string
134 Set string used to represent NULL values. Default is '' (empty
135 string).
136
137 -version
138 Show SQLite version.
139
140 -help Show help on options and exit.
141
142
143
145 sqlite3 reads an initialization file to set the configuration of the
146 interactive environment. Throughout initialization, any previously
147 specified setting can be overridden. The sequence of initialization is
148 as follows:
149
150 o The default configuration is established as follows:
151
152
153 mode = LIST
154 separator = "|"
155 main prompt = "sqlite> "
156 continue prompt = " ...> "
157
158
159 o If the file ~/.sqliterc exists, it is processed first. can be found
160 in the user's home directory, it is read and processed. It should gen‐
161 erally only contain meta-commands.
162
163 o If the -init option is present, the specified file is processed.
164
165 o All other command line options are processed.
166
167
169 http://www.sqlite.org/
170 The sqlite-doc package
171
173 This manual page was originally written by Andreas Rottmann
174 <rotty@debian.org>, for the Debian GNU/Linux system (but may be used by
175 others). It was subsequently revised by Bill Bumgarner
176 <bbum@mac.com>.
177
178
179
180 Mon Apr 15 23:49:17 2002 SQLITE3(1)