SQL INSERT but avoid duplicates

前端 未结 6 1000
北荒
北荒 2020-12-31 10:42

I want to do some quick inserts but avoid duplicates into a Table. For argument\'s sake lets call it MarketPrices, I\'ve been experimenting with two ways of doing it but not

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 11:09

    Another option: create a unique index on the fields (SecurityCode, BuyPrice, SellPrice) in question, issue a simple insert, and let the database decide whether the records are duplicates. The insert will fail on an attempt to insert a duplicate.

    Using code (whether external language or SQL proc) to guarantee uniqueness is not strict enough and will ultimately lead to the very duplicates you hope to prevent.

提交回复
热议问题