UPDATE
Example
Section titled “Example”UPDATE employeesSET salary = 4000WHERE employeeId = 1;Output
Section titled “Output”Query OK, 1 row affected (0.04 sec)Rows matched: 1 Changed: 1 Warnings: 0Explanation
Section titled “Explanation”In the example, the UPDATE command modifies the data of one row in the ‘employees’ table. The SET clause changes the ‘salary’ value to 4000 for the row where ‘employeeId’ equals 1. The output shows that the update operation was successful, one row was matched and affected, and no warnings were issued.
Example
Section titled “Example”UPDATE customersSET email = 'new_email@example.com'WHERE customer_id = 1;Output
Section titled “Output”UPDATE 1Explanation
Section titled “Explanation”The above SQL statement updates email of the customer with customer_id 1 in the customers table to new_email@example.com. The output UPDATE 1 indicates that one row was updated successfully.
Example
Section titled “Example”UPDATE EmployeesSET LastName = 'Johnson', FirstName = 'John'WHERE EmployeeID = 1;Output
Section titled “Output”(1 row(s) affected)Explanation
Section titled “Explanation”The UPDATE statement is used to modify existing records in a table. In the above example, the SQL statement updates the Employees table to set the LastName and FirstName as ‘Johnson’ and ‘John’ respectively for the EmployeeID currently set to 1. The output shows that one row has been affected, meaning the changes have been successfully made.
Example
Section titled “Example”UPDATE employeesSET salary = 60000WHERE employee_id = 100;COMMIT;Output
Section titled “Output”1 row updated.Explanation
Section titled “Explanation”In the example query, the UPDATE statement is used to modify the records in the ‘employees’ table. Specifically, it updates the ‘salary’ column value to ‘60000’ for the row where the ‘employee_id’ is ‘100’. The COMMIT statement is used to permanently save the changes in the database.
Example
Section titled “Example”UPDATE EmployeesSET Department = 'Sales'WHERE EmployeeID = 1;Output
Section titled “Output”Query OK, 1 row affected (0.01 sec)Explanation
Section titled “Explanation”The SQL UPDATE statement changes existing records in a table. In this example, it modifies the ‘Department’ column for the employee with an ‘EmployeeID’ of 1 to ‘Sales’. The output indicates that one row was successfully affected.