有关mysql中ROW_COUNT()的小例子
mysql中的ROW_COUNT()可以返回前一个SQL进行UPDATE,DELETE,INSERT操作所影响的行数
注:mysql中的ROW_COUNT()可以返回前一个SQL进行UPDATE,DELETE,INSERT操作所影响的行数。
MySQL上的测试(数据库版本为:5.1.22):
1.创建数据库表:
代码如下:
create table t(
id int,
name varchar(50),
address varchar(100),
primary key(id,name)
)engine =InnoDB;
2.插入测试数据:
代码如下:
insert into t
(id,name,address)
values
(1,'yubowei','weifang'),
(2,'sam','qingdao');
3.更新:
代码如下:
update t set address = 'weifang'
where id = 1 and name = 'yubowei';
此时查看影响的行数:
select row_count(); ==〉执行结果为0;
4.再更新:
代码如下:
update t set address = 'beijing'
where id = 1 and name = 'yubowei';
此时查看影响的行数:
select row_count(); ==〉执行结果为1;
从上面的测试可以得出在MySQL中只有真正对记录进行修改了的情况下,row_count才会去记录影响的行数,否则如果记录存在但是没有实际修改则不会将该次更新记录到row_count中。
备注:
今天用PREPARE动态处理了UPDATE语句后,发现ROW_COUNT()函数返回的老是-1 ,检查了下原来是把row_count()放到了deallocate 语句后面了。
神一般的我,犯了这样的错,哈。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)
