Skip to content

Commit 0539167

Browse files
[Term Entry] SQL Operators: UPDATE
* Add sql update entry * Update update.md * Fix lint errors * Minor changes ---------
1 parent 78b6d9d commit 0539167

File tree

1 file changed

+55
-0
lines changed
  • content/sql/concepts/operators/terms/update

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
Title: 'UPDATE'
3+
Description: 'Modifies existing records in a table according to specified conditions.'
4+
Subjects:
5+
- 'Data Science'
6+
- 'Computer Science'
7+
Tags:
8+
- 'Database'
9+
- 'Queries'
10+
- 'PostgreSQL'
11+
- 'MySQL'
12+
CatalogContent:
13+
- 'learn-sql'
14+
- 'paths/analyze-data-with-sql'
15+
---
16+
17+
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.
18+
19+
## Syntax
20+
21+
```pseudo
22+
UPDATE table_name
23+
SET column1 = value1, column2 = value2, ...
24+
WHERE condition;
25+
```
26+
27+
- `table_name`: The name of the table containing the data to be updated.
28+
- `SET`: Specifies the columns to update and their new values.
29+
- `condition`: An optional clause that specifies which rows to update. If omitted, all rows in the table are updated.
30+
31+
## Example
32+
33+
Let's say there's a table `Employees`:
34+
35+
| ID | Name | Department | Salary |
36+
| --- | ----- | ---------- | ------ |
37+
| 1 | John | HR | 50000 |
38+
| 2 | Alice | IT | 60000 |
39+
| 3 | Bob | Sales | 45000 |
40+
41+
To update Bob's salary in the Sales department, the following query can be used:
42+
43+
```sql
44+
UPDATE Employees
45+
SET Salary = 47000
46+
WHERE Name = 'Bob' AND Department = 'Sales';
47+
```
48+
49+
Now, the updated table will be as follows:
50+
51+
| ID | Name | Department | Salary |
52+
| --- | ----- | ---------- | ------ |
53+
| 1 | John | HR | 50000 |
54+
| 2 | Alice | IT | 60000 |
55+
| 3 | Bob | Sales | 47000 |

0 commit comments

Comments
 (0)