1. 程式人生 > >mysql數據類型

mysql數據類型

reat lte edi wrap dup big affect bsp ear

常見數據類型有:

整數: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數據類型