From 0539167736a03e07e52130df612f8dc2ccf028c7 Mon Sep 17 00:00:00 2001 From: Pragati Verma Date: Tue, 24 Dec 2024 20:32:44 +0530 Subject: [PATCH] [Term Entry] SQL Operators: UPDATE * Add sql update entry * Update update.md * Fix lint errors * Minor changes --------- --- .../concepts/operators/terms/update/update.md | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 content/sql/concepts/operators/terms/update/update.md diff --git a/content/sql/concepts/operators/terms/update/update.md b/content/sql/concepts/operators/terms/update/update.md new file mode 100644 index 00000000000..c2d00a3102a --- /dev/null +++ b/content/sql/concepts/operators/terms/update/update.md @@ -0,0 +1,55 @@ +--- +Title: 'UPDATE' +Description: 'Modifies existing records in a table according to specified conditions.' +Subjects: + - 'Data Science' + - 'Computer Science' +Tags: + - 'Database' + - 'Queries' + - 'PostgreSQL' + - 'MySQL' +CatalogContent: + - 'learn-sql' + - 'paths/analyze-data-with-sql' +--- + +The **`UPDATE`** statement in SQL is used to modify existing records in a table. This powerful **Data Manipulation Language (DML)** command allows developers to update one or multiple rows simultaneously. + +## Syntax + +```pseudo +UPDATE table_name +SET column1 = value1, column2 = value2, ... +WHERE condition; +``` + +- `table_name`: The name of the table containing the data to be updated. +- `SET`: Specifies the columns to update and their new values. +- `condition`: An optional clause that specifies which rows to update. If omitted, all rows in the table are updated. + +## Example + +Let's say there's a table `Employees`: + +| ID | Name | Department | Salary | +| --- | ----- | ---------- | ------ | +| 1 | John | HR | 50000 | +| 2 | Alice | IT | 60000 | +| 3 | Bob | Sales | 45000 | + +To update Bob's salary in the Sales department, the following query can be used: + +```sql +UPDATE Employees +SET Salary = 47000 +WHERE Name = 'Bob' AND Department = 'Sales'; +``` + +Now, the updated table will be as follows: + +| ID | Name | Department | Salary | +| --- | ----- | ---------- | ------ | +| 1 | John | HR | 50000 | +| 2 | Alice | IT | 60000 | +| 3 | Bob | Sales | 47000 |