Bookmark Topic Watch Topic
 
friki data migration
Ranch Hand
Posts: 772
1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Use the MERGE statement when possible

Many developers are unaware, or afraid of the powerful MERGE statement. Some databases know other forms of UPSERT statements, e.g. MySQL's ON DUPLICATE KEY UPDATE clause. But MERGE is really so powerful, most importantly in databases that heavily extend the SQL standard, such as SQL Server.

The Cure:

If youÂ’re UPSERTING by chaining INSERT and UPDATE or by chaining SELECT .. FOR UPDATE and then INSERT or UPDATE, think again. Apart from risking race conditions, you might be able to express a simpler MERGE statement.

Source


SqlBestPractices
 
    Bookmark Topic Watch Topic
  • New Topic