Relational Database Vs. Hierarchical Database

Techwalla may earn compensation through affiliate links in this story.
Relation and hierarchical databases are two of the most common kinds of databases.

Databases are computer programs that store data, or "records." More importantly, they also describe how that data relates to other data in the database. There are many different kinds of database, including hierarchical, network, relational and object oriented. They all serve different purposes, and allow their records to be described in different ways.

Heirarchical Databases

Hierarchical databases are some of the oldest and simplest kinds of database. They arrange data in a "tree" structure, which is similar to folders and files on a computer. Just as a file on a computer sits in one folder, every record in the database has one "parent." Hierarchically arranged data is often described as having only parent/child relationships.

Problems with Heirachical Databases

While the hierarchical model is a suitable one for simple structures, it is easy to see how problems might arise, as each "child" can only have one "parent." If the database contained the names of actual parents and their children within a company, you would not be able to describe the fact that both parents of a single child worked for that company. In the language of databases, this would be a "many-to one" (or "many-to-many" if there is more than one child involved) relationship, and hierarchical databases don't describe them well.

Relational Databases

Relational databases have no problems with many-to-one or many-to-many relationships. Their records are built as multiple "tables," rather than tree structures, and each record on a table has a unique identifier. A company could then have a table with the names of all the parents, a table with the names of all the children, and each record on the parent table could have a relationship with one (or more, or none) of the unique records on the child table--that relationship being "is the parent of." The ability to give records such relationships is what give relational databases their name.

Advantages of Relational Databases

Relational databases prevent errors by allowing one record to apply to any number of other tables. A child record could be used in a "is the child of" relationship, and the same record could be referred to in a table of "children attending the company picnic." By preventing duplication, the same information can be used in many different ways, without accidentally altering a record.

Also, relational databases are very good for providing other kinds of data hidden in the records, using queries written in Structured Query Language, or SQL. This enables you to explore the database in ways not immediately apparent, such as finding all the children over a certain age, or all the parents with three or more children.

Using Hierarchical Databases

It might seem that relational databases are superior to hierarchical ones, and it's true that they are more flexible. But such flexibility is not always necessary for every database. Libraries use hierarchical databases for recording their books, as the Dewey Decimal system is hierarchical in nature. A list of contact phone numbers might be perfectly well served by a hierarchical database. A database is a tool, and the right tool for the job depends on the job at hand.