I needed an SQL query that would update or create a database entry (if a certain customer doesn’t exist yet). I found the current solution on the internet:
command.CommandText = "REPLACE INTO [Resource_Tracer].[dbo].[Customer](CustomerName, CustomerID) VALUES (@CustomerName, @CustomerID)"
Since I don’t see it used a lot and actually never heard of it before, is this really the solution I want, or should I do this manually?
Both
REPLACE INTOand theON DUPLICATE KEYalternative suggested are non standard SQL from the MySQL variant. So whether you use it depends on a) whether you’re using MySQl and b) whether you want to be tied to that variant.ANSI SQL defines a
MERGEsyntax that is more standard, if it is implemented on your platform