MySQL returns test examples that affect the number of rows

Source: Internet
Author: User
Tags create database

Found_rows (): Select

Row_count (): UPDATE Delete Insert

Note: You need to work with the appropriate operation, otherwise the value returned is only 1 and 1 (all incorrect values)

Example:

Drop database if exists ' mytest ';

Create database ' mytest ';

Use ' mytest ';

drop table if exists ' mytesttable ';

CREATE TABLE ' mytesttable ' (' ID ' int, ' Name ' varchar (10));

Insert INTO ' mytesttable ' (' ID ', ' Name ')

Select ' 1 ', ' role1 ' UNION ALL

Select ' 2 ', ' Role2 ' UNION ALL

Select ' 3 ', ' role3 ';

Select Row_count (); --Output 3 (returns the number of newly added records), [Note: If you use Insert into...values only return 1]

SELECT * from ' mytesttable '; select Found_rows (); --Output 3 (returns the number of rows selected)

Update ' mytesttable ' set ' Name ' = ' people '; select Row_count (); --Output 3 (returns the number of rows modified)

Delete from ' mytesttable '; select Row_count (); --Output 3 (returns the number of rows deleted)

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.