mysql id存储类型_mysql的数据类型int、bigint、smallint 和 tinyint及id 类型变换

bigint

从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字)。存储大小为 8 个字节。

int

从 -2^31 (-2,147,483,648) 到 2^31 - 1 (2,147,483,647) 的整型数据(所有数字)。存储大小为 4 个字节。int 的 SQL-92 同义字为 integer。

smallint

从 -2^15 (-32,768) 到 2^15 - 1 (32,767) 的整型数据。存储大小为 2 个字节。

tinyint

从 0 到 255 的整型数据。存储大小为 1 字节。

有时MySQL创建表时存储设计过小,可以通过以下等方法查看修改:

1。 创建表的时候定义:

create table test ( id int primary key auto_increment)

2. 创建表的时候指定auto_increment的起始值

create table test(id int primary key auto_incrment) auto_increment = 100;

start with 100.... default is 1;

3.去掉自增属性后,其默认值将变为0

alter table test modify column id int;

4.为字段添加auto_increment属性

alter table test modify column id int auto_increment;

5. 修改字段的初始值

alert table test auto_increment = 200;

6. 怎样查看一个表的auto_increment的下一个自增ID值

我们知道getLastInsertID()属性只是获取插入记录之后的最大ID,并不是我们想要的,所以我们采用

show table status like 'tablename', 里面包含Auto_increment的字段

第二:

use information_schema;

select Auto_increment from tables where table_name = 'table_name';

其中information_schema一般用户无法访问.

7. 修改全局自增参数:

利用 show variables like 'AUTO_INCREMENT% ';

我们将看到

auto_increment_increment, auto_increment_offset, 它们代表全局的起始值和步进,通过如下方式修改:

set auto_increment_increment = 100;

set auto_increment_offset = 10 ;

这将对全局的auto_increment列产生影响,建议慎用!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值