TIL: SQLite's 'WITHOUT ROWID'
benjamincongdon.me·3d
🗄️SQLite Internals
Preview
Report Post

By default, SQLite tables have a special rowid column that uniquely identifies each row. This rowid exists even if you have a user-specified PRIMARY KEY on the table. How this rowid column behaves is influenced by your PRIMARY KEY type.

Integer Primary Keys: If you have an integer primary key, then the primary key column becomes an alias for the special rowid column. The rowid and your user-defined primary key are literally just the same column.

Taking an example:

CREATE TABLE IF NOT EXISTS users(
user_id INTEGER PRIMARY KEY,
email TEXT,
);

In this case, since we’ve defined user_id to be an INTEGER PRIMARY KEY, user_id becomes an alias for rowid. These two labels refer to the same physical column.

Figure 1: Integer primary keys are aliase…

Similar Posts

Loading similar posts...