Skip to content
Advertisement

SQL – Violation of UNIQUE KEY constraint

I am trying to find the solution for the below query:

There are declared tables @Country and @WHO (World Health Organization).

Insert all possibles countries from table @Country into table @WHO.

The code for the tables is:

The code that I started looks like this:

The final result should be a table that contains:

I know this is probably an easy one but I cannot seem to find a solution.

What am I missing out from my code? 🙁

Advertisement

Answer

You can use not exists:

A (possibly overkill) alternative is the MERGE syntax:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement