MySQL中自动增长类型要求

自动增长(auto_increment)

1.一个表中只能有一个列为自动增长;

否则会报错Incorrect table definition; there can be only one auto column and it must be defined as a key

2.自动增长列的类型必须是整数类型;

否则会报错Incorrect column specifier for column ‘name’

3.自动增长只能添加到具备主键约束与唯一约束的列上;

否则会报错Incorrect table definition; there can be only one auto column and it must be defined as a key

4.删除主键约束或唯一性约束,如果该列拥有自动增长能力,则需要先去掉自动增长然后再删除约束;

否则会报错Incorrect table definition; there can be only one auto column and it must be defined as a key
(除了2以外,报错提示都是一样的!不知道我发现的对不对;)


创建一个 emp2 表。包含 id 该列为主键,包含 name,包含 seq_num 要求 该列为具备唯一性约束,该列的值自动增长。

Create table emp2(id int primary key , name varchar(30) , seq_num int unique 	auto_increment);

验证:查看表结构;
Desc emp2;
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值