项目中Mysql经验

通用设计字段
id_ucp_doc_ver bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
remark varchar(512) character set utf8mb4 collate utf8mb4_bin not null comment '备注',
created_by varchar(128) character set utf8mb4 collate utf8mb4_bin not null comment '创建人',
date_created datetime not null default current_timestamp comment '创建时间',
updated_by varchar(128) character set utf8mb4 collate utf8mb4_bin not null comment '修改人',
date_updated datetime not null default current_timestamp comment '修改时间'
mysql中给表名、字段名加``是为了防关键字报错,有关键字再加,上面的时间用now()传入即可
utf8mb4_bin区分大小写(针对表中的数据)、utf8mb4_general_ci(不区分大小写)

<if test="status != null and status !=''">  只用于字符串(最好是过滤下空字符串,避免数据库多一些层扫描),数字类型为0的话status !=''会返回false
String str ="A"; <if test="str!= null and str == 'A'">有Bug,应该改为<if test='str!= null and str == "A"'>

短数字可以设置成short
写的时候最好加上jdbcType,否则插入null的时候可能会报错,只识别大写  
#{name,jdbcType=VARCHAR}
#{priority,jdbcType=DECIMAL}
#{dateCreated,jdbcType=TIMESTAMP}

mysql中substr(str,pos,len)和substring(str,pos,len)用法一样,从1开始
instr(str,substr) 返回substr的起始索引

merge操作,依赖索引
insert into table_name (col1,...) values (#{val1}...) on duplicate key update col1=#{val1}... 

mysql支持正则,但是和java不完全一样,^代表开始  .*代表任何多的字符串
name REGEXP "^.*[1-9][0-9]{5}([20])((0[3-9])|(1[0-9]))((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{3}[0-9Xx].*"
                               
创建同样的表结构
create table BAK_1105_1272_133607 like `ucp_work_executor_define`;

navicat导入使用txt性能更好
mysql判断空也是is null ,timestamp格式可以和字符串日期直接用>比较
longtext可以用string接收

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值