web training room for online courses
Online Training for Asp.net MVC Web Designing Development, MS SQL, Digital Marketing

SQL Update Query Example

How to update record in SQL database table

SQL UPDATE Query is used to update / modify the existing records in any SQL table. You can use the WHERE clause (if you want to update any specific record) with the UPDATE , if there is no Where Clause specified then all the rows would be affected.

UPDATE sqlTablename
SET column1 = value1,
    column2 = value2
WHERE [condition];

Let’s assume we have some customer data in below customer table, and we want to update one particular record

tbCustomer
--+----+----------+-----+-----------+----------+-------
| Id | Name     | Code |   City         |   Mobile    |
+----+----------+-----+-----------+----------+---------
|  1 | Ajit     |  0112 | Mumbai        |  9819014758 |
|  2 | Ropesh   |  0247 | Delhi         |  7852147458 |
|  3 | Aniket   |  0142 | Kolkata       |  8852414758 |
|  4 | Brinda   |  0235 | Pune          |  9952504758 |
|  5 | Aman     |  0478 | Raipur        |  9652114758 |
|  6 | Kajal    |  0268 | Goa           |  9452565758 |
|  7 | Purnendu |  1403 | Bangalore     |  9652727538 |
+----+----------+-----+-----------+----------+--------

Now we write a query to update mobile number of a particular customer.
let's look at the query.

SQL Syntax
Update tbCustomer
set Mobile='8054069773'
where Code=0112

After executing the above query, if you again check the data in table, you will see one record has been updated

tbCustomer
--+----+----------+-----+-----------+----------+-----
| Id | Name     | Code |   City   |       Mobile   |
+----+----------+-----+-----------+----------+------
|  1 | Ajit     |  0112 | Mumbai        |  8054069773 |
|  2 | Ropesh   |  0247 | Delhi         |  7852014758 |
|  3 | Aniket   |  0142 | Kolkata       |  8852104758 |
|  4 | Brinda   |  0235 | Pune          |  9954254758 |
|  5 | Aman     |  0478 | Raipur        |  9652014758 |
|  6 | Kajal    |  0268 | Goa           |  9452605758 |
|  7 | Purnendu |  1403 | Bangalore     |  9652720758 |
+----+----------+-----+-----------+----------+--------

Note: if you don’t specify where clause all the data in that table will be updated, so be careful before executing any update statement in SQL


Comment
Name Email Website
Subscribe
 
SQL Update Query Example

Consulting