字段类型
一、整型
整型的宽度是显示宽度,存储宽度是固定死的 无需指定
例如:
create table t5(id tinyint)
mysql> create table t5(id tinyint)
mysql> desc t4;
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| id | tinyint(4) | YES | | NULL | |
+-------+------------+------+-----+---------+-------+
1 row in set (0.01 sec)
mysql> insert t4 values(128);
ERROR 1264 (22003): Out of range value for column 'id' at row 1
mysql>
mysql>
mysql> insert t4 values(127);
Query OK, 1 row affected (0.05 sec)
mysql> select * from t4;
+------+
| id |
+------+
| 127 |
+------+
1 row in set (0.00 sec)
mysql>
二、
create table t7(x float(255,30),y double(255,30),z decimal(65,30)); insert t7 values (1.111111111111111111111111111111,1.111111111111111111111111111111,1.111111111111111111111111111111);
传值精度越来越高 越来越准确
三、
year(1901/2155) time 时:分:秒 ('-838:59:59'/'838:59:59') date 年:月:日 (1000-01-01/9999-12-31) datetime 年:月:日 时:分:秒 1000-01-01 00:00:00/9999-12-31 23:59:59#用于记录注册时间 timestamp 年:月:日 时:分:秒 1970-01-01 00:00:00/2037 #用于记录更新时间 create table t8(y year,t time,d date,dt datetime,ts timestamp); insert t8 values(now(),now(),now(),now(),now()); create table student( id int, name char(10), born_year year, bitrh date, reg_time datetime ); insert student values (1,"wangjing","1911","1911-11-11","1911-11-11 11:11:11"), (2,"lxx","1988","1988-11-11","1988-11-11 11:11:11"); insert student values (3,"wangjing","1911","19111111","19111111111111");
create table t9( id int, name varchar(16), -- update_time datetime not null default now() on update now(), update_time timestamp, reg_time datetime not null default now() ); insert into t9(id,name) values(1,"egon");
解读:
datetime not null default now() on update now(), #用datetime类型 不为空 默认使用下载的时间 只要有一处改动 就更新到现在的时间 update_time timestamp,
mysql> select * from t9;
+------+------+---------------------+---------------------+
| id | name | update_time | reg_time |
+------+------+---------------------+---------------------+
| 1 | egon | 2020-09-01 16:45:51 | 2020-09-01 16:45:51
| +------+------+---------------------+---------------------+
1 row in set (0.00 sec)
mysql> update t9 set name="EGON" where id=1;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from t9;
+------+------+---------------------+---------------------+
| id | name | update_time | reg_time
| +------+------+---------------------+---------------------+
| 1 | EGON | 2020-09-01 16:46:50 | 2020-09-01 16:45:51 |
+------+------+---------------------+---------------------+
1 row in set (0.00 sec)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南