Skip to content
Course content preview

11: Updating records

A library all on its own isn't all that interesting, so let's create the town that holds it.

CREATE town:riverdale SET name = "Riverdale";


Output
[
  {
    id: town:riverdale,
    name: 'Riverdale'
  }
]


If we want, we can select both the library and town inside a single statement.

SELECT * FROM place, town;


Output
[
  {
    address: '2025 Statement Street, Riverdale',
    floors: 8,
    id: place:surreal_library,
    name: 'Surreal Library',
    place_type: 'library'
  },
  {
    id: town:riverdale,
    name: 'Riverdale'
  }
]


However, while these two records have turned up in the same query, they aren't actually connected to each other. It would be nice to link the two so that we could always access the library inside queries on the town. To do this, we can update the town record to add a link to the library.

UPDATE is similar to CREATE in that it can be followed by SET to set values for the fields. And like a SELECT statement, an UPDATE for a table without a WHERE will update every record for the table. A WHERE clause isn't truly needed here because we only have one town, but let's add it to make it clear. Also, this will guarantee that only the town of "Riverdale" gets updated even if we add more town records later.

To practice, we will first update Riverdale to give it a population of 75000.

UPDATE town
SET population = 75000
WHERE name = "Riverdale";


Output
[
  {
    id: town:riverdale,
    name: 'Riverdale',
    population: 75000
  }
]


Now that we know how to update records, we can update this town again in the next page with a link.

THE PLATFORM

Everything an application and its agents know. Five surfaces, one engine.

IN PRODUCTION

Trusted at scale. Samsung, Nvidia, Verizon, Tencent and Walmart run on SurrealDB.

14,000+

Developers building on SurrealDB Cloud

4M+

Developers building on SurrealDB worldwide

FROM THE TEAMS

SurrealDB gives us a foundation where we can unify semantic search, knowledge graphs, and AI-driven decision making without stitching together multiple systems. Collapsing responsibility into SurrealDB has become our default engineering posture.
Justin Foley

VP of Engineering, Later

SurrealDB

The context and memory layer for AI agents

Database. Graphs, vectors, documents and relational data in one engine, in a single ACID transaction.
Agent Memory. Connects and retrieves context wherever your data lives, every fact carrying its source.
Cloud. Fully managed, in the cloud provider and region you choose.

Explore with AI

Copyright © 2026 SurrealDB Ltd. Registered in England and Wales. Company no. 13615201

Registered address: 3rd Floor 1 Ashley Road, Altrincham, Cheshire, WA14 2DT, United Kingdom

Trading address: Huckletree Oxford Circus, 213 Oxford Street, London, W1D 2LG, United Kingdom