Simple Explanation To Relational Database Concepts / RDBMS


Structure of a database: 

To know what a relational database is, we have to learn the concept of a database. A database contains one or more tables of information. The rows in a table are called records, and the columns in a table are called fields or attributes. A database that contains only one table is called a flat database. A database that contains two or more related tables is called a relational database. There are other more complex kinds of databases, but this article is going to focus on the what and why of relational databases.


What are the benefits of dividing your data into multiple tables?

Imagine that you are responsible for keeping track of all the books being checked out of a library. You could use a single table (a flat database) to track all the critical information.

This table contains all the information ( phone, name, date...), about who checked a book out, but this way of storing has some drawbacks in terms of space, efficiency, and waste of time. For example, as voracious reader Bob checks out more books over time, you will have to re-enter all of his contact information for every book.

To re-enter Bob’s contact information wastes time, and increases the opportunity for error. Moreover, when an update is necessary ( e.g. Bob’s phone number changes), each of Bob’s records must be located and corrected. If one of Bob’s records has a different phone number from the rest, is it a correction, a record overlooked during the last update, or a data-entry mistake? These problems can be decreased by normalizing our data – in other words, dividing the information into multiple tables to have “a place for everything, and everything in its place.” Each piece of information should appear just once, simplifying data maintenance and decreasing the storage space required. 




Now that the data are arranged efficiently, we need a way to show which records in the PATRONS table correspond to which records in the CHECKOUT table – in other words, who checked out which book. Instead of repeating everything we know about a patron whenever he checks out a book, we will instead give each library patron an ID, and repeat only the ID whenever we want to associate that person with a record in a different table.



Now the PATRONS and CHECKOUT tables can be related.


Primary Key:

The primary key is a field (column) whose values are unique in this table, and so can be used as identifiers for the records. In table PATRONS, the Patron ID field is the primary key and so its values must remain unique. For example, the value “2” can appear only on one record - Alicia’s - and Alicia can have only one Patron ID - “2.” Is the Patron ID field in table CHECKOUT the primary key? We can see that it contains duplicate values, so the answer is No. If Patron ID were the primary key for CHECKOUT, each person would only be permitted to check out one book, and afterward would be forbidden to check out any more books, ever. 

If Patron ID is not the primary key for table CHECKOUT, which field is? We can’t make Book Title the primary key, or we’d have a similar problem – each book could only be checked out once, and afterward no one would be permitted to check it out ever again. We can’t make Due Date the primary key, or else only one book could be due each day. Since none of the existing fields works as a primary key, we will add a new field to hold an identifier for each record. We could name this field Checkout ID, or we could follow ESRI’s convention of giving all primary key fields exactly the same name: Object ID.


Now that we have a primary for each record. let's separate all of them and make a table for the CHECKOUT TABLE will have all the primary keys , and make a table for books information into their own table.


Parent Child Tables:

When two tables have an unequal relationship, we call the independent table the parent and the dependent table the child. You can identify the parent table by determining which table could contain a record without needing a corresponding record in the table on the other side of the relationship. For example, is it possible to have an unpopular library book which never gets checked out? Yes. Is it possible to check out a book that doesn’t exist? No. Since BOOKS can contain records that aren’t referenced by CHECKOUT, BOOKS is the parent in this relationship, and CHECKOUT is the child.

Another way to identify the child table is to find the field which refers to the other table’s ObjectID. BOOKS does not contain an ObjectID field for the CHECKOUTS, but CHECKOUTS does contain a field to store Book ObjectIDs. Therefore, CHECKOUTS is the child table in this relationship.

orphan

If somehow the child table contains a record that does not have a corresponding record in the parent table, that record is called an orphan. Orphaned records are a problem that generally requires attention from the database administrator.

cardinality

The last new concept to consider is cardinality, which describes how many records in one table can be related to records in another table. Two tables might have a cardinality of 1-1 (one to one), 1- ꝏ (one to many), 1-3 (one to three),  -  (many to many), etc. The PATRONS – CHECKOUT relationship has a 1- ꝏ cardinality, because 1 patron may have any number of checkouts, from zero to infinity. Put another way, the CHECKOUT – PATRONS relationship has a cardinality of  - 1. If the cardinality of PATRONS – CHECKOUT were 1-1, then each patron could check out only one book. If it were  - , then several patrons together might share joint responsibility for one or more checkouts. 

 The BOOKS – CHECKOUT relationship is also 1 -  since one book may be checked out multiple times.

Post a Comment

Previous Post Next Post