mysql資料類型

來源:互聯網
上載者:User

標籤:values   blog   table   height   var   並且   val   聲明   alter   

常見資料類型有:

整數: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: 0mysql> 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: 0mysql> select * from t;+------+| t    |+------+|  011 ||  111 || 1111 |+------+3 rows in set (0.00 sec)

 

mysql資料類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.