mysql建库注意事项笔记

idea 设置代码超出限制自动换行  editor > General > Console >user soft warps in console 画上钩

创建mysql 的数据库表的时候

当我们有很多的行的时候,主键不宜设置成auto_increment 因为自增是有一个限制的,所以我们要自己设置主键,当然对于一些类目比较少的,我们可以设置主键为自增

对于价格来说,我们都会把类型设置成 decimal MySQL DECIMAL数据类型用于在数据库中存储精确的数值 后面有两个参数,例如decimal(8,2) 表示小数点前八位,后两位

每个属性设置默认值的时候 可以用default '默认值'

设置时间

'create_time' timestamp not null default current_timestamp comment '创建时间',
'update_time' timestamp  not null default  current_timestamp  on update current_timestamp comment '更新时间',

default current_timestamp 在mysql 5.6 会报错   on update current_timestamp 表示修改的时候自动填充当前时间

注释用comment  '注释'

在我们进行查表的时候,默认mysql 会设置主键索引 所以有的时候我们要按照买家的;主键进行查询,我们要添加索引,可以加快查询的速度, key 'idx_order_type' (‘order_type') 设置索引 一般根据id 索引我们会起名为idx

mysql 中的 tinyint smallint int bigint

发布了41 篇原创文章 · 获赞 4 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_37992974/article/details/87986790
今日推荐