
6: Deleting records
None of our place records have any useful information, so let's delete them to get ready to finally create the one library that we need. Two things to know when using DELETE are:
A
DELETEstatement followed by a table name will delete all of the records from that table.When SurrealDB performs an operation, it returns the result after the operation. So for
DELETE, it will return nothing (an empty array).
Here is a quick example that shows this behaviour.
[
{
id: some_record:wqewkk86z6qqi18yenhc
}
][]If you want to return the state before an operation, you can add RETURN BEFORE to the end of a query. This is especially useful in DELETE statements because it shows which records were deleted.
[
{
id: place:b53ful62pogdxvjb57sh,
num_books: 10000,
place_type: 'library'
},
{
id: place:bx4iy7ckqzhyj5xkrba9
},
{
id: place:e6uldb0aoq4jib2kfgqs,
place_type: 'library'
},
{
id: place:⟨ma_bibliothèque⟩
},
{
id: place:mq62n1aic4nxpuiuss93
},
{
id: place:my_library
},
{
id: place:noamxxe7h1rx59403sdw
},
{
id: place:p2n354tklmfpgxl3bifs
},
{
id: place:⟨良い図書館⟩
},
{
id: place:⟨𒂍𒁾𒁀𒀀⟩
}
]You can use a WHERE clause to delete records that match a certain condition, or DELETE on a single record ID to delete just one.
-- Delete everyone named "Bill":
-- might be zero, one, or more records
DELETE person WHERE name = "Bill";
-- Will only delete one record
DELETE person:bill;You can also delete a range of records.
-- Delete from person:1 up to but not including person:3
DELETE person:1..3;
-- Delete from person:1 up to and including person:3
DELETE person:1..=3;THE PLATFORM
Everything an application and its agents know. Five surfaces, one engine.
Database
Document, graph, vector, time-series and relational in one engine.

Agent Memory
What an agent learns, with its source and its time, in the same engine.

Cloud
Managed clusters in the regions you choose, scaled on demand.

Studio
Query, explore and design the schema from the browser.

MCP
Every model that speaks MCP reaches the database and the memory directly.

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.
VP of Engineering, Later