BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

UPDATE Query in SQL

Last Updated: September 10, 2022 by Chaitanya Singh | Filed Under: SQL

Update Query is used for updating existing rows(records) in a table. In last few tutorials we have seen how to insert data in table using INSERT query and how to fetch the data using SELECT Query and Where clause. What if we want to update an exiting record? this is where update query comes into picture. Using this we can update any number of rows in a table.

Syntax

UPDATE TableName
SET column_name1 = value, column_name2 = value....
WHERE condition;

Query would update only those rows that satisfy the condition defined in where clause.

Example

EMPLOYEES table:

+------+----------+---------+----------+
|SSN   | EMP_NAME | EMP_AGE |EMP_SALARY|
+------+----------+---------+----------+
|  101 | Steve    |  23     |  9000.00 |
|  223 | Peter    |  24     |  2550.00 |
|  388 | Shubham  |  19     |  2444.00 |
|  499 | Chaitanya|  29     |  6588.00 |
|  589 | Apoorv   |  21     |  1400.00 |
|  689 | Rajat    |  24     |  8900.00 |
|  700 | Ajeet    |  20     | 18300.00 |
+------+----------+---------+----------+

Update the salary of employees to 10000 if they are having age greater than 25.

SQL> UPDATE EMPLOYEES
SET EMP_SALARY = 10000
WHERE EMP_AGE > 25;

Updated EMPLOYEES table would look like this:

+------+----------+---------+----------+
|SSN   | EMP_NAME | EMP_AGE |EMP_SALARY|
+------+----------+---------+----------+
|  101 | Steve    |  23     |  9000.00 |
|  223 | Peter    |  24     |  2550.00 |
|  388 | Shubham  |  19     |  2444.00 |
|  499 | Chaitanya|  29     | 10000.00 |
|  589 | Apoorv   |  21     |  1400.00 |
|  689 | Rajat    |  24     |  8900.00 |
|  700 | Ajeet    |  20     | 18300.00 |
+------+----------+---------+----------+

As you can see that only one employee is there in table above the age of 25. The salary for the employee got updated to 10000.

Update the salary of employee “Apoorv” to 120000.

SQL> UPDATE EMPLOYEES
SET EMP_SALARY = 120000
WHERE EMP_NAME = 'Apoorv';

Output:

+------+----------+---------+----------+
|SSN   | EMP_NAME | EMP_AGE |EMP_SALARY|
+------+----------+---------+----------+
|  101 | Steve    |  23     |  9000.00 |
|  223 | Peter    |  24     |  2550.00 |
|  388 | Shubham  |  19     |  2444.00 |
|  499 | Chaitanya|  29     | 10000.00 |
|  589 | Apoorv   |  21     | 12000.00 |
|  689 | Rajat    |  24     |  8900.00 |
|  700 | Ajeet    |  20     | 18300.00 |
+------+----------+---------+----------+

Top Related Articles:

  1. SQL – DROP Table Statement to delete the entire table
  2. SQL WHERE Clause
  3. DELETE Query in SQL
  4. SQL NULL Check in Where clause – IS NULL and IS NOT NULL
  5. SQL SELECT Database – USE Statement

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

SQL Tutorial

  • SQL Tutorial
  • SQL Introduction
  • SQL Syntax
  • SQL Data Types

SQL Database

  • SQL CREATE DB
  • SQL DROP DB
  • SQL Rename DB
  • SQL USE DB

SQL Queries

  • SQL Select
  • SQL Select Distinct
  • SQL Select Count
  • SQL Select Top
  • SQL Where
  • SQL AND, OR & NOT
  • SQL Order By
  • SQL Insert Into
  • SQL Insert Into SELECT
  • SQL Select Random
  • SQL Alias
  • SQL NULL Check
  • SQL Update
  • SQL Delete
  • SQL MIN, MAX
  • SQL SUM
  • SQL AVG

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap