Update data with the SQL language. SQL has a query for updating data stored in tables.

SQL needs to know which record(s) to update. Use the WHERE clause to tell which records need to be updated.

Lets say you have 10 records (1..10). You want to update the 4th record, then you would write WHERE id=4.

You may like:
Learning SQL: Master SQL Fundamentals

Example

Syntax

Inside the query set the new value and the conditions:

1
UPDATE table SET column = value WHERE ...

Update Query

We start with the basic table created earlier:

1
2
3
4
5
6
7
8
sql> SELECT * FROM Students;
+----------+--------+----------+-----------+-----------+
| PersonID | Gender | LastName | FirstName | StudentID |
+----------+--------+----------+-----------+-----------+
| 13148 | 0 | Johnson | John | 6391931 |
| 13149 | 1 | Dylan | Abby | 439225 |
| 13150 | 1 | Hinton | Alice | 139225 |
+----------+--------+----------+-----------+-----------+

Then, we change the first records column FirstName:

1
sql> UPDATE Students SET FirstName = 'Dave' WHERE PersonID=13148;

If you’d then take a look at the table, you’ll see the record is updated.

1
2
3
4
5
6
7
8
sql> SELECT * FROM Students;
+----------+--------+----------+-----------+-----------+
| PersonID | Gender | LastName | FirstName | StudentID |
+----------+--------+----------+-----------+-----------+
| 13148 | 0 | Johnson | Dave | 6391931 |
| 13149 | 1 | Dylan | Abby | 439225 |
| 13150 | 1 | Hinton | Alice | 139225 |
+----------+--------+----------+-----------+-----------+

Video

The UPDATE Query demonstration in video