What is Difference between CREATE UNIQUE and MERGE?

Hi! i'm newbie in neo4j. i just read some references about cypher.

Form the defenition i got so far, I found that CREATE UNIQUE and MERGE are same queries.

is there any differences between these two queries?

They're mostly the same. Historically CREATE UNIQUE has been established before MERGE. These days you shouldn't use CREATE UNIQUE any more, it's deprecated and will be removed at some point in future.

1 Like

As Stefan mentioned CREATE UNIQUE is deprecated, so please avoid it.

The primary differences, however, is that when provided a pattern CREATE UNIQUE will try to find as much of the pattern as possible in the existing graph and create anything that doesn't exist.

MERGE however will attempt to first MATCH to the entire pattern (and if so use all matched paths), and otherwise the entire pattern will be created.

In the event that the pattern needs to be created, if the pattern contains variables that are already bound to existing graph elements, those elements will be used within the MERGE (rather than being created), but any newly introduced variables (that are not already bound to existing elements through previous matches) will be created instead.

While MERGE may seem more complicated, it covers use cases that are just not possible with CREATE UNIQUE alone, and thus it's the better option and the reason why CREATE UNIQUE is deprecated.

For more information on MERGE and its behavior, check out our knowledge base article on MERGE.