Update set usage of MySQL updated data

Source: Internet
Author: User

Update syntax

The code is as follows Copy Code

UPDATE [low_priority] [IGNORE] Tbl_name
SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE Where_definition]
[Order BY ...]
[LIMIT Row_count]

Instance

The code is as follows Copy Code

CREATE table links (name varchar (255) NOT null default ", URL varchar (255) NOT NULL default");

Let's just insert some data.

The code is as follows Copy Code

INSERT into the users (name, age) VALUES (' Yao Ming ', 25), (' Bill Gates ', 50), (' Martians ', 600);

Update All records

The code is as follows Copy Code

Update links set url= ' http://www.111cn.net ';

The above update is the entire data table URL value is clay written to http://www.111cn.net, so it is certainly not suitable for the current generation of data development,

The code is as follows Copy Code


Update user Set Password = Password (' 123456 ') where user = ' root ';

The above can be updated with some data according to the condition, so that we can update it according to the next where condition.


Here's a way to share a PHP to update a specified record in the MySQL database

  code is as follows copy code

<?php
$con = mysql_connect ("localhost", "Peter", "abc123");
if (! $con)
{
  die (' could not connect: '. Mysql_error ());
}
mysql_select_db ("my_db", $con);
mysql_query ("UPDATE Persons SET age = ' = '
WHERE FirstName = ' Peter ' and LastName = ' Griffin '");
Mysql_close ( $con);
?

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.