有咩有什么方法就表ba2的自动增长字段a的下一条记录的id值
例如他的AUTO_INCREMENT=5,  这个用sql如何来求  (这个表经常删数据 导致许多id缺失
所以只能通过ddl语句来求 想知道我用java程序如何得到这个AUTO_INCREMENT=5???/
)CREATE TABLE `ba2` (
  `b` int(11) default NULL,
  `a` int(11) unsigned NOT NULL auto_increment,
  PRIMARY KEY  (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

解决方案 »

  1.   

    没什么好办法。一种方法是可以在程序中mysql_query("show create table ba2") 然后对结果进行语法分析得到这个 AUTO_INCREMENT=5
      

  2.   

    这个如何放到sql里执行
    而且进行语法分析得到用shell感觉是可以的 
      

  3.   

    mysql -ss -e "select AUTO_INCREMENT from information_schema.TABLES where TABLE_NAME= 'ba2';"
      

  4.   

    mysql -uroot -proot -ss -e "select AUTO_INCREMENT from information_schema.TABLES where TABLE_NAME= 'ba2';
      

  5.   

     高,学习了。mysql> select AUTO_INCREMENT from information_schema.TABLES where TABLE_NAME= 'b
    a2';
    +----------------+
    | AUTO_INCREMENT |
    +----------------+
    |              5 |
    +----------------+
    1 row in set (0.11 sec)
      

  6.   

    你确定你需要的不是LAST_INSERT_ID()?
    LAST_INSERT_ID(), LAST_INSERT_ID(expr)LAST_INSERT_ID() (with no argument) returns the first automatically generated value that was set for an AUTO_INCREMENT column by the most recently executed INSERT or UPDATE statement to affect such a column. For example, after inserting a row that generates an AUTO_INCREMENT value, you can get the value like this:mysql> SELECT LAST_INSERT_ID();
            -> 195