Code for checking the same data present in table column

前端 未结 1 672
逝去的感伤
逝去的感伤 2021-01-28 16:07

I am facing a problem, that in my customer info table the customer id, contact no & E-mail address should not be same for two or more customers.I also have set custmomerid a

相关标签:
1条回答
  • 2021-01-28 17:01

    If i understood correctly, you need to prevent duplicate entries on customerID, contactNo and Email. The most straight forward answer is put the primary key on all three columns. This would throw a DuplicateRecord Exception when adding a record that already exists and you should properly catch it.

    Another way is to check in the query (with execute scalar):

    "IF EXISTS(select 1 from customer_info where customerID = ... and contactNo = ... and email = ...)

    BEGIN select -1 RETURN END

    insert into Customer_Info values('.......... (your query)"

    Hope that helps

    0 讨论(0)
提交回复
热议问题