POST_START
# Updating Existing Records in Delta Tables
In this tutorial, you will learn how to update existing records in a Delta table using Unity Catalog in Databricks. The operation we will focus on is updating a specific customer's country in the `training.sales.customers` table.
—
## Step 1: Verify the Existing Record
Before performing an update, it's a good practice to verify the current state of the record you intend to modify. This helps ensure that the update is applied correctly and avoids unintended changes.
Use the following SQL command to select the customer record with `customer_id = 1`:
“`sql
SELECT * FROM training.sales.customers WHERE customer_id = 1;
“`
This query will return the current details of the customer, including their current country. Make note of this information as a reference.
—
## Step 2: Update the Record
Now that you've confirmed the current state of the record, you can proceed with the update. The following SQL command updates the `country` field for the customer with `customer_id = 1` to `'Netherlands'`:
“`sql
UPDATE training.sales.customers SET country = 'Netherlands' WHERE customer_id = 1;
“`
This operation is atomic and will modify only the specified record in the Delta table. Since Delta Lake supports ACID transactions, this update is safe and consistent across concurrent operations.
—
## Summary
– Always verify the existing data before performing an update.
– Use the `UPDATE` statement with the appropriate `SET` and `WHERE` clauses to modify specific records.
– The `training.sales.customers` table in Unity Catalog supports these operations natively, leveraging Delta Lake's capabilities for reliable and efficient data updates.
By following this process, you can confidently update records in your Delta tables while maintaining data integrity and consistency.


Leave a Reply