MySQL – Update and Delete Records (update, delete)

Updating and Deleting records in a table is very easy. Remember that MySQL does not ask for verification of a command, and so a poorly written statement can be devastating to a database.

  • update users set column1=‘x’ where column2=’a’; – Updates ALL records where condition is true
  • update users set column1=‘x’ where column2=’a’ and column3=‘b’; – Updates ALL records where two conditions are true
  • update users set column1=‘x’, column2=‘y’ where column3=’a’ ; – Updates two columns where condition is true
  • delete from table where column=‘x’; – Deletes ALL records where the conditions is true
  • delete from table where column1=‘x’ and column2=‘y’; – Deletes ALL records where two conditions are true

Be the first to comment

Leave a Reply