How To Update The Details In A Table

We may have a requirement where the existing data in MYSQL table needs to be modified. We can do so by using the SQL UPDATE command. This will modify any field value of any MYSQL table. We can use the Update statement to change column values of a single row, a group of rows, Or all rows in a table.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
UPDATE table_name SET field1= New-value1, Field2 = New-value2 [WHERE Clause]
UPDATE table_name SET field1= New-value1, Field2 = New-value2 [WHERE Clause]
UPDATE table_name SET field1= New-value1, Field2 = New-value2 [WHERE Clause]

First, specify the table name that we want to update data after after the UPDATE keyword.

second, the SET clause specifies which column that we want to modify and the new values. To update multiple columns, we use a list comma-separated assignments. We supply the value in each column’s assignments in the form of a literal value, an expression, or a subquery.

Example:-

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Update products set quantity = 10
Update products set quantity = 10
Update products set quantity = 10

Will update the quantity column of all the rows.

For updating a specific set of rows, the WHERE clause is so important that we should not forget. Sometimes, we may want to change just one row; However, we may forget the WHERE clause and accidentally updates all the rows in the table.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
update products set price=450 where productid=1003,
update products set price=450 where productid=1003,
update products set price=450 where productid=1003,

Will update the price of the products which has the productid, 1003.

Now Execute the above query and click on he Browse tab,