Representing Common Data Structures In SQL

I'm Kenneth and I am software engineer. Here to share my experiences to the world and to learn from everyone as well.
Search for a command to run...

I'm Kenneth and I am software engineer. Here to share my experiences to the world and to learn from everyone as well.
No comments yet. Be the first to comment.
When defining application components, a good strategy is to split by functionality. In a blogging application, we'll have a component to represent the WYSIWYG editor then, another to hold the publish settings. In this particular example, the publish ...

In this post, I'll show you how to implement feature management on your React applications. Feature management is the way to control which features are available based on certain scenarios. Why Do Feature Management? Here are some scenarios where con...

When I create content, I start off with a topic. Then, I create different content pieces revolving around that topic targeting different platforms like Hashnode, Dev.to, or Twitter. In fact, I recently Tweeted about this, that content creation nowada...

In this post, we'll go through the process of creating an API built using Express and MongoDB. We'll cover the ff. steps: Setting up MongoDB Creating an Express application Optimizing your Express routes Handling errors Let's start! Setting up Mong...

In a React + React Router environment, routing configuration is a one-to-one mapping between a route and that route's display elements. Here's a basic example: <Route exact path='/' component={Home} /> <Route exact path='/drafts' component={DraftList...

When designing an application, you usually start with the business processes involved. Then, you extract the data models involved and map out the respective components/services. It's quite a simplified explanation but, you get what I mean!
As part of this planning, we use conceptual data structures to represent data models. Once we start the implementation, we then translate these data structures into actual database tables. Ever wondered how that's done? Then you're at the right place!
In this post, we'll talk about how to represent some of the common data structures in an SQL database.
For the purpose of this post, we'll cover the ff. data structures:
We can go ahead and define the SQL representation for the data structures mentioned above, but, we can still simplify this!
In fact, some of the characteristics mentioned above are more tied to how these structures behave and not on how they store data. After realizing this, I further grouped the data structures into 2 categories:
Now that we have these categories, we don't really need to represent each individual data structure in SQL. We just need to represent these 2 categories instead!
It's time for me to show you how I will represent the above categories in SQL. Let's go!
In terms of representing linear structures in SQL, we just need to take note of 2 things:
Here's the ERD for Linear Structures:

In the above diagram, we used a many-to-many pattern where we defined 2 tables:
Additionally, each node can have 0 or more edges.
In terms of representing ranked structures, we just need to take note of 2 things:
Here's the ERD for Ranked Structures:

In the above diagram, we defined 3 tables:
We made this diagram more flexible so that we can put a single item in multiple lists. Additionally, each ItemRank record has 2 primary keys: ItemListId and Rank. This means that in each list, we don't want items to share a particular rank.
Also, there are other approaches to doing this. If you happen to know one, I'd love to hear from you so, share your thoughts in the comments below!
In this post, we went through how to represent some of the common data structures in an SQL database using the ff. steps:
I know there are tons of other ways to represent these common data structures in SQL. If you know one, feel free to share them in the comments!
Hey, you! Follow me on Twitter!