A comparative introduction to organizing and querying data in relational and graph databases.
Relational and graph databases organize data is distinctly different ways.
Traditional relational databases divide data into tables, columns, and rows.
Similar to other graph databases, TerminusDB organizes data in objects. Objects have properties, properties link to other objects. A network of interlinked objects forms a graph structure - the foundation of graph databases.
Using objects rather than cells enables the creation of databases that closely model the real world.
Example using a family tree
A family tree database stores data representing individuals, their parents, and grandparents.
The table below represents a model for storing this scenario in a relational database.
The diagram further below illustrates the equivalent graph database model. An advantage of the graph model is that it represents real-world objects more accurately, making the model intuitive and easier to understand.
Table: Family tree in a relational database
Diagram: Family tree in a graph database
Relational database queries
Many relational databases use the Structured Query Language (SQL.) The example below uses a two-query approach to get the name of mother, then grandmother. Note the second query uses two nested sub-queries.
Graph database queries
TerminusDB's purpose-built Web Object Query Language (WOQL) is an easier-to-use alternative to SQL. The example below demonstrates the same query using WOQL. WOQL uses triple patterns to get both names in one short query. There are no joins - joins are implied by using the same ID in different parts of the query. Using v:mother_id multiple times creates the chain: