sqlite3 command reference

44
sqlite3 Command Reference

Upload: raghu-nath

Post on 15-Jul-2015

136 views

Category:

Education


2 download

TRANSCRIPT

sqlite3 Command Reference

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

.import Import an external data file into a table

Common Usage

.import filename table-name

.indices Display all of the indexes associated with one or more tables

Common Usage

.indices [table-pattern]

.iotrace Direct I/O trace information to a file

Common Usage

.iotrace [filename|-]

.iotrace Direct I/O trace information to a file

Common Usage

.iotrace [filename|-]

.load Load a dynamic extension

Common Usage

.load filename [entry-point]

.log Turn logging on or off

Common Usage

.log (filename|stdout|stderr|off)

.mode Set the output mode

Common Usage

.mode (column[s]|csv|html|insert|line[s]|list|tabs|tcl) [table-name]

.nullvalue Set the string used to represent a NULL output

Common Usage

.nullvalue string

.output Set the output destination

Common Usage

.output (filename|stdout)

.prompt Set the command prompt

Common Usage

.prompt main [continue]

.quit Quit and exit the sqlite3 application

Common Usage

.quit

.read Execute SQL commands from a file

Common Usage

.read filename

.restore Perform a low-level copy of a database file to a database

Common Usage

.restore [database_name] filename

.schema Display SQL creation commands for schema

Common Usage

.schema [table-pattern]

.separator Define the string used as a column separator

Common Usage

.separator string

.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.

.timeout Set a lock retry timer

Common Usage

.timeout milliseconds

.timer Enable or disable CPU time measurements

Common Usage

.timer switch

.width Set the display width for each column

Common Usage

.width numb [numb ...]

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.

SQLite SQL Commands

The following SQL commands and syntax are supported by SQLite

Common Usage

ALTER TABLE database_name.table_name RENAME TO new_table_name;

ALTER TABLE database_name.table_name ADD COLUMN column_def...

ANALYZE Compute index meta-data

Syntax

Common Usage

ANALYZE;

ANALYZE database_name;

ANALYZE database_name.table_name;

ATTACH DATABASE Attach a database file

Syntax

Common Usage

ATTACH DATABASE 'filename' AS database_name;

BEGIN TRANSACTION Open an explicit transaction

Syntax

Common Usage

BEGIN;

BEGIN EXCLUSIVE TRANSACTION;

COMMIT TRANSACTION Finish and commit a transaction

Syntax

Common Usage

COMMIT;

CREATE INDEX Define and create a new table index

Syntax

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 ,... );

CREATE TABLE Define and create a new tableSyntax