MYSQL创建数据表!

几个常见的建表原则

a,表都加前缀
b,所有的字段选择最小的数据类型,如id可以使用mediumint比INT节省25%的空间
c,尽量所有的字段都设置为NOT NULL的,这样能让速度更快
d,为合适的字段(将来用来查询或者排序的字段)建索引

id 可以用 int , 但是建议使用 mediumint
 
常用的四种
tinyint :  0-255
samllint :  0-65535
mediumint : 0-1千6百多万
int:0-40亿
名称,类型,主键,不为空,自增
id mediumint unsigned not null auto_increment,
===================================
商品价格:
使用decimal(10,2) 表示:一共是十位数字,其中两位是小数,整数位是八位
price decimal(10,2) not null default '0.00' coment '商品价格',
===================================
商品描述:
char : 0-255个字符;
varchar : 0-65535个字;如果是 utf8 能存 2万多汉字,gbk能存3多字
text:0-65535个字
goods_desc longtext comment '商品描述',
===================================
商品添加时间:
使用int :因为现在的时间已经是14亿多了
addtime int unsigned not null comment '添加时间',
====================================

新建一个数据表

drop table if exists fyz_goods;
create table fyz_goods(
    id mediumint unsigned not null auto_increment,
    goods_name varchar(45) not null comment '商品名称',
    logo varchar(150) not null default '' comment '商品logo',
    sw_logo varchar(150) not null default '' comment '商品缩略图',
    price decimal(10,2) not null default '0.00' comment '商品价格',
    goods_desc longtext comment '商品描述',
    is_on_sale tinyint unsigned not null default '1' comment '是否上架;1:上架;0:下架;',
    is_delete tinyint unsigned not null default '0' comment '是否删除;1:已经删除;0:没有删除',
    addtime int unsigned not null comment '添加时间',
    primary key (id),
    key price(price),
    key is_on_sale(is_on_sale),
    key is_delete(is_delete),
    key addtime(addtime)
)engine=MyISAM default charset=utf8;
原文地址:https://www.cnblogs.com/e0yu/p/7240526.html