Skip to content
Advertisement

explain differences between two different updates

I have 2 different update queries, one I created:

my colleague preferred this one:

He can’t explain which one should be better and neither can I. The only difference I have, is that the update on the second query crashes when there are no results to update.

Can anyone explain what’s the difference?

Advertisement

Answer

To sum it up:

The first approach (parameterized query/prepared statement) is best, because it

  1. is easy: automagical quoting and formatting of the parameters
  2. can be more efficient: the DBMS may optimize
  3. avoids fetching and storing the resultset (@Ansgar)
  4. scales better: would work for many records without change
  5. guards against SQL-Injection

The second approach is worse because not having features 1 – 5 and worst/naive because not checking for an empty recordset (@peter, @Cageman).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement