|
Custom Search
| |
|
Update Statement in MySQL Update statement is used to make changes to data in one or more columns in a table. The basic UPDATE statement takes the following syntax format:
UPDATE table-name SET column1 = expression1, column2 = expression2 [,...] [WHERE criteria] [ORDER BY...] [LIMIT row_count] When creating UPDATE statement, consider the following guidelines.
Please note that, unlike other DBMS such as SQL Server, Oracle, etc., when using UPDATE, MySQL will not update columns where the new value is the
same as the old value, and as such, you may see a message that indicates 0 records are updated even though there are records that match the UPDATE criteria.
Practice #1: Update values in one column. The following update query increases the UnitPrice by 10% for all products in the Beverages category. In this query, the SET clause is based on the result of a calculation. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. UPDATE products
Query result set - 12 rows updated (not all rows are shown in the screenshot) Practice #2: Update values in two columns. The following update query increases the UnitPrice of all products in the Beverages category by 10%, and at the same time, increases product reorder level by 5 units for all the Beverage products. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. UPDATE products
Query result set - 12 rows updated (not all rows are shown in the screenshot)
Happy Coding! Other tutorials in this category 1. How to update data in a specific order in MySQL |
Copyright © 2024 GeeksEngine.com. All Rights Reserved. This website is hosted by HostGator. No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it. |
Home | Feedback | Terms of Use | Privacy Policy |