java - How to check and avoid duplicate records in a MySQL database table? -
this question has answer here:
i using spring boot, maven, hibernate , mysql
i trying determine if better programmatically find out if record exist in database --> table or if better modifying database table not allow duplicates.
any suggestions?
modify database not allow duplicates. purpose of unique constraints on tables.
why right solution? basic reason race conditions. when impose unique constraint, database checking. if try in application layer, there small gap of time between check , insert . . . , thread insert same value during time. and, have duplicate.
Comments
Post a Comment