SQL UPDATE Statement
SQL UPDATE statement is used to update or modify existing record(s) in a database table.
Make sure that while using UPDATE statements always remember WHERE conditions, else it will update all records in a table and you will be in trouble. This is very common mistake done by database users but impact can be very high.
SET columnName1 = value1, columnName2 = value2, …columnNameN=valueN
We will consider one example from Student table and try to update country from USA to Brazil where roll number is 1005. Please refer below SQL query for the same.
UPDATE Student SET Country = 'Brazil' WHERE RollNumber = 1005 GO
As you can see in above figure, we have first selected student table where roll number is 1005 whose country is USA. In second query we have updated same record to country equals to Brazil and again selected that record and it is updated to Brazil successfully.
We can also update multiple columns at the same time as given below.
UPDATE Student SET FirstName = 'Bruce', Country = 'Algeria' WHERE RollNumber = 1012
Here we have updated two columns FirstName and Country. As you can see in the query we can update multiple columns by separating comma in the same query.
Reference: Manzoor Siddiqui [www.SQLServerLog.com]