Relational (SQL) and Non-Relational (NoSQL) Databases

 

What is a database (DB)?

A database is a collection of data belonging to the same context and systematically stored for later use. Thus, a library can be considered a database composed mostly of documents and texts printed on paper and indexed for consultation.

The relational database (RDB) or SQL: SQL (Structured Query Language), is a type of database (DB) that complies with the relational model, which is the most widely used today and stores the following data:

  • The name of each table.

  • The name of each column.

  • The data type of each column (numeric or alphabetical).

  • Record, line, or row of the table.

Relational databases go through a process known as normalization, the result of this process is a schema that allows the database to be used optimally together with other databases of other entities or projects.

Non-relational databases (BD NoSQL): They are specifically designed for specific data models and have flexible schemas for building modern applications. They use a wide variety of data models, such as document, graph, key-value.

NoSQL databases use the JSON (JavaScript Object Notation) format, this text format facilitates data exchange and is independent of the programming language used.

Model 1: MongoDB:

Instead of storing data in tables, as is done in relational databases. Documents are the heart of MongoDB. It is an ordered set of keys with their corresponding value. A document would be like a row in a BDR system, but without the imposition of a fixed schema.

Model 2: Firebase: is a database developed by Google and is a web service that provides a cloud backend with a real-time NoSQL data source and libraries to access the database from web, IOS or Android applications.

Example 1: We take the first BDR record of the Central University students and express it in JSON format:

  • It is expressed between braces {}.

  • We have 5 elements separated by commas.

  • Each element is formed by a key pair: value, example "Identity": 25089.

Example 2: We take the three records from the BDR of the Central University students and express it in JSON format:

The most used programming models for dealing with JSON in different languages are:

Object model: The complete JSON is stored in memory in tree format. This tree is scanned, parsed, and modified with the appropriate APIs. Since it loads everything into memory and then processes it, this model consumes a lot of resources. However, it is very flexible when it comes to manipulating the content.

Flow model: Data is read or written in blocks. For example, each time a block is read, the parser generates the appropriate events to indicate what type of block it is. The API client can process the content by listening for the appropriate events. In addition, it is the API client that decides how the JSON is read, allowing the content to be stopped or skipped in the middle of the process.

 

Databases in JSON format and their application in blockchain.

Example of a block

JSON format databases have facilitated the development of blockchain technology. Below, we illustrate the data for BTC block 154,595:

This block has:

  • 15 elements separated by commas.

  • Each element consists of a key: value pair, for example, the first element is:

    “hash”: “0000000000000bae09a7a393a8acded75aa67e46cb81f7acaa5ad94f9eacd103”.

  • The second element is “ver”: 1. 

Example of a transaction

This JSON has:

  • 11 elements separated by commas.

  • Each element consists of a key: value pair, for example, the first element is:

    “hash”: “b6f6991d03df0e2e04dafffcd6bc418aac66049e2cd74b80f14ac86db1e3f0da”.

  • There are complex elements such as: “out” = [

     { ---------

    --------------}

    ]

Closing remark:

The block and transaction presented here, in JSON format, are not encrypted, this is done later when the transaction is processed and stored on the blockchain.

 
Carlos Sampson