2010-04-02 17 views

回答

2

您可以使用

show indexes from your_table; 

欲了解更多信息:12.4.5.23. SHOW INDEX Syntax


作为快速演示(在一个不太完美的桌子上)

mysql> show indexes from post; 
+-------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 
| Table | Non_unique | Key_name  | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | 
+-------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 
| post |   0 | PRIMARY   |   1 | id   | A   |   7 |  NULL | NULL |  | BTREE  |   | 
| post |   1 | id_blog_idx  |   1 | id_blog  | A   |   2 |  NULL | NULL |  | BTREE  |   | 
| post |   1 | id_user_idx  |   1 | id_user  | A   |   7 |  NULL | NULL |  | BTREE  |   | 
| post |   1 | code_syntax_idx |   1 | code_syntax | A   |   7 |  NULL | NULL |  | BTREE  |   | 
| post |   1 | code_status_idx |   1 | code_status | A   |   2 |  NULL | NULL |  | BTREE  |   | 
| post |   1 | id_category_idx |   1 | id_category | A   |   7 |  NULL | NULL |  | BTREE  |   | 
+-------+------------+-----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+ 
6 rows in set (0,00 sec) 


请注意,这将显示索引 - 而auto_increment与索引没有太大关系。

如果你想看到你的表的auto_increment,您可以使用desc

desc your_table; 

欲了解更多信息:12.8.1. DESCRIBE Syntax


而且,例如,与同桌:

mysql> desc post; 
+--------------------+------------------+------+-----+---------+----------------+ 
| Field    | Type    | Null | Key | Default | Extra   | 
+--------------------+------------------+------+-----+---------+----------------+ 
| id     | int(10) unsigned | NO | PRI | NULL | auto_increment | 
| id_blog   | int(10) unsigned | NO | MUL | NULL |    | 
| id_user   | int(10) unsigned | NO | MUL | NULL |    | 
... 
... 
| nb_comments  | smallint(6)  | NO |  | 0  |    | 
+--------------------+------------------+------+-----+---------+----------------+ 
17 rows in set (0,05 sec) 
1

此外,另一种方法(它也显示了当前值th ËAUTO_INCREMENT计数器)是:

=> SHOW CREATE TABLE activations; 

屈服

CREATE TABLE `activations` (
    `id` int(11) NOT NULL AUTO_INCREMENT, 
    `user_id` int(11) DEFAULT NULL, 
    `created_at` datetime DEFAULT NULL, 
    PRIMARY KEY (`id`) 
) ENGINE=InnoDB AUTO_INCREMENT=104974 DEFAULT CHARSET=utf8 
+0

更多的知识,谢谢 – 2010-04-02 05:37:57