A small example of Row_count () in Mysql _mysql

Source: Internet
Author: User

Note: the Row_count () in MySQL can return the number of rows affected by the previous SQL Update,delete,insert operation.

Test on MySQL (database version: 5.1.22):

1. Create a database table:

Copy Code code as follows:

CREATE TABLE T (
ID int,
Name varchar (50),
Address varchar (100),
Primary KEY (Id,name)
) engine =innodb;

2. Insert test data:
Copy Code code as follows:

INSERT INTO T
(id,name,address)
Values
(1, ' Yubowei ', ' Weifang '),
(2, ' Sam ', ' Qingdao ');

3. Update:
Copy Code code as follows:

Update T set address = ' Weifang '
where id = 1 and name = ' Yubowei ';

View the number of rows affected at this time:
Select Row_count (); ==〉 execution result is 0;

4. Re-update:

Copy Code code as follows:

Update T set address = ' Beijing '
where id = 1 and name = ' Yubowei ';

View the number of rows affected at this time:
Select Row_count (); ==〉 execution result is 1;
From the above test can be found in MySQL only if the record is actually modified in the case, Row_count will not be able to record the number of rows affected, otherwise if the record exists but there is no actual modification will not record the update to Row_count.

Note:
Today, with prepare dynamic processing of the UPDATE statement, found that the Row_count () function returned to the 1, check the original is the Row_count () into the deallocate statement behind.
God-like me, made such a mistake, ha.

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.