Relational database

In general, the term relational database denotes a specific form of storing and managing data. In a relational model, databases (which might be related to each other) are stored as tables, in the same way as we have seen in the various tables from our current example (Album, Artist, Customer, and so on). Each attribute of an entry in the database is formalized as a column in the database table, and all entries in the table must therefore share the same set of attributes.

In a database table, each entry must have a unique identifier, which will be used by the underlying data management system to keep track of all the existing entries. Such a unique identifier can often be referred to as the key of the database table, and no two unique keys can hold the same value in a common database table. In the Album database we considered earlier, the AlbumId attribute is used as the key for the table.

The most important aspect of a relational database is the ability to represent any relationships between different databases. A relationship is represented as a reference by an entry in a given database table to one in another table. Generally, a relationship denotes a connection between entries in different database tables.

For example, in the database system of a university, there are two different database tables: one containing information on its students, and one on professors that teach there. Each student has a faculty advisor assigned to him or her, which is one of the professors in the university, and we would like to store that information in the first database for the students. Each entry in that database should then have an attribute that references a professor or, in other words, an entry in the second database.

This kind of reference is typically done via a foreign key. Basically, in the attribute for the advisor information, each student entry will hold the identifier for the corresponding professor entry in the professor database. This way the underlying system can always go from a student entry in the first database and look up the information on their advisor in the second database. The term foreign key is used since the keys in another table are being used as data for an attribute in a given table.

This design is illustrated in the following diagram:

Student-advisor relation diagram

We can interpret the preceding information as the following:

  • Alice has Professor Ken as her advisor.
  • Bob has Professor Richard as his advisor.
  • Caroll also has Professor Ken as her advisor.

Coming back to our current example with the Album database table, we see that each entry denoting each album object has an attribute called ArtistId, which references the Artist table. This relationship denotes an album and the artist that produced that album.

Now, we see that by visualizing the student-advisor relationship with arrows pointing from the referencing table (the student database) to the referenced table (the professor database), we can quickly understand the nature of the relationship. In the next subsection, let's see how PyCharm can streamline that process for us.

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

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