Data models are representations of things that can be defined by their attributes with data. While this may seem like a complex topic, this article will make data models feel like kindergarten math by providing simple explanations and real world examples.
This is an important topic as data models are foundational building blocks of all modern systems. At the end of this article you will have a solid understanding of data models and how to use them to create applications. This is a valuable skill.
I will try to make sure this article is not boring so you make it to the end without too much pain. 😀
Are you ready? Let's go!
First a question: are you a dog person or a cat person? (or neither!)
What do you like about dogs? How could we quantify what a dog is in a data model to encapsulate its attributes? There are simple physical features like color and breed, but there are also more nuanced features like friendliness.
If we wanted to build a simple application so that dog people could understand what type of dog might be best for their situation we could start with the following data model:
- Color - like Black, brown, white etc.
- Breed - as in Boxer or German Shepherd or Chihuahua.
- Friendliness Factor - This could be a scale from 1-10. A pit bull might be a 1 and a golden retriever might be a 10.
This is a very simple data model and we could certainly find different ways to describe a dog. But this will do for now.
Using this data model, we could recommend that a family wanting a dog for young children get a dog with a friendliness factor in the 8+ range. In contrast, someone wanting a guard dog for a warehouse wouldn't want a dog that would lick intruders to death! They'd want a dog more like a doberman pinscher with a lower friendliness factor.
Don't get hung up on any inaccuracies here if you happen to have a very friendly doberman or pit bull! Lock in on the idea of modeling a real world thing by its important characteristics.
That is all a data model is.
Have you every done a home project? Personally I don't enjoy home projects, but I do them all along.
For a larger project like building a pull-up bar in your back yard
, how do you get it done? You generally need to follow a sequence of steps.
The idea of a project is more abstract than a dog because it is not a physical thing. So it may not be as obvious but we can still create a data model to represent a project.
In this case we are going to create a more complex data model that includes two related things: a Project and its associated Tasks.
How can we define our Project data model? Let's start simple:Project
- ID - a unique identifier of a project; generally a number
- Name - a descriptive value of what you want to accomplish.
Many data models are that simple. We just need a name or title that provides a simple description of what we are modeling. In this case the related Task model is where we codify more information into our data model. Consider the following Task data model:
- Title - a descriptive title of the task
- Description - the full details of the task
- Due Date - the date the task needs to be done by
- Responsible person - who is going to do the task
- Completed - is the task done or not?
- Project ID - the project is this task associated with
This is the data model for a simple project management system. A new topic in this design is the idea that data models have an ID that uniquely identifies it. These IDs are then used to define relationships. In the case above the Task data model will have a Project ID field that connects it to a specific Project. This design allows our system to support many different projects that all have their own set of tasks.
In data modeling parlance what we have described so far are conceptual data models. Conceptual data models describe what is in the data model without concern for how it will be implemented within a system. In conceptual data models you'd consider each thing you're modeling as an Entity (a real world thing or idea) and its characteristics as as Attributes including any Relationships.
One key aspect of data modeling is supporting different types of data attributes. Below are several common types of data you can use to define your data:
- Text or Strings - This data type is used for attributes or fields that are simply alphanumeric text. The Title and Description of the Task data model would be codified this way.
- Numbers - This can be any numeric value and sometimes may be further categorized as Decimals or Integers. Using a Number data type for a field provides a signal to the system that calculations can be performed on the field. A persons weight is an example of a field that could have a numeric data type.
- Dates - This data type signified a specific day on the timeline of history or the future. It could be further specified as a "DateTime" if you also wanted to codify the time of day of an event.
- Boolean - This is a true/false or yes/no or binary value. A classic example of this is the Completed attribute in the Task model above. You would mark a task as Completed being true as you finish each task.
- Relationships - This "data type" is generally an ID that connects or relates a data model to another data model and is where real power of these ideas come to life. Being able to relate data models to each other allows for the creation of new complex data types (that are in turn built with their own set of primitive data types above). In the example above a Task data model becomes its own data type that is connect to a Project by the Project ID.
Other types of data could be included but for now this list is sufficient. We are not trying to create an exhaustive set of definitions for data models here (that would be too exhausting for you to read!! :-) but merely outline the core principles to understand data models.
Data models simply provide a set of ideas for how you capture the salient details of real world things and ideas with data. You can literally model anything with data by following the ideas within this article.
One of the core features of WeBase is the ability to define data models in an intuitive way with a spreadsheet like interface.
The next step for you to creating a few different data models yourself in order to get that visceral experience that will make the ideas presented here more real to you and eventually lead to full mastery of this subject. Here are a few ideas: Build a data model of a Friend and include their birthday as the foundation of a system for keeping up with their special day. Or create a Trip data model that could include all the places you want to go to! Or model ideas like our solar system, or if you like cooking model out Recipes and Food.
You can literally model anything! What data models will you build today? Feel welcome to Sign Up for a free WeBase account and start modeling and be sure to reach out to us and let us know what you build! Especially if you'd like to include your data models in our data model library.