insert contacts into database but does not want to duplicate already existing contact

前端 未结 4 1616
失恋的感觉
失恋的感觉 2020-12-07 06:23

I am trying to insert contacts into database but does not want to duplicate already existing contact.

Not sure INSERT has WHERE CLAUSE.

Any ideas?

         


        
4条回答
  •  一整个雨季
    2020-12-07 06:56

    You could use a stored procedure that checks if the record first exists before doing an insert. If the record exists, the stored procedure would do an update.

    The advantage of using a stored procedure instead of a select followed by an update is you only hit the database server once instead of twice.

提交回复
热议问题