skip to Main Content
<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 the datas in mySQL DB. if transactionDate, transactionNumber, and uid from parameters are same with market_day, order_number, uid from stock_order_abusing table columns at the same time, then there will be no insertion or insertion should be ignored. There are no pk(primary key) to compare. All the methods in google are telling me that I should have primary key to prevent duplicated insertion. Are there any ways to deal with this problem?

2

Answers


  1. You can use INSERT IGNORE syntax if you want to take no action when there’s a duplicate record.

    here is full syntax guide

    Login or Signup to reply.
  2. If you have access to the database structure, you can create unique indexes on the
    "uid" field. In this way, the database prevents double entry of data

    CREATE UNIQUE INDEX index_name  
    ON table_name (index_column1, index_column2,...);  
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search