MySQL UPDATE

The UPDATE statement is used to modify existing records in a table. It can be used to update one or multiple records.

Example with Tamil Kings

1. Updating a Single Record

UPDATE tamil_kings_auto_increment
SET reign_period = '985–1015 CE'
WHERE king_name = 'Raja Raja Chola';

Code Explanation: This command updates the reign_period of 'Raja Raja Chola' to '985–1015 CE' in the tamil_kings_auto_increment table.

Best Practices

  • Always use the WHERE clause to avoid updating all records by mistake.
  • Back up data before performing updates on important tables.

Key Takeaways

  • The UPDATE statement modifies data in existing records.
  • Always use the WHERE clause to target specific records.