The term UPSERT has been coined to refer to an operation that inserts rows into a table if they don’t exist, otherwise they are updated. To perform the UPSERT operation Microsoft introduced the MERGE statement. Not only does the MERGE statement support the UPSERT concept, but it also supports deleting records. Greg Larsen discusses how to use the MERGE statement to UPDATE, INSERT and DELETE records from a target table.
The MERGE statement is powerful and multifunctional, yet it can be hard to master. SOmetimes the MERGE statement that just doesn't do what it's needed to do, like process a Type 2 slowly-changing dimension. Check out this tip to learn more.