Get startedGet started for free

Working with relational data models

1. Working with relational data models

We will learn how to create relational data models in this video.

2. Basics about relational data models

To start we define the term database model. A database model is a type of data model that determines the logical structure of a database and fundamentally determines in which manner data can be stored, organized, and manipulated. In general, there are some data modeling techniques we should know when we are working with a database. One of these modeling techniques is the concept of relational database models. The relational database model is the most widely used database model and is the standard in database development today. To be able to work with a relational database model, we have to know the different parts of such a model. Generally, it consists of tables, attributes, relations between the tables, and relational algebra. We will learn more details about each of these elements, in the following slides.

3. Tables and attributes

The first two elements are tables and attributes. One basic property is that every table must have a name. In this example, we have a table Personal_Data. This table consists of the attributes ID, Name, and Birthday represented by the columns of the table. To finalize a table we have to insert data into the table for each row. This could be, for example, ID equals 1, the name is Adam Smith, and the birthday is the day 1, month 3, year 1978.

4. Create relations

The concept of tables is well-known. Now, we will learn why relational data models are called relational. As the name indicates, we need relations. These relations are defined between tables. To create these relations, we have to define keys. There are two types of keys, primary and foreign keys. The primary key is always unique and is present for every row in the table. In the example on the right, we can see two tables, Person_Data and Order. In Person_Data the general data of a person is stored. The primary key of the table is the field ID. The second table, Order, has three columns, OrderID, ProductName, and PersonID. PersonID is the foreign key of the Order table and is the primary key of the Person_Data table. To build a relation, we can connect these two tables to know, for example, how many orders a person has. We can connect these tables by joining the tables on PersonID and ID.

5. Define primary and foreign keys

To define the primary and the foreign key we have to know the syntax to define the fields. The primary key is defined by fieldName fieldType NOT NULL PRIMARY KEY. An example for the table Person_Data is ID INT NOT NULL PRIMARY KEY which defines ID as a primary key. The definition of the foreign key is fieldName fieldType FOREIGN KEY REFERENCES tableName(primaryKey). An example is newID INT FOREIGN KEY REFERENCES Person_Data(ID). The foreign key newID references the primary key ID of the table Person_Data.

6. Relational algebra

The last element that makes up relational data models is relational algebra. Relational algebra is the formal language for relational databases, and makes it possible to form a new relation between two or more tables. We already know many examples for relational algebra like select, union, difference, or join.

7. Let's practice!

We now know the basics of relational data models. Next, we will practice these concepts by creating such database models, inserting data correctly into these tables, and finally selecting a new relation from the existing tables.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.