mysql 建表時各列中資料型別的使用

2021-08-21 05:17:34 字數 575 閱讀 4332

create table userinfo(

id int unsigned not null primary key auto_increment comment '主鍵',

name varchar(20) default null comment '姓名',

mobile char(11) default null unique comment '手機號碼',

address varchar(100) default null comment '居住位址',

description text comment '個人簡介', -- 當不確定長度時,可以使用text

*** char(1) default null comment '性別',

age tinyint default 0 comment '年齡', -- 年齡可以使用tinyint,範圍為-128~127

idno char(18) default null comment '身份證號碼',

key telephone(mobile) -- 新增索引,提高查詢效率

)

MySQL建表過程 資料型別

a.主要學習列型別的儲存範圍與佔據的位元組關係 b.儲存同樣的資料不同列型別所佔據的空間和效率是不一樣的 c.乙個位元組八個位 d.參考 1 數值型 b.整形 tinyint 佔1個位元組 128 127 or 0 255 smallint 2個位元組 mediuint 3個位元組 int 4個位元...

mysql 建表時,我們應該考慮的資料型別

本文是由 高效能mysql 摘錄而來 如何選擇最優的資料型別,請看下面幾個原則 1 更小通常更好 好處 占用更少磁碟 記憶體和cpu快取,處理時需要的cpu週期更少 2 簡單就好 簡單資料型別通常需要更少的cpu週期,例子 用mysql內建日期型別 date,datetime,timestample...

MYSQL建表時資料型別的選擇

對於相同級別的資料型別,應該優先選擇占用空間小的資料型別。大小範圍 signed 範圍 unsigned 用途tinyint 1 位元組 128,127 0,255 小整數值,如年齡 smallint 2 位元組 32768,32 767 0,65535 大整數值 mediumint 3 位元組 8...