一些数字的属性

M, 宽度, 在0填充时有效
unsigned 无符号型, 也就是非负
zerofill , 0填充时有效, 默认非负, 用于对齐用
not null default '100', 设置字段默认值

 

float(m,d)
m 总位数
d 小数位

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
mysql> create table i(id int, scor int zerofill);
Query OK, 0 rows affected (0.04 sec)
 
mysql> desc i;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type                      | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| id    | int(11)                   | YES  |     | NULL    |       |
| scor  | int(10) unsigned zerofill | YES  |     | NULL    |       |
+-------+---------------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
 
 
mysql> insert into i values(1,1);
Query OK, 1 row affected (0.00 sec)
 
mysql> select * from i;
+------+------------+
| id   | scor       |
+------+------------+
|    1 | 0000000001 |
+------+------------+
1 row in set (0.00 sec)
 
mysql><br><br>

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mysql> alter table i add end int not null default 100;
Query OK, 1 row affected (0.06 sec)
Records: 1  Duplicates: 0  Warnings: 0
 
mysql> desc i;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type                      | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| id    | int(11)                   | YES  |     | NULL    |       |
| scor  | int(10) unsigned zerofill | YES  |     | NULL    |       |
| end   | int(11)                   | NO   |     | 100     |       |
+-------+---------------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
 
mysql> select * from i;
+------+------------+-----+
| id   | scor       | end |
+------+------------+-----+
|    1 | 0000000001 | 100 |
+------+------------+-----+
1 row in set (0.00 sec)
 
mysql>

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mysql> desc i;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type                      | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| id    | int(11)                   | YES  |     | NULL    |       |
| scor  | int(10) unsigned zerofill | YES  |     | NULL    |       |
| end   | int(11)                   | NO   |     | 100     |       |
+-------+---------------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
 
mysql> alter table i add f float(3,1) not null default 222.1;
ERROR 1067 (42000): Invalid default value for 'f'
mysql> alter table i add f float(3,1) not null default 22.1;
Query OK, 1 row affected (0.03 sec)
Records: 1  Duplicates: 0  Warnings: 0
 
mysql>

 

posted on   Perl6  阅读(276)  评论(0编辑  收藏  举报

编辑推荐:
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
阅读排行:
· 《HelloGitHub》第 108 期
· Windows桌面应用自动更新解决方案SharpUpdater5发布
· 我的家庭实验室服务器集群硬件清单
· C# 13 中的新增功能实操
· Supergateway:MCP服务器的远程调试与集成工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示