UPDATE Statement

The UPDATE statement is used to modify existing records in a table. You can specify which rows to update using the WHERE clause.

Examples of Using UPDATE

Scenario 1: Updating a Single Column

UPDATE FreedomFighters
SET City = 'Chennai'
WHERE Name = 'Karthick AG';

Output:

City updated successfully for Karthick AG.

Scenario 2: Updating Multiple Columns

UPDATE FreedomFighters
SET City = 'Salem', Contribution = 'Community Leader'
WHERE FighterID = 2;

Output:

City and Contribution updated successfully for FighterID 2.

Do's and Don'ts

Do's

  • Always use a WHERE clause to avoid updating all records unintentionally.
  • Back up your data before performing updates on critical tables.
  • Test your update queries on a small dataset before applying to the entire table.

Don'ts

  • Don't update primary or foreign key values without understanding the implications.
  • Don't forget to log changes when updating critical data.
  • Don't run updates on production databases without proper testing and validation.