1*022f0052Schristos.\" $NetBSD: sqlite3.1,v 1.1 2017/03/11 16:29:51 christos Exp $ 2*022f0052Schristos.Dd December 16, 2012 3*022f0052Schristos.Dt SQLITE3 1 4*022f0052Schristos.Os 5*022f0052Schristos.Sh NAME 6*022f0052Schristos.Nm sqlite3 7*022f0052Schristos.Nd A command line interface for SQLite version 3 8*022f0052Schristos.Sh SYNOPSIS 9*022f0052Schristos.Nm 10*022f0052Schristos.Op Ar options 11*022f0052Schristos.Op Ar databasefile 12*022f0052Schristos.Op Ar SQL 13*022f0052Schristos.Sh DESCRIPTION 14*022f0052Schristos.Nm 15*022f0052Schristosis a terminal-based front-end to the SQLite library that can evaluate 16*022f0052Schristosqueries interactively and display the results in multiple formats. 17*022f0052Schristos.Nm 18*022f0052Schristoscan also be used within shell scripts and other applications to provide 19*022f0052Schristosbatch processing features. 20*022f0052Schristos.Pp 21*022f0052SchristosTo start a 22*022f0052Schristos.Nm 23*022f0052Schristosinteractive session, invoke the 24*022f0052Schristos.Nm 25*022f0052Schristoscommand and optionally provide the name of a database file. 26*022f0052SchristosIf the database file does not exist, it will be created. 27*022f0052SchristosIf the database file does exist, it will be opened. 28*022f0052Schristos.Pp 29*022f0052SchristosFor example, to create a new database file named "mydata.db", create 30*022f0052Schristosa table named "memos" and insert a couple of records into that table: 31*022f0052Schristos.Bd -literal -offset indent 32*022f0052Schristos$ sqlite3 mydata.db 33*022f0052SchristosSQLite version 3.1.3 34*022f0052SchristosEnter ".help" for instructions 35*022f0052Schristossqlite> create table memos(text, priority INTEGER); 36*022f0052Schristossqlite> insert into memos values('deliver project description', 10); 37*022f0052Schristossqlite> insert into memos values('lunch with Christine', 100); 38*022f0052Schristossqlite> select * from memos; 39*022f0052Schristosdeliver project description|10 40*022f0052Schristoslunch with Christine|100 41*022f0052Schristossqlite> 42*022f0052Schristos.Ed 43*022f0052Schristos.Pp 44*022f0052SchristosIf no database name is supplied, the 45*022f0052Schristos.Em ATTACH 46*022f0052Schristossql command can be used 47*022f0052Schristosto attach to existing or create new database files. 48*022f0052Schristos.Em ATTACH 49*022f0052Schristoscan also be used to attach to multiple databases within the same 50*022f0052Schristosinteractive session. 51*022f0052SchristosThis is useful for migrating data between databases, 52*022f0052Schristospossibly changing the schema along the way. 53*022f0052Schristos.Pp 54*022f0052SchristosOptionally, a SQL statement or set of SQL statements can be supplied as 55*022f0052Schristosa single argument. 56*022f0052SchristosMultiple statements should be separated by semi-colons. 57*022f0052Schristos.Pp 58*022f0052SchristosFor example: 59*022f0052Schristos.Bd -literal -offset indent 60*022f0052Schristos$ sqlite3 -line mydata.db 'select * from memos where priority > 20;' 61*022f0052Schristos text = lunch with Christine 62*022f0052Schristos priority = 100 63*022f0052Schristos.Ed 64*022f0052Schristos.Ss SQLITE META-COMMANDS 65*022f0052SchristosThe interactive interpreter offers a set of meta-commands that can be 66*022f0052Schristosused to control the output format, examine the currently attached 67*022f0052Schristosdatabase files, or perform administrative operations upon the 68*022f0052Schristosattached databases (such as rebuilding indices). 69*022f0052SchristosMeta-commands are always prefixed with a dot 70*022f0052Schristos.Dq \&. . 71*022f0052Schristos.Pp 72*022f0052SchristosA list of available meta-commands can be viewed at any time by issuing 73*022f0052Schristosthe '.help' command. 74*022f0052SchristosFor example: 75*022f0052Schristos.Bd -literal -offset indent 76*022f0052Schristossqlite> .help 77*022f0052Schristos\&.databases List names and files of attached databases 78*022f0052Schristos\&.dump ?TABLE? ... Dump the database in an SQL text format 79*022f0052Schristos\&.echo ON|OFF Turn command echo on or off 80*022f0052Schristos\&.exit Exit this program 81*022f0052Schristos\&.explain ON|OFF Turn output mode suitable for EXPLAIN on or off. 82*022f0052Schristos\&.header(s) ON|OFF Turn display of headers on or off 83*022f0052Schristos\&.help Show this message 84*022f0052Schristos\&.import FILE TABLE Import data from FILE into TABLE 85*022f0052Schristos\&.indices TABLE Show names of all indices on TABLE 86*022f0052Schristos\&.mode MODE ?TABLE? Set output mode where MODE is one of: 87*022f0052Schristos csv Comma-separated values 88*022f0052Schristos column Left-aligned columns. (See .width) 89*022f0052Schristos html HTML <table> code 90*022f0052Schristos insert SQL insert statements for TABLE 91*022f0052Schristos line One value per line 92*022f0052Schristos list Values delimited by .separator string 93*022f0052Schristos tabs Tab-separated values 94*022f0052Schristos tcl TCL list elements 95*022f0052Schristos\&.nullvalue STRING Print STRING in place of NULL values 96*022f0052Schristos\&.output FILENAME Send output to FILENAME 97*022f0052Schristos\&.output stdout Send output to the screen 98*022f0052Schristos\&.prompt MAIN CONTINUE Replace the standard prompts 99*022f0052Schristos\&.quit Exit this program 100*022f0052Schristos\&.read FILENAME Execute SQL in FILENAME 101*022f0052Schristos\&.schema ?TABLE? Show the CREATE statements 102*022f0052Schristos\&.separator STRING Change separator used by output mode and .import 103*022f0052Schristos\&.show Show the current values for various settings 104*022f0052Schristos\&.tables ?PATTERN? List names of tables matching a LIKE pattern 105*022f0052Schristos\&.timeout MS Try opening locked tables for MS milliseconds 106*022f0052Schristos\&.width NUM NUM ... Set column widths for "column" mode 107*022f0052Schristossqlite> 108*022f0052Schristos.Ed 109*022f0052Schristos.Sh OPTIONS 110*022f0052Schristos.Nm 111*022f0052Schristoshas the following options: 112*022f0052Schristos.Bl -tag -width abcdefghij 113*022f0052Schristos.It Fl init Ar file 114*022f0052SchristosRead and execute commands from 115*022f0052Schristos.Ar file , 116*022f0052Schristoswhich can contain a mix of SQL statements and meta-commands. 117*022f0052Schristos.It Fl echo 118*022f0052SchristosPrint commands before execution. 119*022f0052Schristos.It Fl header 120*022f0052SchristosTurn headers on. 121*022f0052Schristos.It Fl noheader 122*022f0052SchristosTurn headers off. 123*022f0052Schristos.It Fl column 124*022f0052SchristosQuery results will be displayed in a table like form, using 125*022f0052Schristoswhitespace characters to separate the columns and align the 126*022f0052Schristosoutput. 127*022f0052Schristos.It Fl html 128*022f0052SchristosQuery results will be output as simple HTML tables. 129*022f0052Schristos.It Fl line 130*022f0052SchristosQuery results will be displayed with one value per line, rows 131*022f0052Schristosseparated by a blank line. 132*022f0052SchristosDesigned to be easily parsed by scripts or other programs 133*022f0052Schristos.It Fl list 134*022f0052SchristosQuery results will be displayed with the separator (|, by default) 135*022f0052Schristoscharacter between each field value. 136*022f0052Schristos.It Fl separator Ar separator 137*022f0052SchristosSet output field separator. 138*022f0052SchristosDefault is 139*022f0052Schristos.Dq | . 140*022f0052Schristos.It Fl nullvalue Ar string 141*022f0052SchristosSet 142*022f0052Schristos.Ar string 143*022f0052Schristosused to represent 144*022f0052Schristos.Dv NULL 145*022f0052Schristosvalues. 146*022f0052SchristosDefault is 147*022f0052Schristos.Dq \e 148*022f0052Schristos(empty string). 149*022f0052Schristos.It Fl version 150*022f0052SchristosShow SQLite version. 151*022f0052Schristos.It Fl help 152*022f0052SchristosShow help on options and exit. 153*022f0052Schristos.El 154*022f0052Schristos.Ss INIT FILE 155*022f0052Schristos.Nm 156*022f0052Schristosreads an initialization file to set the configuration of the 157*022f0052Schristosinteractive environment. 158*022f0052SchristosThroughout initialization, any previously specified setting can be overridden. 159*022f0052SchristosThe sequence of initialization is as follows: 160*022f0052Schristos.Bl -enum 161*022f0052Schristos.It 162*022f0052SchristosThe default configuration is established as follows: 163*022f0052Schristos.Bd -literal -offset indent 164*022f0052Schristosmode = LIST 165*022f0052Schristosseparator = "|" 166*022f0052Schristosmain prompt = "sqlite> " 167*022f0052Schristoscontinue prompt = " ...> " 168*022f0052Schristos.Ed 169*022f0052Schristos.It 170*022f0052SchristosIf the file 171*022f0052Schristos.Pa ~/.sqliterc 172*022f0052Schristosexists, it is processed first. 173*022f0052Schristoscan be found in the user's home directory, it is 174*022f0052Schristosread and processed. 175*022f0052SchristosIt should generally only contain meta-commands. 176*022f0052Schristos.It 177*022f0052SchristosIf the 178*022f0052Schristos.Fl init 179*022f0052Schristosoption is present, the specified file is processed. 180*022f0052Schristos.It 181*022f0052SchristosAll other command line options are processed. 182*022f0052Schristos.El 183*022f0052Schristos.Sh SEE ALSO 184*022f0052Schristos.Lk http://www.sqlite.org/ 185*022f0052Schristos.Sh AUTHORS 186*022f0052SchristosThis manual page was originally written by Andreas Rottmann 187*022f0052Schristos.Aq rotty@debian.org , 188*022f0052Schristosfor the Debian GNU/Linux system (but may be used by others). 189*022f0052SchristosIt was subsequently revised by Bill Bumgarner 190*022f0052Schristos.Aq bbum@mac.com . 191