SQL Server: Update command
In this article i will explain what is Update command and how to use Update command in SQL Server.
In previous articles i explained How to create a table in SQL Server, How to alter table column in SQL Server, How to add a column to table and How to delete a column from table in SQL Server, and How to rename a column and How to rename a table in SQL Server. Now i will explain what is Update command and how to use Update command in SQL Server.
Here i'm using Employee table.
Update command is used to update particluar records of a table. While updating records we can specify conditions in where clause. Where clause is optional.
Update <table-name> set <column-name1> = '<new-value1>', <column-name2> = '<new-value2>'
We can specify more than one column for update.
Now i'm updating all employees salaries by 1000.
update Employee set EmpSalary = EmpSalary + 1000
Now we will see another example with where clause.
Our requirement is update EmpName where EmpNo is 2.
update Employee set EmpName = 'Sagar Reddy' where EmpNo = 2
Note: In previous example 3 rows updated. Here only 1 row updated beacause we are updating based on EmpNo.
CreatedSep 21, 2013
UpdatedSep 21, 2013