table

 一、创建表结构

create table order_ipad(
id bigint(20) unsigned not null auto_increment comment '自增主键',
uuid bigint(20) unsigned not null default 0 comment '用户id',
order_id varchar(64) not null default '' comment '订单id',
name varchar(64) not null default '' comment '商品名称',
type tinyint(4) unsigned not null default 0 comment '状态 1:增加 2:减少',
price int(11) unsigned not null default 0 comment '',
title varchar(64) not null default '' comment '标题',
status tinyint(4) unsigned not null default 0 comment '状态 1:进行中 2:已完成 3:已退款 4:已失败 99:异常',
source tinyint(4) unsigned not null default 0 comment '来源 1:任务系统 2:金币系统 3:活动系统',
end_time bigint(20) unsigned not null default 0 comment '过期时间',
record_time bigint(20) unsigned not null default 0 comment '记录发生时间',
create_time timestamp not null default current_timestamp comment '创建时间',
refund_time bigint(20) unsigned not null default 0 comment '退款时间',
update_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (id),
unique key uk_orderid (order_id) ,
key idx_uuid_name (uuid,name(10)),
key idx_uuid_title (uuid,title(10))
)engine=innodb auto_increment=1 default charset=utf8mb4 comment='用户小游戏金币收支记录表';  

############################################################################################
1、一张表必须有主键。一般都是与业务无关的unsigned自增主键。
2、字段一般都要有not null约束;
   除主键外,一般还都有default约束,通常整型的默认值是0,字符串的默认值为'';
   每个字段和表都有comment说明,用以说明每个字段的含义和表的用途。
3、通常需要在建表的时候就能预估下常用的查询,以便创建合适的索引来加快查询、删除、更新速度。
4、表的存储引擎一般都是innodb,表的默认字符集一般都是utf8mb4,自增列初始值。

二、修改表结构

1、修改表的字符集和字符序

alter table table_name convert to character set utf8mb4 collate utf8mb4_general_ci;




原文地址:https://www.cnblogs.com/igoodful/p/12896037.html