SQL update data update

Source: Internet
Author: User
Tags mysql commands mysql update

In SQL, we often want to update data, so we will use the update statement. update can be updated according to your conditions, and can be used in batches or in a single instance.

In SQL, we often want to update data so we will use the update statement,UpdateYou can update the instance according to your conditions, batch or single instance.

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


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

In this lesson, you will learn how to replace existing data and update MySQL queries with the latest data that MySQL tables provide.

For example, MySQL update
We will again associate with the data from the previous example. Sha has just had a birthday. She is now 22 years old. Our current task is to update her age using MySQL commands like update, set, and location.

Update-latest performance M ySQL Query
Set-new values are placed in the Post-sequel to the table
Where-influence of line over line

<? Php
// Connect to MySQL

// Get Sandy's record from the "example" table
$ Result = mysql_query ("UPDATE example SET age = '22' WHERE age = '21 '")
Or die (mysql_error ());


$ Result = mysql_query ("SELECT * FROM example WHERE age = '22 '")
Or die (mysql_error ());

// Get the first (and hopefully only) entry from the result
$ Row = mysql_fetch_array ($ result );
Echo $ row ['name']. "-". $ row ['age']. "<br/> ";
?>

Output

22

Now it is important to note that this query will update all records for a 21-year-old New 22-year-old. Sandground on a table is not the only portal, which may become a problem, and more advanced solutions will be necessary www.111cn.cn

Related Article

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.