The SQL UPDATE Query is used to modify the existing records in a table. You can use WHERE clause with UPDATE query to update selected rows, otherwise all the rows would be affected.
Syntax: The basic syntax of UPDATE query with WHERE clause is as follows:
UPDATE table_name SET column1 = value1, column2 = value2…., columnN = valueN WHERE [condition];
You can combine N number of conditions using AND or OR operators.
Example: Consider the DEPT table having the following records:
deptno | dname | location |
10 | Accounting | New York |
20 | Research | Dallas |
30 | Sales | Chicago |
40 | Operations | Boston |
Following is an example, which would update location for a dname whose deptno is 10:
UPDATE DEPT SET LOCATION = 'India' WHERE DEPTNO = 10;
Now, DEPT table would have the following records:
deptno | dname | location |
10 | Accounting | India |
20 | Research | Dallas |
30 | Sales | Chicago |
40 | Operations | Boston |