首页 技术 正文
技术 2022年11月21日
0 收藏 485 点赞 4,767 浏览 1405 个字

初次研究:

表:

mysql获得自增字段下一个值

sql:

show table status from carsale_db LIKE 'tb_car'

结果:

mysql获得自增字段下一个值

想办法取得这其中的值….

在Internet上找到这个资料:

  MySQL中可以使用 show table status 查看表的状态,但是不能像select 语句选出结果那样做结果过滤。

  有没有办法像select语句那样过滤呢,答案是有的,就是从information_schema库的tables表中查询。

  如下是模仿show table status 的SQL: 

SELECT table_name,Engine,Version,Row_format,table_rows,Avg_row_length,
Data_length,Max_data_length,Index_length,Data_free,Auto_increment,
Create_time,Update_time,Check_time,table_collation,Checksum,
Create_options,table_comment
FROM information_schema.tables
WHERE Table_Schema='MyDataBaseName';

  注意替换MyDataBaseName的名称为自己的库名称,这样就可以方便在Where部分添加各种条件过滤了。

  (From URL:http://jishu.zol.com.cn/3689.html)  

于是,复制->粘贴,修改所需字段:

SELECT table_name,Auto_increment,Engine,Version,Row_format,table_rows,Avg_row_length,
Data_length,Max_data_length,Index_length,Data_free,
Create_time,Update_time,Check_time,table_collation,Checksum,
Create_options,table_comment
FROM information_schema.`TABLES`
WHERE Table_Schema='carsale_db'

结果:

mysql获得自增字段下一个值

感觉表太多了,修改:

SELECT table_name,Auto_increment,Engine,Version,Row_format,table_rows,Avg_row_length,
Data_length,Max_data_length,Index_length,Data_free,
Create_time,Update_time,Check_time,table_collation,Checksum,
Create_options,table_comment
FROM information_schema.`TABLES`
WHERE Table_Schema='carsale_db'
AND table_name = 'tb_car'

结果:

mysql获得自增字段下一个值

排除不需要的字段:

SELECT Auto_increment
FROM information_schema.`TABLES`
WHERE Table_Schema='carsale_db'
AND table_name = 'tb_car'

结果:

mysql获得自增字段下一个值

OK,这就是我想要的结果…..

———————>>>>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860