Advertisements
This article is based upon UPDATE statement in SQL queries; it is used to modify the data in a table, means modify the existing data.
Syntax
UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value
Suppose we have a table "Employee":
LastName
FirstName
Address
City
Singh
Bhupendr
10, K. Road
New York
Travolta
34, mall road
Los Angeles
Update one Column in a Row
We want to add a first name to the person with a last name of "Travolta":
UPDATE Employee SET FirstName = 'John'
WHERE LastName = 'Travolta'
Result:
LastName FirstName Address City
Singh Bhupendr 10, K. Road New York
Travolta John 34, mall road Los Angeles
Update several Columns in a Row
We want to change the address and add the name of the city:
UPDATE Employee
SET Address = '4 Downhill', City = 'Hawaii'
WHERE LastName = 'Travolta'
Result:
LastName FirstName Address City
Singh Bhupendr 10, K. Road New York
Travolta John 4 Downhill Hawaii