# Why Graphs Should not be Stored in a Relational Database

2020-09-16

One minute

Suppose you have graph-like data that describes the (undirected) relationship between `target`

and `destination`

. If we store these relationships in a traditional relational database with a single key to query on we would have something like this,

```
target, destination
A, B
A, C
B, A
B, C
C, A
C, B
...
```

So to get all relationships associated with A we can just filter A on the target column. This is inefficient since we are replicating a lot of information (e.g. storing both A, B and B, A, even though the relationship is the same.

Alternatively we could store it as,

```
target, destination
A, B
A, C
B, C
```

But now to get all relationships with A we have to filter on both the target and the destination column, which is a little clumsy.

If we store it in a graph like database then we would have a single column to query on (the nodes) which will give us all the relationships for a given node (by following the edges for the node we’re filtering on).

176 Words