Insert data if and only if there is no duplicate data in the mysql database
P粉883278265
P粉883278265 2023-09-13 18:17:33
0
1
510

<insert id="insertStockOrderAbusingList" parameterType="java.util.List">
    INSERT IGNORE INTO iruda_trade.stock_order_abusing (
        market_day,
        uid,
        stock_account_id,
        order_number,
        symbol,
        conclusion_quantity,
        order_type,
        created_at
    ) VALUES
    <foreach collection="list" item="item" index="index" separator=",">
    (
            #{item.transactionDate},
            #{item.uid},
            #{item.stockAccountId},
            #{item.transactionNumber},
            #{item.symbol},
            #{item.filledVolume},
            #{item.transactionType},
            #{item.clientTimeStamp}
     )
     </foreach>
</insert>

I'm trying to insert data into mySQL DB. If the transactionDate, transactionNumber and uid in the parameters are also the same as the market_day, order_number, uid in the stock_order_abusing table column, then there will be no insertion or the insertion should be ignored. There is no pk (primary key) to compare. All methods in Google tell me that there should be primary key to prevent duplicate insertion. Is there any way to solve this problem?

P粉883278265
P粉883278265

reply all(1)
P粉216807924

If you want to take no action when duplicate records exist, you can use the INSERT IGNORE syntax.

Here is the complete grammar guide

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template