The UPDATE statement in SQL is used to modify existing records in a table. Here’s a detailed tutorial on how to use the UPDATE statement effectively.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Assume you have a table named employees with columns first_name, last_name, age, and department.
Update the age of an employee named John Doe:
UPDATE employees
SET age = 31
WHERE first_name = 'John' AND last_name = 'Doe';
2. Updating Multiple Columns
Update the age and department of an employee named Jane Smith:
UPDATE employees
SET age = 29, department = 'Sales'
WHERE first_name = 'Jane' AND last_name = 'Smith';
3. Updating All Rows
Increase the age of all employees by 1 year:
UPDATE employees
SET age = age + 1;