For faster navigation, this Iframe is preloading the Wikiwand page for Merge (SQL).

Merge (SQL)

Een MERGE-opdracht in SQL wordt gebruikt in combinatie met INSERT en UPDATE voor het invoegen of bijwerken van bestaande records afhankelijk van de opgegeven conditie. Het werd voor het eerst geïntroduceerd in de SQL:2003-standaard, en later uitgebreid in de SQL:2008-standaard.

Het MERGE-statement is met name praktisch bij het uitvoeren van meerdere INSERT en UPDATE instructies, omdat er slechts een instructie gebruikt hoeft te worden.

Sommige implementaties gebruiken de term 'Upsert', een porte-manteau van Update en Insert. Hiermee wordt een niet-bestaand record in een tabel ingevoegd, of als het record wel bestaat, de gegevens ervan bijgewerkt. Dit synoniem wordt toegepast in SQLite en Microsoft Azure SQL.

 MERGE INTO doeltabel USING brontabel ON (conditie)
   WHEN MATCHED THEN
   UPDATE SET kolom1 = waarde1 [, kolom2 = waarde2 ...]
   WHEN NOT MATCHED THEN
   INSERT (kolom1 [, kolom2 ...]) VALUES (waarde1 [, waarde2 ...]);

Om aantallen bij te werken of in te voegen in de tabel 'verkoop' waarbij het artikelID gelijk is, gebruikt men:

 MERGE INTO verkoop USING producten ON (producten.artikelID = verkoop.artikelID)
   WHEN MATCHED THEN
   UPDATE SET aantal = 50
   WHEN NOT MATCHED THEN
   INSERT (aantal) VALUES (50);
[bewerken | brontekst bewerken]
  • (en) MERGE MSDN-documentatie
  • (en) Introduction to the MERGE Statement Essential SQL
{{bottomLinkPreText}} {{bottomLinkText}}
Merge (SQL)
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?