Monday, September 12, 2011

HOW TO USE UPDATE STATEMENT SYNTAX IN SQL SERVER

The Update statement is use to update any column in a table

The syntax of update statement is

Update table_name
Set column_name ='value'
Where column_name='value'

Lets say we have a following table (table_1)


We want to change Asad raza's city from Lahore to Karachi, so for his the syntax would be

update table_1
set city='Karachi'
where firstname='asad'

so the output will be


We can also update multiple column at a same time

lets say we want to change city from Karachi to Islamabad for Muhammad Taqi & Muhammad Taqi

so for this the syntax would be

update table_1
set city='Islamabad'
where firstname='muhammad' or lastname='Taqi'

We can also use AND & OR Operator like in the above example we used OR operator

Note : If you use update statement without where clause than it will update all the record.

If you still have any confusion about update statement than please leave a comment.

No comments:

Post a Comment