Smallest unit of information when stored on a paper or electronic memory we call it data. Related data about a person or entity or thing is called a record. Collection of records builds tables and collection of tables generates databases.
When a new record is added or updated or deleted we say a transaction on the database has been carried out. Databases are important to store records and transactions on databases can be performed by authorized persons only.
Size of database depends on type of application, quantum of users, and number of records. Records of transactions performed on databases are stored in the same database or on a different database. When these databases are stored and maintained by a particular person and at a particular site we say the database is centralized. A centralized database is considered to be authentic as compared to a decentralized database.
When the database is large it becomes cumbersome to store and maintain it as a centralized database, so Database Administrators maintain and store it as a decentralized database or distributed database.
In distributed databases, the database is broken down into smaller databases, maintaining its parent database characteristics and structure, while running in its own environment and having private hardware, software and transactional load.
A centralized database has low data redundancy and is less secure as compared to a distributed database. Cost of maintaining and storing the database is less for a centralized database as compared to a distributed database.
In a centralized database, all databases are located in one place and easily available for analysis. A distributed/decentralized database follows peer-to-peer or master slave network architecture. A peer-to-peer or master slave architecture offers better load balancing, high fault tolerance and autonomy to execute transactions and maintain resources independently. A decentralized or distributed database executes distributed transactions queries. Data Manipulation Language and Data Definition Language queries.
Application of distributed/decentralized databases is Blockchain.
Skeleton of Blockchain
Components of distributed database transaction query consists of:
- A node that fires a query on another node containing a distributed database.
- A node that returns results of a query executed on it.
- A node from where a distributed transaction query is fired.
- A node that carries out an internal process to successfully execute a query.
- A node responsible to execute commit or roll back as directed by the query originator node.
In a distributed transaction, a node is authorized to initiate a commit or roll back. This authorization is approved by the Database Administrator and authorization is given to a node containing critical data. The redo logs are maintained as soon as the commit is executed by the authorized node.
If the commit is not executed successfully then roll back is executed. Roll back is executed on all the nodes and execution of database transaction query ends. Transaction queries are either executed successfully or get terminated by executing roll back. Thus it becomes necessary to maintain database integrity. Distributed database integrity is maintained by a two-phase commit mechanism.
When a commit is executed by a transaction it is given a system change number (SCN). This SCN is used to identify executed SQL statements and changes made by them on a distributed database. SCN is used to identify the committed database version.
SCN maintains distributed database read consistency and gives birth to Blockchain.
Transactions of distributed databases are clubbed together to build Blocks. These blocks are linked together using a hash key. Transaction blocks are used to resolve transactions that are not committed successfully. Transaction blocks are associated with the System Change Number (SCN). SCN tagged blocks are used to serialize and synchronize database transactions.
Blockchain Programming Language
Structured Query Language (SQL) is the Blockchain Programming Language. SQL is used to organize and retrieve relations from a Relational Database. SQL is used to work with structured data. SQL is used to execute Data Query Language (DQL), Data Definition Language (DDL), Data Control Language (DCL), and Data Manipulation Language (DML).
Example of Blockchain Programming Language using SQL
Case – I: Online purchase of Puliyodarai
…. …… ... select j.tablein_posss, o.pubkeyy_hash, o.textout_valuue from txx tt join tablein i on (tt.txx_id=i.txx_id) join txout_detail o on (o.txout_id = i.txout_id) where tt.txx_hash = ‘b2123sd43f215ff5ab231h63f2571k156’ order by 1 asc; .. … …….
…. ……. …... select table2.txx_hash as txx_hash, q.pubkey_hash as address1, Oo2.txout_poss as position2, Oo2.txout_value as amount from txx t11, txout Oo1, txxin i, txx tt2, txxtout Oo2, pubkeyy pp where tt1.txx_id = Oo1.txx_id and ii.txxout_id = Oo1.txxtout_id and Oo2.txx_id =i.txx_id and ii.txx_id = tt2.txx_id and Oo2.pubkey_id = pp.pubkey_id and tt1.txx_hash = ‘b2123sd43f215ff5ab231h63f2571k156’ … …… ….