How to Update Table in SQL?
Introduction
- UPDATE query is used to update a record in a table.
- UPDATE is a DML command, which operates on the data of the table and not on the structure of the table.
- Using UPDATE Query, one can update all the records as well as update specific records within a table.
- To update specific records within a table, UPDATE Query is used with the WHERE Clause.
- UPDATE Query to change a single record in a table
We can use an UPDATE query with the WHERE clause to change one particular column value of an entire record.
Syntax:
UPDATE TABLE_NAME SET column_name = value WHERE[condition];
Example:
First we will create a database with name “employeedb”. Then in that database we will create a table “employee” and insert records into the table. We will consider this table and database for all the subsequent examples.
mysql> USE employeedb;
Database changed
mysql> SELECT *FROM employee;
+ — — — — + — — — — — + — — — — — — +
| Emp_ID | Emp_Name | Emp_Salary |
+ — — — — + — — — — — + — — — — — — +
| 1 | Nikita | 30000 |
| 2 | Riddhi | 25000 |
| 3 | Nayan | 45000 |
| 4 | Shruti | 15000 |
| 5 | Anurati | 50000 |
+ — — — — + — — — — — + — — — — — — +
5 rows in set (0.06 sec)