Database:
c_id, name (c_id is a primary key)
Context (made up context for this problem to make sense):
In this context we can assume no one has the same name. I own a hotel and a customer walks in. Her name is Madi Smith (before she got married, her name was Madi Andrews). I do not know if this is a new customer. Then, I do my process:
- first
find_customer(name)which returns me a primary key orFALSEif not found. - If I received a primary key then I always
update_customer(c_id, name)otherwise if the customer was not found Iinsert_customer(name).
However, my hypothetical problem arises when I think like this.
- Process 1 |
Jameswalks in - Process 1 |
find_customer('james')-> return'sFALSE - Process 2 |
Jameswalks in (same person as above) - Process 2 |
find_customer('james')-> return'sFALSE - Process 1 |
insert_customer('james') - Process 2 |
insert_customer('james')
Now I have a duplicate row of james's when they are the same person. How are you actually supposed to insert/update data?