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 the database file does not exist, it will be created. If no database filename is given (or an empty string is given), a file-backed temporary database will be created. If the database name :memory: is given, an in-memory database will be created.

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 SQL statements need to be passed as a single argument, so they will most likely need to be enclosed in quotes. If present, sqlite3 will open the database file, execute the provided SQL statements, and exit. Dot-commands cannot be included in the SQL string. If no SQL string is given, sqlite3 will provide an interactive prompt and accept either SQL or dot-commands from the terminal interface.

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). The init file may contain both dot-commands and SQL statements. All SQL statements must end in a semicolon. The init file is processed before the command-line options. This allows the command-line options to override ...

Get Using SQLite now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.