auto incrementの次の値を取得する

auto incrementの次の値は、以下のコマンドで取得できます。

◆書式

SHOW TABLE STATUS WHERE Name = カラム名;

 

◆実行例

mysql> SHOW TABLE STATUS WHERE Name = col1;
+------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| Name             | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time | Collation       | Checksum | Create_options | Comment |
+------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| col1	  | MyISAM |      10 | Dynamic    |    2 |             38 |         136 | 281474976710655 |         2048 |        60 |              6 | 2012-07-14 13:50:33 | 2012-07-18 22:43:16 | NULL       | utf8_unicode_ci |     NULL |                |         |
+------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+

上記の、Auto_increment値(6)これが次回発行されるAuto_increment値となります。

※なお、SHOW TABLE STATUSコマンドのカラム名は必ずクオテーションで囲います。

 

[対象]
MySQL 5.x.x