unique constraints are very common for database table designs in applications nowadays. there are two ways to safely code an application to cater for this unique constraint requirement. (1) do an existence check/query before doing the insert. (2) let the database throw a unique constraint and handle it.
i have always viewed option 1 to be the wrong way to do it because it is still possible to fail if an insert of the same unique data happened in between the checking and the intended insert. i always advise option 2, let it throw. performance wise, option 1 involves two queries as opposed to option 2's single action query.
i was surprised that they opted for option 1 but the rare scenario is still handled by their application: user will be issued by an error page, user will re-fill up the same data (unlucky him), and when the duplicate check is done again, he will be presented by a "data already exist" message.
Posted
Apr 24 2007, 06:52 PM
by
jokiz