Creating tables and data entry in Datasette (Datasette Advent Day 3)
Learn how to create, modify, and relate tables in Datasette using simple commands and the new label column feature.

Introduction
Datasette makes it easy to turn SQLite databases into interactive web APIs. In the third Advent Day video, Simon Willison demonstrates the workflow for creating tables, inserting and updating rows, altering schemas, and defining relationshipsâincluding the newly added label column that helps Datasette choose a humanâreadable summary for related records.
Creating and Populating Tables
The video starts by launching Datasette with the convenient `uvx` helper:
```bash uvx --pre datasette sightings.db --create --root ```
- `--pre` pulls the latest preârelease version.
- `--create` generates `sightings.db` if it doesnât exist.
- `--root` starts the server with root privileges, allowing schema changes.
Once the server is running, you can use the builtâin SQL editor or the API to create a table:
```sql CREATE TABLE sightings ( id INTEGER PRIMARY KEY, species TEXT NOT NULL, location TEXT, observed_at TEXT ); ``` After the table exists, inserting data is straightforward:
```sql INSERT INTO sightings (species, location, observed_at) VALUES ('Barn Owl', 'Meadow', '2026-11-30 22:15'), ('Red Fox', 'Forest Edge', '2026-12-01 07:42'); ``` Updates follow the same pattern with `UPDATE ⌠SET ⌠WHERE âŚ`.
Altering Tables and Adding Columns
Datasette supports standard SQLite `ALTER TABLE` commands. To add a column for photographer notes:
```sql ALTER TABLE sightings ADD COLUMN notes TEXT; ``` You can then backâfill or edit notes using regular `UPDATE` statements. Because the server runs as root, these schema changes take effect immediately without restarting.
Defining Relationships
Foreign Keys
To relate sightings to a `users` table that stores observer information, first create the users table:
```sql CREATE TABLE users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, email TEXT UNIQUE ); ``` Then add a foreignâkey column to `sightings`:
```sql ALTER TABLE sightings ADD COLUMN userid INTEGER REFERENCES users(id); ``` When you query a sighting, Datasette can now follow the `userid` link to display the observerâs name.
ManyâtoâMany Relationships
For more complex scenariosâsuch as linking sightings to multiple tagsâyou create a join table:
```sql CREATE TABLE sightingtags ( sightingid INTEGER REFERENCES sightings(id), tagid INTEGER REFERENCES tags(id), PRIMARY KEY (sightingid, tag_id) ); ``` This pattern enables flexible categorisation without duplicating data.
Using the New Label Column
Datasette 1.0a47 introduces a label column attribute. By setting a column as the label, you tell Datasette which field best represents a row when it appears in a relationship view. For example:
```sql ALTER TABLE users SET LABEL COLUMN name; ``` Now, whenever a user is displayed as part of a related record (e.g., in a sightingâs detail view), the UI will show the userâs name instead of the raw `id`.
Practical Takeaways
- Quick launch â `uvx --pre datasette ⌠--root` gets you a fullyâfeatured instance without a global install.
- Schema changes are live â Root mode lets you create, alter, and drop tables on the fly.
- Relationships are explicit â Use foreign keys for oneâtoâmany and join tables for manyâtoâmany.
- Label columns improve readability â Designate a humanâfriendly column to make related data clearer.
Closing Thoughts
Datasetteâs blend of SQLite simplicity and webâready APIs makes it ideal for rapid prototyping and lightweight data publishing. By mastering table creation, data entry, and relationship mappingâincluding the new label columnâyou can build richer, more navigable datasets with minimal friction. The next step is to explore Datasette plugins for authentication, custom visualisations, and deployment to cloud platforms, turning your local database into a shareable, interactive resource.
Source
Read original sourceWhy we picked this
Tutorial on data entry in Datasette highlights new features useful for AIâdriven data workflows.