SQL Update Data Update

Source: Internet
Author: User
Tags mysql commands mysql query mysql update

In SQL we often want to update the data then we use the UPDATE statement, update can be updated according to your criteria, batch or single can be an instance.

Imagine that you have a MySQL table that has information for all employees in your company. The column in this table is called "seniority" and it has an integer value of how many months an employee has in your company. But unfortunately for you, your job is to update these numbers every month.


You may think you want to open your MySQL admin tool and edit each entry hand. This will take several hours. On the other hand, you can master MySQL and an automated script that you run every month to complete the task for you.

In this lesson you will learn how to replace the existing data, MySQL table fresh supply of the latest data to update the MySQL query.

For example, the MySQL update
We will again be with the data from previous examples. Sandy has just had a birthday, she is now 22 years old. Our task now is to update her age with MySQL commands like update, Setup, and location.

Update-Latest M ysql query for performance
Set-new values are placed in a subsequent set of tables
Where-the boundary and the effect of the line

<?php
Connect to MySQL

Get Sandy's record from the "example" table
$result = mysql_query ("UPDATE example SET age= ' WHERE age= ' 21 '")
Or Die (Mysql_error ());


$result = mysql_query ("SELECT * From Example WHERE age= ' 22")
Or Die (Mysql_error ());

Get the "Hopefully only" entry from
$row = Mysql_fetch_array ($result);
echo $row [' name ']. '-'. $row [' age ']. <br/> ";
?>

Output

22

It is important to note that this query will update all records of a 21-year-old new 22-Year-old. On a table Sandy is not the only entrance, which may become a problem, and more advanced solutions will be necessary www.111cn.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.