原生mysql 执行多条数据,数据存在更新,不存在插入(设置唯一索引)

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:20   2016   0

//表结构

CREATE TABLE `stair_performance` (
  `id` int(8) NOT NULL AUTO_INCREMENT,
  `dep_id` int(8) DEFAULT NULL COMMENT '部门id',
  `product_id` varchar(64) DEFAULT NULL,
  `type` tinyint(2) DEFAULT NULL COMMENT '1进件\r\n2放款笔数\r\n3放款金额',
  `target` int(9) DEFAULT NULL COMMENT '目标金额',
  `year` int(4) DEFAULT NULL,
  `month` int(2) DEFAULT NULL,
  `created` int(10) DEFAULT NULL,
  `updated` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `only` (`dep_id`,`product_id`,`type`,`year`,`month`) USING HASH //设置联合唯一索引
) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8mb4;
 

//批量操作语句

INSERT INTO stair_performance (
    dep_id,
    product_id,
    type,
    target,
    year,
    m

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP