Relational versus non-relational DB

So, besides ACID and BASE compliance, what is the real difference between relational and non-relational databases? Essentially, we have the ability to provide roughly the same features from both of these database types: storing data, both can do that; support for transactions and scripting, yup, we can do that on both as well. It's just that the database types are better at doing one specific thing. Relational databases are better at scripting, complex transactions, table joins, and so on, whereas non-relational databases are better at storing huge datasets of simple values that we need to retrieve at very high performance rates; some non-relational databases support scripting and transactions, but they are much less efficient at it.

The biggest difference is probably in the datasets themselves. Relational databases are designed to store data according to a schema; imagine a table with columns and rows. Each column has a purpose and each row is treated as a separate entry with atomic pieces of data that can be addressed separately. With non-relational databases, an entry could be any kind of piece of data: a document, a value for a key, a map, a graph, a stream, and so on. Non-relational databases typically do not have a schema and can store variable sizes and types of entries in the same table.

Now, let's compare the data for a real-world example; relational database entries will look like this:

Index Name Surname Position Active
1001 Johan Dohe Engineer Y
1002 Ben Dopher Administrator Y


We can see that each entry has its own index and each entry has specific values for each field.

In a NoSQL database, the data might be stored in a JSON format like so:

{
"Index":"1001",
"Name":"Johan",
"Surname":"Dohe"
"Position":"Engineer"
"Active":"Y"
}

Essentially, instead of formatting the table, we create a document repository, and when we upload the document, the service might present those values as entries in a table to achieve the same purpose.

How about when we need to change the data and add more information to the user? Let's say we want to give the group information only for all the administrators in our database. With a relational database, we would need to extend the schema to accommodate new entries for each index, whereas with the NoSQL database, there is no schema. We can simply add information to our user by adding more key-value pairs like so:

{
"Index":"1001",
"Name":"Ben",
"Surname":"Dopher"
"Position":"Administrator"
"Active":"Y"
"Group Membership": [
{
"Sales":"Administator",
},
{
"Tech":"Member",
}]
}

This adds more attributes to the entry on the fly without having to extend the schema of the database, a clever feature of NoSQL databases that can make quite a difference.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.76.138