企业规范约束

库表字段约束规范

 #这个人是不是vip
 字段命名:is_vip,字段必须是小写字母,不能以数字开头,不能出现复数,不能使用关键字,主键索引名一般以pk_xxx形式
 类型:unsigned tinyint
 长度:1
 
 表名:
 主键索引名一般以pk_xxx形式
 唯一键索引名uk_xxx
 
 小数禁止使用float和double,只能用decimal,
 
 字符串小的话使用char,别用varchar
 
 表里必须有的:id,create_time,update_time,缺一不可
 id必须为primary key,类型无符号(unsigned)bigint,自动增长(auto-increment)
 create_time,updatetime为datatime类型
 
 字段频繁的被查询的话,应当允许字段冗余

 


索引规范

 


SQL开发约束

 count(xxx,xxx,xxx)不能替代count(*),没办法统计null
 
 错误:select * from student where name=null;
 正确:select * from student where name is null;或者使用ISNULL()函数
 
 高并发的项目中不要使用外键和级联
 
 实际开发中不允许使用存储过程,不利于扩展移植
 先select再更新
 
 in操作尽量不要使用
 
 utf8编码格式

 


其他约束

orm框架不要使用select*,要写清楚

 

 

posted @ 2020-08-03 17:36  leoIOIO  阅读(104)  评论(0)    收藏  举报