mysql unsigend_创建表 查询数据

创建表的语法:

create table [if not exisit] `tableNane`(

`字段名` 数据类型 [字段属性] [完整性约束] [索引] [注释],

...

);

示例:

primary key: 完整性约束(主键:唯一的,非空的)

create table if not exisit `Student`(

`StuNumber` int primary key,

Name char(20),

...

);

MySQL中的数据类型e94ad1672062d6c5faf29da2d807deb5.png常用数据类型

UNSIGNED   标识为无符号数

ZEROFILL属性位数(宽度)不足时以0填充

如果某个字段指定了ZEROFILL属性,将自动添加UNSIGEND属性

示例,创建表查询数据

# 选择数据库

use mydatabases;

# 创建表

create table if not exists `tb_type`(

`sid` int(4) zerofill

);

# 连续插入单条数据

insert into `tb_type` (`sid`) value (1);

insert into `tb_type` (`sid`) value (12);

insert into `tb_type` (`sid`) value (134);

insert into `tb_type` (`sid`) value (1234);

# 从tb_type表中查询所有数据

select * from `tb_type`;

运行结果:sid

0001    # 数位小于宽度 以0填充

0012

0123

1234   # 数位大于等于宽度,以实际位数显示

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值