MySQL建表DDL規範 歡迎補充

2022-09-14 11:24:11 字數 1292 閱讀 4497

基本規範:

表名和欄位名全大寫,一般表名以t開頭

指令碼需支援可重複執行,帶if not exists ,但不可帶drop語句

字符集使用utf8mb4 (charset = utf8mb4 collate utf8mb4_unicode_ci)

指令碼檔案使用無bom的utf-8編碼,否在會導致亂碼

普通表,使用t開頭,例如t_account

參數列,使用t_para開頭,例如t_para_genral_config

批量業務使用的表,使用t_batch開頭,如t_batch_account_item

流水類的表,必須帶業務流水號、系統流水號(全域性貫穿),例如t_trans_log_recharge

案例ddl模板:

create table if not exists `t_***todo`

( `id` bigint not null comment '主鍵id',

`column1` tinyint(4) not null comment '***1',

`column2` tinyint(4) not null comment '***1',

`column3` tinyint(4) not null comment '***1',

`biz_date` date not null comment '業務日期',

`created_datetime` datetime not null default current_timestamp comment '建立時間',

`last_modified_datetime` datetime not null default current_timestamp on update current_timestamp comment '更新時間',

`version` int(11) not null comment '樂觀鎖版本號',

primary key (`id`),

key t_***todo_last_modified_datetime (last_modified_datetime)

) engine = innodb

default charset = utf8mb4

collate utf8mb4_unicode_ci comment 't_***todo表';

mysql建表規範

create table dbname bodyguard black box id int 11 not null auto increment,login id varchar 64 default null comment 使用者登入賬號,手機號 bize code varchar 64 de...

Mysql 建表及查詢規範

int 如無特殊需要,存放整型數字使用unsigned int型。整型欄位後的數字代表顯示長度。整型型別如下表 資料型別 最大儲存長度 有符號 最大儲存長度 無符號 tinyint m 1個位元組 範圍 128 127 1個位元組 範圍 0 256 smallint m 2個位元組 範圍 32768...

MySQL學習之建表規範

資料型別盡量用數字型別,數字型別的比字元型別的要快很多,比如使用int unsigned儲存ip 大資料字段最好剝離出單獨的表,以便影響效能 使用varchar,代替char,這是因為varchar會動態分配長度資料型別盡量小,這裡的盡量小是指在滿足可以預見的未來需求的前提下的,但是有不能太小,所以...