SQL UPDATE Statement
SQL UPDATE Syntax
UPDATE
table_name SET column1=value, column2=value2,... WHERE some_column=some_value
|
SQL UPDATE Example
“Persons” TABLE:
P_Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Suhail
|
Osmani
|
Maharaj
Nagar
|
Sitapur
|
2
|
Maxwel
|
Tom
|
Biswan
|
Sitapur
|
3
|
Rahi
|
Ayon
|
Okhla
|
Delhi
|
4
|
Nyla
|
Johan
|
Bakken
2
|
Delhi
|
5
|
Thoria
|
Jakob
|
|
|
We use the following SQL statement:
UPDATE
Persons SET Address='New Road', City='Sitapur' WHERE LastName='Thoria' AND FirstName='Jakob'
|
P_Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Suhail
|
Osmani
|
Maharaj
Nagar
|
Sitapur
|
2
|
Maxwel
|
Tom
|
Biswan
|
Sitapur
|
3
|
Rahi
|
Ayon
|
Okhla
|
Delhi
|
4
|
Nyla
|
Johan
|
Bakken
2
|
Delhi
|
5
|
Thoria
|
Jakob
|
New
Road
|
Sitapur
|
SQL UPDATE Warning
Be careful when updating records. If we had omitted the WHERE clause in the example above, like this:
UPDATE
Persons
SET Address='New Road', City='Sitapur' |
P_Id
|
LastName
|
FirstName
|
Address
|
City
|
1
|
Suhail
|
Osmani
|
New
Road
|
Sitapur
|
2
|
Maxwel
|
Tom
|
New
Road
|
Sitapur
|
3
|
Rahi
|
Ayon
|
New
Road
|
Sitapur
|
4
|
Nyla
|
Johan
|
New
Road
|
Sitapur
|
5
|
Thoria
|
Jakob
|
New
Road
|
Sitapur
|
|
|
|
|
|
SQL UPDATE Statement
Reviewed by Admin
on
04:11:00
Rating:
No comments: