SQL UPDATE Statement
Syntax
The UPDATE statement in SQL is used to modify data in one or more rows of a table. The SET clause specifies the columns to update, and the WHERE clause limits the rows affected.
-- Update specific rowsUPDATE table_nameSET column1 = value1, column2 = value2WHERE condition;
-- Update all rows (use cautiously)UPDATE table_nameSET column1 = value1;Example
-- Update a specific rowUPDATE employeesSET age = 35WHERE name = 'John Doe';/* Updates:| id | name | department | age ||----|------------|------------|-----|| 1 | John Doe | Sales | 35 |*/
-- Update multiple rowsUPDATE employeesSET department = 'General'WHERE age > 30;/* Updates:| id | name | department | age ||----|------------|------------|-----|| 1 | John Doe | General | 35 || 3 | Alice Brown| General | 40 |*/
-- Update all rowsUPDATE employeesSET department = 'Unknown';/* Updates all rows:| id | name | department | age ||----|------------|------------|-----|| 1 | John Doe | Unknown | 35 || 2 | Jane Smith | Unknown | 25 || 3 | Alice Brown| Unknown | 40 |*/