Skip to content

Commit

Permalink
[Term Entry] SQL Operators: UPDATE
Browse files Browse the repository at this point in the history
* Add sql update entry

* Update update.md

* Fix lint errors

* Minor changes

---------
  • Loading branch information
PragatiVerma18 authored Dec 24, 2024
1 parent 78b6d9d commit 0539167
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions content/sql/concepts/operators/terms/update/update.md
Original file line number Diff line number Diff line change
@@ -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 |

0 comments on commit 0539167

Please sign in to comment.