Back to course

Modifying Existing Data (UPDATE)

Database Fundamentals: From Zero to Hero

Lesson 21: Modifying Existing Data (UPDATE)

The UPDATE statement is used to change the data in existing rows of a table.

The Critical Role of the WHERE Clause

The UPDATE command is extremely powerful and dangerous. If you omit the WHERE clause, you will modify ALL records in the table.

Basic Syntax

sql UPDATE [table_name] SET [column1] = [new_value1], [column2] = [new_value2], ... WHERE [condition];

Example 1: Updating a Single Record

Update Jane Smith's email address using her unique Primary Key (CustomerID = 5).

sql UPDATE Customers SET Email = 'jane.s_new@example.com' WHERE CustomerID = 5;

Example 2: Updating Multiple Records

Give all employees in the 'Sales' department a 10% bonus.

sql UPDATE Employees SET Salary = Salary * 1.10 WHERE Department = 'Sales';

Notice how we perform a calculation (Salary * 1.10) directly within the SET clause.