Thursday 15 December 2011

SQL Update

The UPDATE statement is used to update existing records in a table.


SQL UPDATE Syntax

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

SQL Update Example

The "Custmast" table:

custcode
custname
city
qty
rate
1
Siva
Srivilliputtur
50
70
2
Bala
Sivakasi
30
56
3
Kanna
Madurai
100
200
4
Vijay
Chennai
30
30
5
Kodee
Srivilliputtur
60
30
5
Kodee
Rajapalayam
60
30

Now we want to update the person "Siva" in the "custmast" table.

Example 1: 

Update CustMast Set City='Virudhunagar' Where custcode=1 


Output :

custcode
custname
city
qty
rate
1
Siva
Virudhunagar
50
70

Example 2:

UPDATE custmast
SET custcode=6
WHERE CustName='Kodee' AND City='Rajapalayam'

Select * from custmast

Output : 

custcode
custname
city
qty
rate
1
Siva
Virudhunagar
50
70
2
Bala
Sivakasi
30
56
3
Kanna
Madurai
100
200
4
Vijay
Chennai
30
30
5
Kodee
Srivilliputtur
60
30
6
Kodee
Rajapalayam
60
30

No comments:

Post a Comment


”Back