0

I am mostly familiar with MySQL, if I wanted to truncate a table I would normally issue the command

TRUNCATE <table>

And to drop

DROP <table>

Now, on neo4j -- what would be the best way to do this?

Louie Miranda
  • 1,012
  • 17
  • 32

1 Answers1

2

The closest equivalent is

MATCH (n)
DETACH DELETE n

The DETACH keyword causes relationships of the nodes to be deleted as well.

This doesn't work well on large graphs (~10M nodes+, depending on your RAM), because the transaction state is held in memory. But you can work around that by repeating following command, which deletes 1M nodes at a time:

MATCH (n)
DETACH DELETE n
LIMIT 1000000
František Hartman
  • 13,638
  • 2
  • 38
  • 57
  • 2
    Note that usage of DETACH DELETE also deletes relationships, which is also added to the transaction. It usually works better in lower batch sizes. You can use `apoc.periodic.iterate()` to delete in batches, which can be easier to manage. – InverseFalcon Sep 11 '19 at 07:51