int
int unsigned
int(5) zerofill
tinyint[(m)] [unsigned] [zerofill]
bigint[(m)][unsigned][zerofill]
示例
create table L1(id int, uid int unsigned, zid int(5) zerofill) default charset=utf8;
insert into L1(id, uid, zid) values(1,2,3)
insert into L1(id, uid, zid) values(21444444, 4000000, 3000000)
decimal[(m[,d])] [unsigned] [zerofill]
sql 示例
create table L2(
id int not null primary key auto_increment,
salary decimal(8, 2)
) default charset=utf8;
如果插入 小数不是 2位,会自动四舍五入
如果整数部分超出,则会报错(严格模式)
项目开发中,一般都用 decimal, float, double 不常用
FLOAT[(M,D)] [UNSIGNED] [ZEROFILL]
DOUBLE[(M,D)] [UNSIGNED] [ZEROFILL]
char(m)
sql-mode="NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION"
PAD_CHAR_TO_FULL_LENGTH
即可,但是一般不加varchar(m)
例如
-- 创建 表 L3
create table L3(
id int not null primary key auto_increment
name varchar(5),
depart char(3)
) default charset=utf8;
insert into L3(name, depart) values("asssss", "s");
select id, name, depart, length(depart) from L3; -- 如果配置了 PAD_CHAR_TO_FULL_LENGTH 不足长度的,会补足
严格模式和非严格模式的区别
text
create table L4(
id int not null primary key auto_increment,
title varchar(128),
content text
) default charset=utf8;
mediumtext
longtext
datetime
timestamp
举例
create table L5(
id int not null primary key auto_increment,
dt datetime,
tt timestamp
) default charset=utf8;
insert into L5(dt, tt) values("2023-12-12 12:12:12", "2023-12-12 12:12:12")
select * from L5;
从上面显示的时间是一样的
show varibales like '%time_zone%'
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+
set time_zone='+0:00'
,再次查询时
date
time