LogoInterview Master

SQL Learning

SQL UPDATE Statement

What Does SQL UPDATE Do?

The UPDATE statement modifies existing data in a table. You can update one row, many rows, or even all rows — but watch out! A missing WHERE clause can cause mass updates by accident.

Basic UPDATE Syntax

UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;

Update a Single Record

-- Update a user's email
UPDATE Users
SET email = 'new_email@example.com'
WHERE user_id = 101;

Update Multiple Columns

-- Update username and email together
UPDATE Users
SET 
  username = 'new_username',
  email = 'new_email@toktuk.com'
WHERE user_id = 102;

Update All Rows (Use With Caution)

-- Set all videos to 0 views (careful!)
UPDATE Videos
SET views = 0;

⚠️ This affects every row. Always back up your data or wrap in a transaction when unsure.

Best Practices for UPDATE

  • Always include a WHERE clause unless you're intentionally updating everything
  • Preview affected rows first with a SELECT using the same condition
  • Use transactions when updating multiple related tables
  • Keep an audit trail of changes when possible
  • Validate values before updating (especially for types like dates, emails, enums)

Loading SQL editor...