MariaDB 10.6.4でauto_incrementのカラムの値を確認する方法

環境
MariaDB 10.6.4
Windows 10 Home 64bit

構文
show table status like 'テーブル名’;

使用例
SQL構文
show table status like 'emptbl’;
実行結果

MariaDB [testdb]> show table status like 'emptbl';
+--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+------------------+-----------+
| 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 | Max_index_length | Temporary |
+--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+------------------+-----------+
| emptbl | InnoDB |      10 | Dynamic    |    0 |              0 |       16384 |               0 |            0 |         0 |           NULL | 2022-01-13 22:29:29 | NULL        | NULL       | utf8mb3_general_ci |     NULL |                |         |                0 | N         |
+--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+------------------+-----------+
1 row in set (0.710 sec)

構文2
SELECT auto_increment FROM information_schema.tables
WHERE table_schema = 'データベース名’ and table_name = 'テーブル名’;

使用例
SQL構文
SELECT auto_increment FROM information_schema.tables WHERE table_schema = 'testdb’ and table_name = 'emptbl’;

実行結果

MariaDB [testdb]> SELECT auto_increment FROM information_schema.tables
    -> WHERE table_schema = 'testdb' and table_name = 'emptbl';
+----------------+
| auto_increment |
+----------------+
|           NULL |
+----------------+
1 row in set (0.038 sec)

 

MariaDB

Posted by arkgame