sqlite3 command reference
TRANSCRIPT
The sqlite3 program is a command-line interface, or shell, that allows the user to
interactively issue SQL commands and display the results.
Command-Line Options
The sqlite3 tool understands the following command-line format:
sqlite3 [options...] [database [SQL_string]]
Options are given first, followed by an optional database filename. This database will
be opened as the main database
If a database filename is given, an optional SQL string can be provided. This string may
consist of one or more SQL statements separated by semicolons.
The interactive startup sequence will attempt to locate and open the .sqliterc init file
in the current user’s home directory. If the file exists, lines will be read and executed
before any other processing (including the command-line SQL string).
Interactive Dot-CommandsThis section covers the sqlite3 dot-commands. Dot-commands control the mode and
configuration of the sqlite3 utility and, in some cases, the underlying SQLite library.
Normally, any input to the sqlite3 utility is assumed to be an SQL statement and is
passed to the SQLite library for processing. To distinguish these commands from SQL
statements, all of the dot-commands start with a period, or “dot.” Hence, the name.
.backup Perform a low-level copy of a database to file
Common Usage
.backup [database_name] filename
.bail Stop if an error is encountered
Common Usage
.bail switch
.databases List all of the currently attached databases
Common Usage
.databases
Description
The .databases command generates a table of all the currently attached databases. The format
of the table is:
.dump Produce an SQL dump file
Common Usage
.dump [table-pattern ...]
.echo Turn command echoing on or off
Common Usage
.echo switch
.exit Quit and exit the sqlite3 application
Common Usage
.exit
explain Format output for EXPLAIN SQL command
Common Usage
.explain [switch]
.headers Control display of column names and headers
Common Usage
.headers switch
.help Display help
Common Usage
.help
.indices Display all of the indexes associated with one or more tables
Common Usage
.indices [table-pattern]
.mode Set the output mode
Common Usage
.mode (column[s]|csv|html|insert|line[s]|list|tabs|tcl) [table-name]
.restore Perform a low-level copy of a database file to a database
Common Usage
.restore [database_name] filename
.tables Display the list of table and view names
Common Usage
.tables [table-pattern]
Description
The .tables command displays the list of names for all of the table and view objects that are
found in the main and temp databases.
SQLite SQL Command ReferenceThis appendix lists the SQL commands and syntax that are supported by SQLite. SQL
statements consist of a single command and any required parameters. Command statements
are separated by a semicolon. Technically, standalone statements do not need
to be terminated with a semicolon, but most interactive environments require the use
of a semicolon to indicate that the current command statement is complete and should
be executed. For example, the C API sqlite3_exec() does not require that command
statements end with a semicolon, but interactive use of sqlite3 requires ending each
statement with a semicolon.
Common Usage
ALTER TABLE database_name.table_name RENAME TO new_table_name;
ALTER TABLE database_name.table_name ADD COLUMN column_def...
Common Usage
CREATE INDEX index_name ON table_name ( column_name COLLATE NOCASE );
CREATE UNIQUE INDEX database_name.index_name ON table_name ( col1, col2 ,... );