mysql 常用数据类型

tinyint类型

有符号,取值范围-128~127 【默认】

无符号,取值范围0~255  

create table tb1(
id int not null auto_increment primary key,
age tinyint          --有符号  取值范围-128~127
)default charset=utf8;

 

create table tb1(
id int not null auto_increment primary key,
age tinyint unsigned         --无符号  取值范围0~255
)default charset=utf8;

int类型 

int

int unsigned

bigint类型

bigint

bigint unsigned

实例

create table tb(
id int not null auto_increment primary key,
salary int,
age tinyint          
)default charset=utf8;

float

double

decimal

create table tb3(
id int not null auto_increment primary key,
salary decimal(8,2)          
)default charset=utf8;

insert into tb3(salary) values(10046.45),(28067.753),values(14046.157);

 

char定长字符串

create table tb4(
id int not null auto_increment primary key,
mobile char(11)
)default charset=utf8;

insert into tb4(mobile) values(131),(17319223260);

char(11) 规定长度为11

varchar变长字符串

如果存储字符串长度小于11,也按11的长度存储。

create table tb5(
id int not null auto_increment primary key,
mobile varchar(11)
)default charset=utf8;

insert into tb4(mobile) values(13106322075),(17319223260);

char(11) 规定最大长度为11 

如果存储字符串长度小于11,按字符串本身长度存储。

text

 mediumtext

longtext

datetime

data

create table tb7(
    id int not null auto_increment primary key,
    name varchar(64) not null,
    password char(64) not null,
    email varchar(64) not null,
    age tinyint,
    salary decimal(10,2),
    ctime datetime
 )default charset=utf8;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值