Search code examples
memgraphdbopencypher

When should I use CREATE and when MERGE in Cypher queries?


I've seen that sometimes CREATE is used to create nodes, and in other situations, MERGE is used. What's the difference, and when should one be used in place of another?


Solution

  • CREATE does just what it says. It creates, and if that means creating duplicates, well then it creates.

    MERGE does the same thing as CREATE, but also checks to see if a node already exists with the properties you specify. If it does, then it doesn't create. This helps avoid duplicates.

    Here's an example: I use CREATE twice to create a person with the same name.