TRENDING TOPICS

×

SQL UPDATE Query

SQL UPDATE clause is used to update OR change any existing data in the table through UPDATE query.

UPDATE query is basically used to modify the existing records in a table with the WHERE condition. The UPDATE query command update the selected rows through the WHERE condition only, otherwise all the rows would be affected.

SQL UPDATE Query Syntax

UPDATE table_name
SET column_1 = value_1, column_2 = value_2, ....
WHERE condition;
  • Update records in a table very carefully.
  • The WHERE condition is used to specifies which record(s) that would be going update.
  • If you are appling WHERE condition then, all records in the table will be updated.

Employee Table

A sample of EMPLOYEE records table & the name of table Employee. The column(s) of the Employee table [ID, EMPLOYEE_NAME, EMPLOYEE_EMAIL, ADDRESS, CITY, and COUNTRY]:

ID EMPLOYEE_NAME EMPLOYEE_EMAIL ADDRESS CITY COUNTRY
1 Mark J. mark@gmail.com House 53, Sq. London U.K.
2 Lack Josh lackjosh@gmail.com 2745 road mark Delhi India
3 Kim Juhu kimjuhu@gmail.com Street 587327, 34 House Seoul South Korea
4 Jack Jenifer jenifer@gmail.com 464673 Mataderos Mexico D.F. Mexico
5 McKinley mckinley@gmail.com 54, Road Washington Washington U.S.
6 Alena aln@gmail.com House No. 6563 Tokyo Japan Japan
7 Mack Marina mmk@gmail.com 43 Road, NH San Francisco U.S.
8 Dipak Jha jha@gmail.com Mahanager, 26 Road Lucknow India

UPDATE Query with WHERE condition

UPDATE Employee
SET EMPLOYEE_NAME = 'Minakshi Kapoor', EMAIL = 'minakshi@gmail.com
WHERE ID = 2;

Result Look Like

ID EMPLOYEE_NAME EMPLOYEE_EMAIL ADDRESS CITY COUNTRY
1 Mark J. mark@gmail.com House 53, Sq. London U.K.
2 Minakshi Kapoor minakshi@gmail.com 2745 road mark Delhi India
3 Kim Juhu kimjuhu@gmail.com Street 587327, 34 House Seoul South Korea
4 Jack Jenifer jenifer@gmail.com 464673 Mataderos Mexico D.F. Mexico
5 McKinley mckinley@gmail.com 54, Road Washington Washington U.S.
6 Alena aln@gmail.com House No. 6563 Tokyo Japan Japan
7 Mack Marina mmk@gmail.com 43 Road, NH San Francisco U.S.
8 Dipak Jha jha@gmail.com Mahanager, 26 Road Lucknow India

UPDATE Query without WHERE condition

If you want to modify the EMPLOYEE_NAME and EMPLOYEE_EMAIL column values in the Employee table without using WHERE condition, then UPDATE query full the same values for all. You can see the following table:

UPDATE Employee
SET EMPLOYEE_NAME = 'Minakshi Kapoor', EMAIL = 'minakshi@gmail.com;

Result Look Like

ID EMPLOYEE_NAME EMPLOYEE_EMAIL ADDRESS CITY COUNTRY
1 Minakshi Kapoor minakshi@gmail.com House 53, Sq. London U.K.
2 Minakshi Kapoor minakshi@gmail.com 2745 road mark Delhi India
3 Minakshi Kapoor minakshi@gmail.com Street 587327, 34 House Seoul South Korea
4 Minakshi Kapoor minakshi@gmail.com 464673 Mataderos Mexico D.F. Mexico
5 Minakshi Kapoor minakshi@gmail.com 54, Road Washington Washington U.S.
6 Minakshi Kapoor minakshi@gmail.com House No. 6563 Tokyo Japan Japan
7 Minakshi Kapoor minakshi@gmail.com 43 Road, NH San Francisco U.S.
8 Minakshi Kapoor minakshi@gmail.com Mahanager, 26 Road Lucknow India

© 2021 GDATAMART.COM (All Rights Reserved)