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;