The SQL UPDATE statement is used when information already stored in a database needs to be changed. Instead of creating another row, UPDATE modifies selected values in existing records. It is therefore an important SQL command for maintaining information as real-world situations change.
For example, a student's marks may need correction, an employee may move to another department, a product price may change, or a customer's contact information may be edited. All of these situations can be handled with an UPDATE query.
The most important part of an UPDATE operation is identifying the correct rows. A carefully written WHERE condition helps ensure that only the intended records are changed. Before executing a large update, it is also good practice to review the condition and understand how many rows it can affect.
UPDATE belongs to SQL's Data Manipulation Language (DML). It changes values stored in one or more columns of existing rows while leaving the table structure unchanged.
Depending on the condition supplied with the query, an UPDATE operation may affect one row, several rows, or every row in a table. The database does not automatically know which record you intended, so the condition should be written carefully.
An UPDATE statement generally contains three important components:
The WHERE clause is optional from a syntax perspective, but omitting it means that the SET operation can apply to every row in the table.
UPDATE table_name SET column_name = new_value WHERE condition;
For example, a particular student's marks can be changed using a unique StudentID:
UPDATE Student SET Marks = 87 WHERE StudentID = 101;
Only the row matching StudentID 101 is targeted by this query.
| StudentID | StudentName | Course | Marks |
|---|---|---|---|
| 101 | Rahul | BCA | 80 |
| 102 | Priya | BCA | 85 |
| 103 | Amit | MCA | 78 |
| 104 | Neha | B.Tech | 90 |
A common database task is correcting or changing one particular record. A primary key or another unique identifier is usually a good choice for locating that record.
UPDATE Student SET Marks = 88 WHERE StudentID = 101;
After execution, the marks stored for student 101 become 88. The other students remain unchanged.
| StudentID | StudentName | Marks |
|---|---|---|
| 101 | Rahul | 88 |
An UPDATE statement can intentionally affect several rows. This is useful when the same change applies to every record satisfying a particular condition.
UPDATE Student SET Course = 'BCA Advanced' WHERE Course = 'BCA';
Every student currently associated with the BCA course is changed to BCA Advanced.
This demonstrates why the WHERE condition should be checked before execution. A condition matching many rows produces a bulk update rather than a single-record update.
There is no requirement to create a separate UPDATE statement for every column. Multiple column assignments can be included in the same SET clause.
UPDATE Student
SET Course = 'MCA',
Marks = 91
WHERE StudentID = 102;
The query changes both the course and marks of the selected student.
WHERE determines which existing rows qualify for modification. It can use comparison operators, logical operators, ranges, lists, and other SQL expressions.
UPDATE Employee SET Salary = 55000 WHERE EmployeeID = 12;
Only the employee whose EmployeeID is 12 is selected.
If WHERE is not included, the SET expression applies to every row in the target table.
UPDATE Student SET Status = 'Active';
This statement assigns Active to the Status column for every row in Student. Such a query can be completely valid when the requirement really is to change all records, but it should never be executed accidentally.
Character columns such as names, departments, cities, and categories can be changed by placing the new text value inside quotes.
UPDATE Employee SET Department = 'Human Resources' WHERE Department = 'HR';
Every employee whose department value is HR is assigned the new department name.
Numbers can be assigned directly or calculated from the existing value.
UPDATE Product SET Price = 1299 WHERE ProductID = 25;
The price of product 25 is changed to 1299.
The SET clause can calculate a new value from the existing value. This is particularly useful for salary revisions, price changes, stock adjustments, and similar operations.
UPDATE Employee SET Salary = Salary * 1.10 WHERE Department = 'IT';
The existing salary of each matching IT employee is multiplied by 1.10.
UPDATE Student SET Marks = Marks + 5 WHERE Course = 'BCA';
Five marks are added to students belonging to the selected course.
Multiple conditions can be combined when a change should apply only to a narrower group of records.
UPDATE Employee SET Bonus = 10000 WHERE Department = 'IT' AND Experience > 5;
The bonus is assigned only to IT employees whose experience is greater than five years.
OR can be used when more than one condition should qualify a row.
UPDATE Student SET Status = 'Eligible' WHERE Marks >= 75 OR Attendance >= 80;
A student is marked Eligible when either condition is satisfied.
IN is useful when several known values should be matched without writing a long series of OR conditions.
UPDATE Student SET Status = 'Selected' WHERE StudentID IN (101, 103, 104);
Only the three listed students are selected for the update.
BETWEEN can be used when a condition applies to values inside a specified range.
UPDATE Employee SET Bonus = 5000 WHERE Salary BETWEEN 30000 AND 50000;
Employees whose salary falls within the specified range receive the assigned bonus.
SQL uses NULL to represent the absence of a value. NULL should be tested with IS NULL rather than the normal equality operator.
UPDATE Employee SET Department = 'Unassigned' WHERE Department IS NULL;
Only rows where Department currently contains NULL are modified.
An existing value can also be cleared by assigning NULL, provided the column allows NULL values.
UPDATE Customer SET AlternatePhone = NULL WHERE CustomerID = 105;
Date or timestamp columns can also be modified. The exact literal format and functions may differ between database systems, so the syntax should be checked for the SQL platform being used.
UPDATE Employee SET JoiningDate = '2026-07-15' WHERE EmployeeID = 8;
The joining date for the selected employee is changed to the specified date.
CASE is useful when different rows need different new values based on conditions. Instead of executing several UPDATE statements, a single statement can contain conditional logic.
UPDATE Student
SET Grade =
CASE
WHEN Marks >= 90 THEN 'A'
WHEN Marks >= 75 THEN 'B'
WHEN Marks >= 60 THEN 'C'
ELSE 'D'
END;
The database evaluates the student's marks and assigns a corresponding grade.
A subquery can be used when the new value or selection condition depends on information calculated from another query.
UPDATE Employee
SET Salary =
(
SELECT AVG(Salary)
FROM Employee
)
WHERE Department = 'Training';
The example assigns the calculated overall average salary to employees in the Training department. Actual production queries should be designed carefully when the source and target data come from the same table.
In applications containing related tables, an update may depend on information stored somewhere else. The exact syntax for this operation varies between database systems.
UPDATE Employee AS E INNER JOIN Department AS D ON E.DepartmentID = D.DepartmentID SET E.Location = D.Location;
This example copies the department location into the corresponding employee records.
UPDATE JOIN syntax is not identical across all SQL products. For portable applications, developers should use the syntax supported by their particular database system.
EXISTS can be useful when rows should be changed only if a related record is present.
UPDATE Customer AS C
SET C.Status = 'Active'
WHERE EXISTS
(
SELECT 1
FROM Orders AS O
WHERE O.CustomerID = C.CustomerID
);
The idea behind this query is to activate customers for whom at least one related order exists.
An empty string and NULL are not necessarily the same thing. If a column contains an empty string, it can be searched using an equality condition.
UPDATE Customer SET Email = 'Not Provided' WHERE Email = '';
This changes empty email strings to the specified placeholder text.
Suppose an employee receives a promotion and needs a new job designation.
UPDATE Employee SET Designation = 'Senior Developer' WHERE EmployeeID = 20;
The query changes the designation for the selected employee without creating a new employee record.
A college system may need to correct marks after verification.
UPDATE Student SET Marks = 92 WHERE StudentID = 205;
The marks stored for student 205 are replaced with the corrected value.
An online store may update inventory after receiving a shipment.
UPDATE Product SET Stock = Stock + 100 WHERE ProductID = 40;
The existing stock is increased by 100 units.
A banking application may need to update an account's status after a defined period of inactivity.
UPDATE Account SET Status = 'Inactive' WHERE LastTransactionDate < '2025-01-01';
The condition selects accounts whose recorded last transaction date is earlier than the specified date.
A hospital application may update a patient's assigned doctor after a scheduling change.
UPDATE Patient SET DoctorID = 18 WHERE PatientID = 302;
The doctor reference for the selected patient is changed.
When several related modifications must succeed together, transactions can provide an important layer of control. A transaction allows changes to be committed as a unit or rolled back when the operation needs to be cancelled.
START TRANSACTION; UPDATE Account SET Balance = Balance - 1000 WHERE AccountID = 101; UPDATE Account SET Balance = Balance + 1000 WHERE AccountID = 202; COMMIT;
This example represents the two sides of a simple transfer. Transaction behavior and syntax can vary between database engines and storage configurations.
ROLLBACK is used to undo changes that belong to an active transaction and have not yet been committed.
START TRANSACTION; UPDATE Account SET Balance = Balance - 500 WHERE AccountID = 101; ROLLBACK;
The uncommitted update is cancelled when the transaction is rolled back.
COMMIT confirms the changes made within a transaction.
START TRANSACTION; UPDATE Student SET Marks = 95 WHERE StudentID = 101; COMMIT;
After the transaction is successfully committed, the change becomes part of the database state according to the database system's transaction rules.
A useful safety practice is to first run a SELECT query using the same WHERE condition that will later be used by UPDATE.
SELECT * FROM Employee WHERE Department = 'IT' AND Experience > 5;
UPDATE Employee SET Bonus = 10000 WHERE Department = 'IT' AND Experience > 5;
This approach makes it easier to verify which rows are going to be affected before changing their values.
Database tools and application APIs commonly provide the number of rows affected by an UPDATE operation. Reviewing this information can help detect unexpected results, especially during bulk changes.
For example, if an operation was expected to modify five rows but the database reports several thousand affected rows, the query should be investigated before proceeding with further work.
Updating a large number of rows can require substantial database resources. The engine may need to locate qualifying records, modify data pages, maintain indexes, and enforce constraints or triggers.
For this reason, large update operations should be planned rather than executed blindly.
Indexes can help the database locate rows that satisfy a WHERE condition. However, indexes also have a maintenance cost because changing indexed column values may require corresponding index updates.
Therefore, indexes should be designed according to the overall workload rather than being added automatically to every column used in UPDATE statements.
| UPDATE | INSERT |
|---|---|
| Changes existing rows. | Adds new rows. |
| Modifies stored column values. | Creates a new record. |
| Can target rows with WHERE. | Usually supplies values for a new row. |
| Does not normally increase the row count. | Normally increases the row count. |
| UPDATE | DELETE |
|---|---|
| Changes values in existing rows. | Removes selected rows. |
| The row continues to exist. | The selected row is removed from the table. |
| Used for modification or correction. | Used when records are no longer required. |
| UPDATE | ALTER TABLE |
|---|---|
| Changes data stored in rows. | Changes the structure of a table. |
| Used for DML operations. | Used for DDL operations. |
| Can modify column values. | Can add, remove, or modify columns depending on the database system. |
UPDATE Student SET Marks = 100;
This statement targets every row. It should only be used when changing all records is genuinely intended.
A syntactically correct UPDATE can still produce incorrect results if its WHERE condition identifies the wrong records. Always inspect the condition before execution.
The value assigned to a column should be compatible with its definition. Database systems may reject incompatible values or convert them according to their rules.
Primary keys, foreign keys, CHECK constraints, NOT NULL restrictions, triggers, and other database rules may affect whether an UPDATE succeeds.
Bulk updates should be tested carefully. A SELECT statement using the same condition is a simple way to inspect the intended target set.
UPDATE is a DML statement used to modify values in existing database rows.
UPDATE table_name SET column_name = value WHERE condition;
SET specifies the columns and new values that should be assigned.
WHERE identifies the rows that should be modified.
The UPDATE operation can affect every row in the target table.
Yes. Multiple column assignments can be written in the SET clause.
Yes. Every row satisfying the WHERE condition can be updated.
Yes. Existing values can be used in expressions such as Salary = Salary * 1.10.
Yes. Logical operators can be used in the WHERE condition.
Yes. IN can select rows whose values match any value in a specified list.
Yes. BETWEEN can select values within a specified range.
IS NULL is normally used to identify NULL values.
Yes. CASE can assign different values according to different conditions.
Yes. Subqueries can supply values or conditions depending on the database system and query design.
Yes, although the syntax differs among SQL database products.
Yes. UPDATE is commonly classified as a Data Manipulation Language command.
A bulk UPDATE is an operation that modifies multiple rows as part of one statement or operation.
COMMIT confirms changes made within a transaction.
ROLLBACK cancels uncommitted changes in an active transaction.
Yes. Large updates may consume CPU, memory, storage, locking, and transaction resources.
Preview the target rows, use an accurate WHERE condition, test the statement, and use a transaction when appropriate.
No. UPDATE changes values in existing rows.
No. UPDATE changes data values, whereas commands such as ALTER TABLE are used for structural changes.
Yes, provided the column permits NULL values.
UPDATE is a fundamental SQL operation used in database applications, practical projects, examinations, and technical interviews.
| Concept | Important Point |
|---|---|
| UPDATE | Changes values in existing rows. |
| SET | Specifies the new column values. |
| WHERE | Selects the rows to modify. |
| CASE | Supports condition-based assignments. |
| Subquery | Can supply values or conditions for an update. |
| JOIN | Can be used for updates involving related tables, depending on the SQL dialect. |
| COMMIT | Confirms transaction changes. |
| ROLLBACK | Reverses uncommitted transaction changes. |
| Bulk Update | Modifies multiple qualifying rows. |
The SQL UPDATE statement provides a direct way to keep existing database information current. It can be used for a small correction in one row, a controlled change across several records, or a larger business operation involving expressions, CASE logic, related tables, and transactions.
The most important skill when working with UPDATE is not simply remembering its syntax. A reliable database developer should understand which rows are being targeted, what values will be assigned, how many records may change, and whether the operation should be protected by a transaction or recovery plan.
Once the basic UPDATE syntax is understood, learners can gradually move toward more advanced operations such as conditional updates, subqueries, UPDATE JOIN techniques, transaction handling, and large-scale data maintenance.