SQLite

SQLite is a C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine. SQLite is the most used database engine in the world. SQLite is built into all mobile phones and most computers and comes bundled inside countless other applications that people use every day.

SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files. A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file. The database file format is cross-platform - you can freely copy a database between 32-bit and 64-bit systems or between big-endian and little-endian architectures. These features make SQLite a popular choice as an Application File Format.

Usage

Usage: sqlite3 [OPTIONS] FILENAME [SQL] FILENAME is the name of an SQLite database. A new database is created if the file does not previously exist.

Options

OptionDescription
-appendappend the database to the end of the file
-asciiset output mode to ‘ascii’
-bailstop after hitting an error
-batchforce batch I/O
-boxset output mode to ‘box’
-columnset output mode to ‘column’
-cmd COMMANDrun “COMMAND” before reading stdin
-csvset output mode to ‘csv
-deserializeopen the database using sqlite3_deserialize()
-echoprint inputs before execution
-init FILENAMEread/process named file
-[no]headerturn headers on or off
-hexkey KEYhexadecimal encryption key
-htmlset output mode to HTML
-interactiveforce interactive I/O
-key KEYraw encryption key
-jsonset output mode to ‘json
-lineset output mode to ‘line’
-listset output mode to ‘list’
-lookaside SIZE Nuse N entries of SZ bytes for lookaside memory
-markdownset output mode to ‘markdown
-maxsize Nmaximum size for a --deserialize database
-memtracetrace all memory allocations and deallocations
-newline SEPset output row separator. Default: \n
-nofollowrefuse to open symbolic links to database files
-nonce STRINGset the safe-mode escape nonce
-nullvalue TEXTset text string for NULL values. Default ”
-pagecache SIZE Nuse N slots of SZ bytes each for page cache memory
-quoteset output mode to ‘quote’
-readonlyopen the database read-only
-safeenable safe-mode
-separator SEPset output column separator. Default: ""
-statsprint memory stats before each finalize
-textkey PASSPHRASEtext to be hashed into the encryption key
-tableset output mode to ‘table’
-tabsset output mode to ‘tabs’
-versionshow SQLite version

Commands

The most important commands inside the SQLite3 Shell:

  • .backup ?DB? FILE: Backup DB (default “main”) to FILE
  • .bail on|off: Stop after hitting an error. Default OFF
  • .binary on|off: Turn binary output on or off. Default OFF
  • .cd DIRECTORY: Change the working directory to DIRECTORY
  • .changes on|off: Show number of rows changed by SQL
  • .check GLOB: Fail if output since .testcase does not match
  • .clone NEWDB: Clone data into NEWDB from the existing database
  • .databases: List names and files of attached databases
  • .dbinfo ?DB?: Show status information about the database
  • .dump ?OBJECTS?: Render database content as SQL
  • .echo on|off: Turn command echo on or off
  • .excel: Display the output of next command in spreadsheet
  • .exit ?CODE?: Exit this program with return-code CODE
  • .headers on|off: Turn display of headers on or off
  • .help ?-all? ?PATTERN?: Show help text for PATTERN
  • .hex-rekey OLD NEW NEW: Change the encryption key using hexadecimal
  • .import FILE TABLE: Import data from FILE into TABLE
  • .imposter INDEX TABLE: Create imposter table TABLE on index INDEX
  • .indexes ?TABLE?: Show names of indexes
  • .limit ?LIMIT? ?VAL?: Display or change the value of an SQLITE_LIMIT
  • .lint OPTIONS: Report potential schema issues.
  • .log FILE|off: Turn logging on or off. FILE can be stderr/stdout
  • .nullvalue STRING: Use STRING in place of NULL values
  • .once ?OPTIONS? ?FILE?: Output for the next SQL command only to FILE
  • .open ?OPTIONS? ?FILE?: Close existing database and reopen FILE
  • .output ?FILE?: Send output to FILE or stdout if FILE is omitted
  • .print STRING...: Print literal STRING
  • .quit: Exit this program
  • .read FILE: Read input from FILE or command output
  • .rekey OLD NEW NEW: Change the encryption key
  • .recover: Recover as much data as possible from corrupt db.
  • .restore ?DB? FILE: Restore content of DB (default “main”) from FILE
  • .save ?OPTIONS? FILE: Write database to FILE (an alias for .backup …)
  • .schema ?PATTERN?: Show the CREATE statements matching PATTERN
  • .selftest ?OPTIONS?: Run tests defined in the SELFTEST table
  • .separator COL ?ROW?: Change the column and row separators
  • .sha3sum ...: Compute a SHA3 hash of database content
  • .shell CMD ARGS...: Run CMD ARGS… in a system shell
  • .system CMD ARGS...: Run CMD ARGS… in a system shell
  • .show: Show the current values for various settings
  • .stats ?ARG? : Show stats or turn stats on or off
  • .tables ?TABLE? : List names of tables matching LIKE pattern TABLE
  • .text-rekey OLD NEW NEW: Change the encryption key using hexadecimal
  • .width NUM1 NUM2 ...: Set minimum column widths for columnar output