Saturday, March 16, 2013

How to use UPDATE Command in SQL Server

SQL Server UPDATE Command
The UPDATE is a DML command which is used to update existing records in a table, based on the condition specified in the Where Clause.
Syntax:
UPDATE Table_Name
SET Column1=Value1, Column2=Value2,...WHERE Some_Column=Some_Value

Example:

Let us consider the following 'Employee' Table.



Here from the above , we want to update the table by replacing the city "Hyderabad" with "Chennai". This can be done by using the following SQL Query.
UPDATE Employee SET City= 'Chennai" WHERE  City= 'Hyderabad"

Result:

Caution:
Be careful when updating records.If you omit the Where Clause in the above example then all the records in city column of the table are set to 'Chennai'.

Key Difference between Update and Alter Commands:

Update is a SQL command that is used to update existing records in a database, while Alter is a SQL command that is used to modify, delete or add a column to an existing table in a database.

Update is a DML statement whereas Alter is a DDL statement. Alter command modifies the database schema, while Update statement only modifies records in a database without modifying its structure.


Thanks,
TAMATAM

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.