mysql 如何输出 auto_increment 计数器值 [英] mysql how to output the auto_increment counter value

查看:45
本文介绍了mysql 如何输出 auto_increment 计数器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在表中插入一条记录时,auto_increment 字段的值可能是 1000,我知道有一个 auto_increment 计数器,决定了这个值.

When i insert a record into a table, the auto_increment field 's value maybe 1000, I know there is a auto_increment counter, deciding the value.

我使用命令:

SHOW VARIABLES LIKE 'auto_incre%'

输出:

auto_increment_increment    1
auto_increment_offset   1

所以我只想知道,是否有一种方法可以用来检查 auto_increment 计数器值.感谢您的帮助.

so I just want to know, if there is a way i can use to check the auto_increment counter value. Thanks for any help.

推荐答案

SHOW TABLE STATUS LIKE 'table_name'

为您提供 Auto_increment 列.这是将在 INSERT 中添加的下一个值(通常是 id).

Gives you the column as Auto_increment. This is the next value (often id) which will be added on INSERT.

示例:

$str_table = 'users';

$query = mysql_query("SHOW TABLE STATUS LIKE '{$str_table}'");
$row   = mysql_fetch_assoc($query);

$int_increment = $row['Auto_increment'];

这篇关于mysql 如何输出 auto_increment 计数器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆