The basic syntax of an UPDATE
query is:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
table_name
: The name of the table you want to update.SET
: Specifies the column(s) and the new value(s).WHERE
: The condition that identifies which rows to update. Without a WHERE
clause, all rows in the table will be updated.Let’s assume we have a table employees
and we want to update the salary of an employee with a specific employee_id
. Here’s the query:
UPDATE employees
SET salary = 60000
WHERE employee_id = 101;
In this example:
UPDATE
statement is applied to the employees
table.SET
clause changes the salary
column to 60000
.WHERE
clause ensures that only the employee with employee_id = 101
is updated.UPDATE
query modifies existing records in the table.WHERE
clause to specify which rows to update, otherwise, all rows will be updated.SET
clause.The UPDATE
query in MySQL is essential for modifying existing records. It's important to use the WHERE
clause carefully to avoid accidentally updating all rows in a table. With UPDATE
, you can efficiently modify data in a table based on specific conditions.