UPDATE Statement
The UPDATE
statement is used to modify the data values for particular record in the table.
Syntax:
UPDATE table_name SET column1=value,
column2=value2,...
WHERE some_column=some_value
WHERE some_column=some_value
Note: ‘WHERE’ Clause in Update command to be must. That WHERE
Clause specifies which record
or records that should be
updated. Without WHERE Clause all records of table to be modified.
Example:
The
Table “Contact” has following data,
ID
|
NAME
|
DESIGNATION
|
CITY
|
MOBILE
|
1
|
venkat
|
CEO
|
Kodambakkam
|
999989845
|
2
|
Santhosh
|
manager
|
Puddukottai
|
9999898978
|
3
|
Kousilaya
|
Asst.manager
|
Trichy
|
9659315754
|
4
|
Ananth
|
CEO
|
Chennai
|
9999999945
|
5
|
Sajil
|
MD
|
Surandai
|
6677888997
|
If we want to change designation of employee “Ananth” as
Developer and mobile-9698958775, we use following syntax,
UPDATE contact SET Designation=’Developer’,
Mobile=9698958775 WHERE Name=’Ananth’
The Result-Set is,
ID
|
NAME
|
DESIGNATION
|
CITY
|
MOBILE
|
1
|
venkat
|
CEO
|
Kodambakkam
|
999989845
|
2
|
Santhosh
|
manager
|
Puddukottai
|
9999898978
|
3
|
Kousilaya
|
Asst.manager
|
Trichy
|
9659315754
|
4
|
Ananth
|
Developer
|
Chennai
|
9698958775
|
5
|
Sajil
|
MD
|
Surandai
|
6677888997
|
Note: SQL Not Case-Sensitive and Varchar datatype should be
enclosed with single quote.
If we omit the WHERE Clause in the above command like,
UPDATE contact SET Designation=’Developer’,
Mobile=9698958775
The Result-set is,
ID
|
NAME
|
DESIGNATION
|
CITY
|
MOBILE
|
1
|
venkat
|
Developer
|
Kodambakkam
|
9698958775
|
2
|
Santhosh
|
Developer
|
Puddukottai
|
9698958775
|
3
|
Kousilaya
|
Developer
|
Trichy
|
9698958775
|
4
|
Ananth
|
Developer
|
Chennai
|
9698958775
|
5
|
Sajil
|
Developer
|
Surandai
|
9698958775
|
No comments:
Post a Comment