Updating multiple columns in mysql

6854933580_2c8b688306_z

The UPDATE statement requires a few items of information in order to operate.

Firstly, it needs the name of the table that is to be updated.

This chapter builds on that material to go into more detail on several areas of SQL implemented by My SQL.

It discusses how to refer to elements of databases, including the rules for naming and the case sensitivity constraints that apply.

The dominant factor in the time taken to complete the overall operation tends to be the “admin” work in conveying the application’s intention to the database server rather than the actual updates to the database.

A more effective solution to this problem is to attempt to reduce the number of UPDATE statements.

Finally, it needs information about which specific rows are to be updated (controlled by the WHERE keyword).Fluency with SQL is necessary for effective communication with the My SQL server, because that is the language that it understands.For example, when you use a program such as the mysql client, it functions primarily as a means for you to send SQL statements to the server to be executed.Let us start with a simple table: UPDATE staff SET salary = 1200 WHERE name = ' Bob'; UPDATE staff SET salary = 1200 WHERE name = ' Jane'; UPDATE staff SET salary = 1200 WHERE name = ' Frank'; UPDATE staff SET salary = 1200 WHERE name = ' Susan'; UPDATE staff SET salary = 1200 WHERE name = ' John'; UPDATE staff SET salary = 1200 WHERE name = ' Bob'; UPDATE staff SET salary = 1250 WHERE name = ' Jane'; UPDATE staff SET salary = 1200 WHERE name = ' Frank'; UPDATE staff SET salary = 1250 WHERE name = ' Susan'; UPDATE staff SET salary = 1200 WHERE name = ' John'; We are no longer setting all the salary fields to the same value, so we can’t collapse it into a single statement.But we can group the updates according to the value being set, and then do one UPDATE statement per distinct value.For example, operations to be performed from the command line.

You must have an account to comment. Please register or login here!