drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 1 | .\" 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) |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 5 | .TH SQLITE3 1 "Fri Oct 31 10:41:31 EDT 2014" |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 6 | .\" 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 |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 19 | .B sqlite3 |
| 20 | \- A command line interface for SQLite version 3 |
| 21 | |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 22 | .SH SYNOPSIS |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 23 | .B sqlite3 |
| 24 | .RI [ options ] |
| 25 | .RI [ databasefile ] |
| 26 | .RI [ SQL ] |
| 27 | |
| 28 | .SH SUMMARY |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 29 | .PP |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 30 | .B sqlite3 |
| 31 | is a terminal-based front-end to the SQLite library that can evaluate |
| 32 | queries interactively and display the results in multiple formats. |
| 33 | .B sqlite3 |
| 34 | can also be used within shell scripts and other applications to provide |
| 35 | batch processing features. |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 36 | |
| 37 | .SH DESCRIPTION |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 38 | To start a |
| 39 | .B sqlite3 |
| 40 | interactive session, invoke the |
| 41 | .B sqlite3 |
| 42 | command and optionally provide the name of a database file. If the |
| 43 | database file does not exist, it will be created. If the database file |
| 44 | does exist, it will be opened. |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 45 | |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 46 | For example, to create a new database file named "mydata.db", create |
| 47 | a table named "memos" and insert a couple of records into that table: |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 48 | .sp |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 49 | $ |
| 50 | .B sqlite3 mydata.db |
| 51 | .br |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 52 | SQLite version 3.8.8 |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 53 | .br |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 54 | Enter ".help" for instructions |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 55 | .br |
| 56 | sqlite> |
| 57 | .B create table memos(text, priority INTEGER); |
| 58 | .br |
| 59 | sqlite> |
| 60 | .B insert into memos values('deliver project description', 10); |
| 61 | .br |
| 62 | sqlite> |
| 63 | .B insert into memos values('lunch with Christine', 100); |
| 64 | .br |
| 65 | sqlite> |
| 66 | .B select * from memos; |
| 67 | .br |
| 68 | deliver project description|10 |
| 69 | .br |
| 70 | lunch with Christine|100 |
| 71 | .br |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 72 | sqlite> |
| 73 | .sp |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 74 | |
| 75 | If no database name is supplied, the ATTACH sql command can be used |
| 76 | to attach to existing or create new database files. ATTACH can also |
| 77 | be used to attach to multiple databases within the same interactive |
| 78 | session. This is useful for migrating data between databases, |
| 79 | possibly changing the schema along the way. |
| 80 | |
| 81 | Optionally, a SQL statement or set of SQL statements can be supplied as |
| 82 | a single argument. Multiple statements should be separated by |
| 83 | semi-colons. |
| 84 | |
| 85 | For 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 |
| 92 | priority = 100 |
| 93 | .br |
| 94 | .sp |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 95 | |
| 96 | .SS SQLITE META-COMMANDS |
| 97 | .PP |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 98 | The interactive interpreter offers a set of meta-commands that can be |
| 99 | used to control the output format, examine the currently attached |
| 100 | database files, or perform administrative operations upon the |
| 101 | attached databases (such as rebuilding indices). Meta-commands are |
| 102 | always prefixed with a dot (.). |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 103 | |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 104 | A list of available meta-commands can be viewed at any time by issuing |
| 105 | the '.help' command. For example: |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 106 | .sp |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 107 | sqlite> |
| 108 | .B .help |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 109 | .nf |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 110 | .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 |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 116 | If TABLE specified, only dump tables matching |
| 117 | LIKE pattern TABLE. |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 118 | %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. |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 122 | With no args, it turns EXPLAIN on. |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 123 | %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 |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 128 | If TABLE specified, only show indices for tables |
| 129 | matching LIKE pattern TABLE. |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 130 | %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: |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 133 | 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 |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 141 | %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 |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 152 | If TABLE specified, only show tables matching |
| 153 | LIKE pattern TABLE. |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 154 | %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 |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 161 | If TABLE specified, only list tables matching |
| 162 | LIKE pattern TABLE. |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 163 | %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 |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 169 | sqlite> |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 170 | .sp |
| 171 | .fi |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 172 | .SH OPTIONS |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 173 | .B sqlite3 |
| 174 | has the following options: |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 175 | .TP |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 176 | .B \-bail |
| 177 | Stop after hitting an error. |
persicom | 45698a3 | 2002-04-18 02:53:54 +0000 | [diff] [blame] | 178 | .TP |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 179 | .B \-batch |
| 180 | Force batch I/O. |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 181 | .TP |
| 182 | .B \-column |
| 183 | Query results will be displayed in a table like form, using |
| 184 | whitespace characters to separate the columns and align the |
| 185 | output. |
| 186 | .TP |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 187 | .BI \-cmd\ command |
| 188 | run |
| 189 | .I command |
| 190 | before reading stdin |
| 191 | .TP |
| 192 | .B \-csv |
| 193 | Set output mode to CSV (comma separated values). |
| 194 | .TP |
| 195 | .B \-echo |
| 196 | Print commands before execution. |
| 197 | .TP |
| 198 | .BI \-init\ file |
| 199 | Read 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 |
| 204 | Turn headers on or off. |
| 205 | .TP |
| 206 | .B \-help |
| 207 | Show help on options and exit. |
| 208 | .TP |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 209 | .B \-html |
| 210 | Query results will be output as simple HTML tables. |
| 211 | .TP |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 212 | .B \-interactive |
| 213 | Force interactive I/O. |
| 214 | .TP |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 215 | .B \-line |
| 216 | Query results will be displayed with one value per line, rows |
| 217 | separated by a blank line. Designed to be easily parsed by |
| 218 | scripts or other programs |
| 219 | .TP |
| 220 | .B \-list |
| 221 | Query results will be displayed with the separator (|, by default) |
| 222 | character between each field value. The default. |
| 223 | .TP |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 224 | .BI \-mmap\ N |
| 225 | Set default mmap size to |
| 226 | .I N |
| 227 | \. |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 228 | .TP |
| 229 | .BI \-nullvalue\ string |
| 230 | Set string used to represent NULL values. Default is '' |
| 231 | (empty string). |
| 232 | .TP |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 233 | .BI \-separator\ separator |
| 234 | Set output field separator. Default is '|'. |
| 235 | .TP |
| 236 | .B \-stats |
| 237 | Print memory stats before each finalize. |
| 238 | .TP |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 239 | .B \-version |
| 240 | Show SQLite version. |
| 241 | .TP |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 242 | .BI \-vfs\ name |
| 243 | Use |
| 244 | .I name |
| 245 | as the default VFS. |
persicom | 45698a3 | 2002-04-18 02:53:54 +0000 | [diff] [blame] | 246 | |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 247 | |
persicom | 45698a3 | 2002-04-18 02:53:54 +0000 | [diff] [blame] | 248 | .SH INIT FILE |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 249 | .B sqlite3 |
| 250 | reads an initialization file to set the configuration of the |
| 251 | interactive environment. Throughout initialization, any previously |
| 252 | specified setting can be overridden. The sequence of initialization is |
| 253 | as follows: |
persicom | 45698a3 | 2002-04-18 02:53:54 +0000 | [diff] [blame] | 254 | |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 255 | o The default configuration is established as follows: |
persicom | 45698a3 | 2002-04-18 02:53:54 +0000 | [diff] [blame] | 256 | |
| 257 | .sp |
| 258 | .nf |
| 259 | .cc | |
| 260 | mode = LIST |
| 261 | separator = "|" |
| 262 | main prompt = "sqlite> " |
| 263 | continue prompt = " ...> " |
| 264 | |cc . |
| 265 | .sp |
| 266 | .fi |
| 267 | |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 268 | o If the file |
| 269 | .B ~/.sqliterc |
| 270 | exists, it is processed first. |
| 271 | can be found in the user's home directory, it is |
| 272 | read and processed. It should generally only contain meta-commands. |
persicom | 45698a3 | 2002-04-18 02:53:54 +0000 | [diff] [blame] | 273 | |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 274 | o If the -init option is present, the specified file is processed. |
persicom | 45698a3 | 2002-04-18 02:53:54 +0000 | [diff] [blame] | 275 | |
drh | 7530873 | 2005-02-24 04:51:51 +0000 | [diff] [blame] | 276 | o All other command line options are processed. |
persicom | 45698a3 | 2002-04-18 02:53:54 +0000 | [diff] [blame] | 277 | |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 278 | .SH SEE ALSO |
drh | 0fb5dae | 2014-10-31 14:46:51 +0000 | [diff] [blame] | 279 | http://www.sqlite.org/cli.html |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 280 | .br |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 281 | The sqlite3-doc package. |
drh | 3a88fbd | 2002-01-07 19:58:43 +0000 | [diff] [blame] | 282 | .SH AUTHOR |
drh | 0fface6 | 2002-05-06 11:34:26 +0000 | [diff] [blame] | 283 | This manual page was originally written by Andreas Rottmann |
| 284 | <rotty@debian.org>, for the Debian GNU/Linux system (but may be used |
drh | d49c545 | 2014-01-31 11:50:20 +0000 | [diff] [blame] | 285 | by others). It was subsequently revised by Bill Bumgarner <bbum@mac.com> and |
| 286 | further updated by Laszlo Boszormenyi <gcs@debian.hu> . |