-1

我有两个表,例如 customer_name 和 customer_phone,但唯一的客户是从两个表中的所有四列的组合中识别出来的。

由于我们有多个源系统同时插入到下表中,在所有这些工作中,我们在插入之前使用一个函数来验证客户是否已经存在,使用 (f_name,l_name,area_code,phone_num) 这个组合。然而,我们仍然看到重复插入,因为验证发生在其他作业已经插入但尚未提交时。有没有避免重复的解决方案?

顾客姓名

列:ID、名字、姓氏

cutomer_phone

col: ID,area_code, Phone_number

4

1 回答 1

0

是的。不要在应用程序中进行检查。让数据库使用唯一索引/约束进行检查。如果我不得不猜测你想要的约束:

create unique index idx_customer_name_2 on customer_name(first_name, last_name);

create unique index idx_customer_phone_2 on customer_phone(customer_id, phone_number);

然后数据库将进行检查,您不必担心重复 - 尽管您应该检查插入时的错误。

于 2015-06-24T09:57:05.947 回答