Hi, I am trying to create an upsert for my table, ...
# cfml-beginners
s
Hi, I am trying to create an upsert for my table, if records exists, update else insert, for a table, anyone knows how to do all in one i am going in google but its too much information instead of just one small page which shows how it is done in sql server
m
What do you mean by "all in one"?
r
sql server has no upsert statement, only workarounds
d
I use if statements in cfml You could use if statemen In sql too
m
i don't use the pattern very frequently, but when i do, i use the approach outlined here under 'the solution'. https://sqlperformance.com/2020/09/locking/upsert-anti-pattern
1
m
I do this with a try/catch in CF. Run the insert first, if you catch a duplicate error, then do the update. Another try/catch around the update will handle its errors Any other error you handle as you normally would. I typically only do this on the "admin" side of an app where I know the user traffic is low or where the routine is not something that is heavily used
s
do you mind sharing code