首页 > 数据库技术 > 详细

mysql数据类型

时间:2017-07-14 14:38:51      阅读:223      评论:0      收藏:0      [点我收藏+]

常见数据类型有:

整数:tinyint、smallint、mediumint、int、bigint

浮点数:float、double

定点数:decimal

 

字符串:char、varchar、tinytext、text、mediumtext、longtext

 

日期:date、datetime、timestamp、year、time

 

整数的申明方式:

类型 声明方式
tinyint

TINYINT[(M)] [UNSIGNED] [ZEROFILL]  M默认为4

smallint

SMALLINT[(M)] [UNSIGNED] [ZEROFILL] M默认为6

mediumint

MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL] M默认为9

int

INT[(M)] [UNSIGNED] [ZEROFILL]   M默认为11

bigint

BIGINT[(M)] [UNSIGNED] [ZEROFILL] M默认为20

注:这里的M代表的并不是存储在数据库中的具体的长度,而是指明int的最小显示位数,并且该值只有在指明了zerofill之后才会生效。

 

mysql> create table t (t int(3));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t values(11),(111),(1111);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from t;
+------+
| t    |
+------+
|   11 |
|  111 |
| 1111 |
+------+
3 rows in set (0.00 sec)

mysql> alter table t change t t int(3) zerofill;
Query OK, 3 rows affected (0.06 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from t;
+------+
| t    |
+------+
|  011 |
|  111 |
| 1111 |
+------+
3 rows in set (0.00 sec)

 

mysql数据类型

原文:http://www.cnblogs.com/jade640/p/7169651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!