Mysql 是否与 mssql 中的 @@ROWCOUNT 等效?
如何像 @@ROWCOUNT
在 mssql 中那样在 MySQL 中获取行计数值?
How can I get row count values in MySQL as @@ROWCOUNT
does in mssql?
推荐答案
对于 SELECT,您可以使用 FOUND_ROWS
构造 (此处记录):
For SELECTs you can use the FOUND_ROWS
construct (documented here):
SELECT SQL_CALC_FOUND_ROWS something FROM your_table WHERE whatever;
SELECT FOUND_ROWS( ) ;
这将返回最后一个 SELECT
查询中的行数(或者如果第一个查询有一个 LIMIT
子句,它会返回那里将有的行数没有LIMIT
).
which will return the number of rows in the last SELECT
query (or if the first query has a LIMIT
clause, it returns the number of rows there would've been without the LIMIT
).
对于UPDATE
/DELETE
/INSERT
,它是ROW_COUNT 构造
INSERT INTO your_table VALUES (1,2,3);
SELECT ROW_COUNT();
这将返回受影响的行数.
which will return the number of affected rows.
相关文章