Sqlite client: Difference between revisions

From wikinotes
No edit summary
 
 
Line 33: Line 33:
.schema table_name            # table definition
.schema table_name            # table definition
</source>
</source>
See [[sqlite syntax]] for PRAGMA commands.
See [[sqlite syntax]] for PRAGMA commands.<br>
 
(ex. <code>PRAGMA table_info(my_table)</code> shows schema)


== Result Formatting ==
== Result Formatting ==

Latest revision as of 14:15, 6 May 2024

SQLite uses SQL.

Locations

~/.sqliterc config

Create Database

sqlite3         # in-memory db
sqlite3 new.db  # open/create db

CLI

Config

You can add sqlite commands to your sqliterc.

# ~/.sqliterc
.mode column
.header on

Introspection

.tables                        # list tables in db
.schema table_name             # table definition

See sqlite syntax for PRAGMA commands.
(ex. PRAGMA table_info(my_table) shows schema)

Result Formatting

.mode line    # one line per column
.mode column  # one line per row

.header on    # show column headers

Dump/Restore

# dumps database with data to dump.sql
.output dump.sql
.dump  # optionally, specify just table
.quit
# dump schema only to schema.sql
.output schema.sql
.schema
.quit
# restore from a dump
.read schema.sql
.quit