SQL UPDATE Statement
Introduction
SQL UPDATE statement is used to modify the data already present in the database.
Syntax:
UPDATE table_name
SET Column1= value1, Cloumn2 = value2, column3 = value3.....
WHERE [Condition];
Example : Query using UPDATE statement.
Consider the following table titled as
'Clients'
Client_ID | Last_Name | First_Name | Contact | Country |
---|
1 | Thomas | Alex | 2400000 | USA |
2 | Cruise | Martin | 5600000 | USA |
3 | Pandit | Prajakta | null | India |
1. Write a query to update contact information of a particular row where condition is given as, client id = 3.
UPDATE Clients
SET Contact = 34542892
WHERE Client_ID = 3 AND LAST_Name = 'Pandit';
The result is shown in the following table.
Client_ID | Last_Name | First_Name | Contact | Country |
---|
1 | Thomas | Alex | 2400000 | USA |
2 | Cruise | Martin | 5600000 | USA |
3 | Pandit | Prajakta | 34542892 | India |
2. Write a query to perform update operation on multiple fields from given table (titled as Clients) below.
Client_ID | Last_Name | First_Name | Contact | Country |
---|
1 | Thomas | Alex | 2400000 | USA |
2 | Cruise | Martin | 5600000 | USA |
3 | Pandit | Prajakta | 34542892 | India |
UPDATE Clients
SET LAST_Name = 'Brown', First_name = 'Albert', Contact = 923849, Country = 'UK'
WHERE Client_ID = 3;
The result is shown in the following table.
Client_ID | Last_Name | First_Name | Contact | Country |
---|
1 | Thomas | Alex | 2400000 | USA |
2 | Cruise | Martin | 5600000 | USA |
3 | Brown | Albert | 923849 | UK |