MySQL数据字段属性

MySQL有如下字段属性:

这里写图片描述

模板:

create table test(

id int unsigned auto_increment primary key,

name varchar(30) not null default “”,

age int not null default 0,

height float not null default 0.00

);

1.unsigned(无符号)

作用:可以让空间增长一倍,只能使用在整型中使用
例子:create table test(
    id int unsigned not null;
   )
注意:上面的id定义为无符号类型的,所以不能添加负值

2.zerofill(前导0)

作用:在位数不够时,前面用0补充。
例子:id int(5) zerofill
当你输入1234的时候,如果没有zerofill,查看时数据库里会显示:1234;加上zerofill时,会显示01234来补齐5位。

注意:如果我们定义的列是zerofill的,那么MySQL会自动给这个列加上unsigned属性。

3.auto_increment(自动增长)

作用:
  如果我们给一个列添加了autoincrement属性,那么当我们插入null或0值时,列值便会自动设置成下一个序列号,一般是当前value+1。
例子:
  id int auto_increment primary key;

注意:
  1.auto_increment字段的值不能有重复,所以创建时需要加索引;
  2.通常每个表都有一个ID设置为auto_increment;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值