MySQL最標準建表語句

2021-07-11 21:35:34 字數 3011 閱讀 3546

sql分類:ddl(資料定義語言)、dml(資料操縱語言)、dcl(資料控制語言)

create

table

`t_wxuser_trade_log` (

`id`

int(11) not

null auto_increment comment '序號',

`order_id` bigint(20) not

null comment '訂單id:微秒時間戳+4位隨機數(18位)',

`ordertype` tinyint(4) not

null

default

'0' comment '訂單型別0預設1復投2轉投3贖回',

`order_status` tinyint(4) not

null

default

'1' comment '投資狀態:1等待付款;2等待還款中;3已回款,交易成功;4買家取消訂單,交易已關閉;5交易失敗;6交易成功;7超時未支付訂單自動關閉;',

`order_date`

int(11) not

null comment '年月日(格式yyyymmdd)- 使用者來查詢報表需要',

`order_month`

int(11) not

null comment '年月(格式yyyymm)- 使用者來查詢報表需要',

`wxshop_id`

int(11) not

null comment '微店id',

`wxuser_id`

int(11) not

null comment '使用者id',

`accountstatus` tinyint(4) not

null

default

'0' comment '到賬狀態(0處理中,1轉賬成功(到賬),-1轉賬失敗)',

`accounttime` datetime default

null comment '到賬時間',

`tradetype` tinyint(4) not

null

default

`paytype` tinyint(4) not

null

default

'0' comment '支付方式:1寶付支付',

`payid`

varchar(50) default

null comment '支付單號:pay+微秒時間戳+4位隨機數(18位)',

`batchid`

varchar(50) default

null comment '寶付批次號(使用者於查詢使用者交易狀態)',

`paystatus` tinyint(4) not

null

default

'1' comment '支付狀態(1未支付,2支付成功,3支付失敗)',

`paytime` datetime default

null comment '支付時間',

`trademoney`

decimal(18,6) default

null,

`payemoney`

decimal(18,6) default

null,

`servicecharge`

decimal(8,2) not

null

default

'0.00' comment '手續費',

`category_id` tinyint(4) default

null comment '產品型別(0其它(充值、提現等非產品),1投資產品,2體驗金)',

`product_id`

int(11) default

null comment '產品id(若投資產品,則為企業標第id;若為體驗金,則為體驗金id)',

`account_type` tinyint(4) not

null comment '操作人:1使用者,2商家,3系統',

`comefrom`

varchar(20) default

null comment '**',

`account`

varchar(50) not

null comment '操作帳號',

`operation_title`

varchar(50) not

null comment '操作標題',

`operation_type` tinyint(4) not

null comment '操作型別(1充值、2提現、3投資**入)、4轉出、5收益、6佣金、7活動、8大額支付、101員工存入)',

`activity_type`

int(11) default

'0' comment '活動型別',

`operation`

varchar(100) default

null comment '操作說明',

`recorddate` datetime default

null comment '記錄時間',

primary

key (`id`)

) engine=innodb auto_increment=556536

default charset=utf8 comment='使用者交易記錄日誌表'

注意點:

1、mysql的sql特性:表名和欄位名需要加反引號引住;

2、我們寫sql語句一般不加,如果要手寫sql,建議在sqllog等軟體上先新建查詢,將sql語句格式化粘到需要用到的位置;

3、decimal(8,2)型別可用於交易金額;

4、comment對於一些使用mysql connector的人來說,閱讀方便,建議寫上;

5、engine=innodb 選擇資料表引擎;

6、default charset=utf8 選擇合適的編碼;

7、auto_increment=556536 目前的最大自增索引號;

PostgreSQL標準建表語句

建表 create table if not exists public.user id character varying 32 not null default sys guid name character varying 100 not null,gender character varyi...

Oracle標準建表語句

create table 建表 create table outln.customer id varchar2 32 default sys guid not null,cust id varchar2 64 cust name varchar2 255 id no varchar2 64 mobi...

mysql建表語句

在sql語句中注意 約束的概念 1.實體完整性約束 主鍵 唯一且非空 primary key 違約處理 no action 拒絕執行 2.參照完整性約束 外來鍵約束 foregin key references tablename filedname on delete update casecad...