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

Basics

  • upsert - behave as an UPDATE or a no-op if the INSERT would violate a uniqueness constraint.

Create Db

$sqlite3 DatabaseName.db
sqlite> .quit

Ruby tutorial

How can I analyse a Sqlite query execution?

Index

rowid / Autoincrement

Rowid Tables are distinguished by the fact that they all have a unique, non-NULL, signed 64-bit integer rowid that is used as the access key for the data in the underlying B-tree storage engine.

  • is not a virtual table, and
  • is not a WITHOUT ROWID table.

when the rowid table declares an INTEGER PRIMARY KEY. the INTEGER PRIMARY KEY becomes an alias for the rowid.

  • if the rowid is not aliased by INTEGER PRIMARY KEY then it is not persistent and might change. Therefore, applications should not normally access the rowid directly, but instead use an INTEGER PRIMARY KEY.

  • Sqlite primary key on multiple columns

CREATE TABLE something (
  column1, 
  column2, 
  column3, 
  PRIMARY KEY (column1, column2)
);

WITHOUT ROWID

A WITHOUT ROWID table is an optimization that can reduce storage and processing requirements.

The WITHOUT ROWID optimization is likely to be helpful for tables that have non-integer or composite (multi-column) PRIMARY KEYs and that do not store large strings or BLOBs.

In some cases, a WITHOUT ROWID table can use about half the amount of disk space and can operate nearly twice as fast.

SQL Dialect

Replace (/ insert)

Virtual Table

The Session Extension / HN

a mechanism for recording changes to some or all of the rowid tables in an SQLite database, and packaging those changes into a “changeset” or “patchset” file that can later be used to apply the same set of changes to another database with the same schema and compatible starting data. A “changeset” may also be inverted and used to “undo” a session.

Tools & Visualizer

Version

In 2004 sqlite migrate to sqlite version 3 with new API and incompatible file format. - sqlite3

API

Typescript/Node.js0

Written on August 21, 2020, Last update on January 30, 2023
sqlite sql db ruby