美文网首页
mySql语法(2)

mySql语法(2)

作者: yxCassiel | 来源:发表于2019-01-29 16:53 被阅读0次

    创建表,多列唯一索引

    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 id="insertIntoGrid" parameterType="java.util.List">

    INSERT INTO ${tableName}

    (GRID_SN, GRID_NUMBER,

    .......)

    VALUES

    <foreach collection="list" item="item" index="index" separator=",">

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

    .......

    </foreach>

    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)

          本文链接:https://www.haomeiwen.com/subject/lgwxsqtx.html