SQL database treated as a graph