In this post, you will see how the update and delete commands in MySQL work. As the name suggests, the update is used to update the records from the table according to the conditions specified. Delete is used to delete the records with specified conditions. We specify the conditions using the where clause, if we don’t specify the condition then it will update or delete all the records from the table.
Update Syntax
UPDATE table_name
SET column_name1 = value1, column_name2 = value2, ...
WHERE conditions;
Update all records
The following command will update the values of the specified columns for all the records. So it’s important to add a where clause while using the update command if you don’t want to update all the records.
UPDATE table_name
SET column_name1 = value1, column_name2 = value2,...;
Delete Syntax
DELETE FROM table_name
WHERE condition;
Delete all syntax
Like update, the following command will delete all the records in the table since no condition is defined in the where clause.
DELETE FROM table_name;