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

前端 未结 4 1615
失恋的感觉
失恋的感觉 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:46

    Perhaps you want to do an "upsert"? That means that you try to do an INSERT, and if the record already exists, you do an UPDATE instead.

    To do that, first use a SELECT to see if the record already exists. If the contact isn't in the database, do an INSERT. If the contact is already in the database, do an UPDATE.

提交回复
热议问题