Constraints and Indexes
Primary Key
Stable Row Identity
A primary key identifies rows. It is the column other tables often reference.
Program
Play the script to create stable user IDs.
primary_key.sql
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO users VALUES (1, 'Ada'), (2, 'Lin');
SELECT id, name FROM users ORDER BY id;
PRIMARY KEY
`PRIMARY KEY` marks a row identifier.
identity
IDs make rows easy to reference from other tables.
ordering
Primary keys are often used for stable output order.