mySql语法(2)

创建表,多列唯一索引

CREATE TABLE ${tableName} (

`GRID_ID` bigint(20) NOT NULL AUTO_INCREMENT,

`GRID_SN` varchar(64) CHARACTER SET utf8 DEFAULT NULL,

......

PRIMARY KEY (`GRID_ID`)

UNIQUE INDEX `MultipleColumnsKey` (`GRID_ROAD_WAY`,`GRID_NUMBER`,`GRID_ROW`,`GRID_COLUMN`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;



mybatis批量插入,数据表里有数据就更新为原有数据+当前value,没有数据就插入新的记录

INSERT INTO ${tableName}

(GRID_SN, GRID_NUMBER,

.......)

VALUES

(#{item.gridSn,jdbcType=VARCHAR}, #{item.gridNumber,jdbcType=REAL},

.......

ON DUPLICATE KEY UPDATE GRID_PAVER_NUMBER=  `GRID_PAVER_NUMBER` +  values( GRID_PAVER_NUMBER),

GRID_COMPACTOR_R_NUMBER= `GRID_COMPACTOR_R_NUMBER`+ values(GRID_COMPACTOR_R_NUMBER),

......

你可能感兴趣的:(mySql语法(2))