What is Xata?
Deleting records

Deleting records

Edit on GitHub

To delete a record you can execute, for example:

const user = await xata.db.Users.delete('rec_cd8s3r8avc42pi67m13g');

// or, using the delete method on the record object:

In case the record with the given ID doesn't exist, the REST API returns a 404 and the TypeScript SDK throws an exception.

Transactions are used when deleting multiple records:

const users = await xata.db.Users.delete(['rec_cd8s3r8avc42pi67m13g', 'rec_cgh9o1oncchhigq95n2g']);

To delete multiple records from the API, we recommend using transactions. Transactions will not fail a delete operation if a record is not found. All operations in a transaction must succeed otherwise it is rolled back.

Alternatively, you can use the DELETE statement via the SQL proxy, like in the following example:

DELETE FROM "titles"
    SELECT id
    FROM titles
    WHERE "originalTitle" ILIKE '%Matrix%'
    ORDER BY "xata.createdAt" ASC
    LIMIT 10000
  • SELECT id: Specifies that only the id column will be retrieved in the query.
  • FROM titles: The subquery operates on the titles table.
  • WHERE "originalTitle" ILIKE '%Matrix%': Filters rows based on a case-insensitive partial match in the originalTitle column.
  • LIMIT 10000: Restricts the number of results to a maximum of 10,000 rows.


Next Steps

Now that you have seen how to do the basic create, remove, update, and delete operations, you can check out the docs on using the free text search API, which is a new super power that Xata gives you.

You can also review the pages on getting data, updating data, inserting data. We've got guides for each of these operations.