Home > Net >  Data update
Data update

Time:04-26

Now there is a scene, there is such a registration method to execute the query query did not have a user data to insert inside, but now the same time, there are two requests as well as a moment will perform two times this registration method, which leads to the first query is not user followed by the second is no user will perform two insert the last database so there will be two such user, how to solve this problem, consult

CodePudding user response:

Insert before modifying

CodePudding user response:

No matter how you concurrent processing data of only one does not exist at the same time two that directly under the simple and crude way is to change insert statement to
If the exits (query)
The begin
Insert
end

CodePudding user response:

Is there a better way of

CodePudding user response:

refer to the second floor qq_30335331 response:
no matter how you concurrent processing of the data is only one does not exist at the same time two that directly under the simple and crude way is to change insert statement to
If the exits (query)
The begin
Insert
End

And so did my logic, the execution order now is
1: the exits () for the first time the front-end request
2: the exits () followed by a second request
3: insert the first
4 the insert for the second time

CodePudding user response:

Data table on the primary key of the uniqueness, is by the database system to ensure
No matter how concurrent is the only
So the insert first, then according to the increased key change is the safest solution
  •  Tags:  
  • C#
  • Related