Adam
Adam

Reputation: 10036

Storing data structures in SQL databases

Here's the problem I'm trying to solve:

I need to design a database capable of storing user data and post data. Among other things, each entry in the user table needs to track a series of post attributes we've determined that the user likes. For each post, I need to store a list of attributes associated with the post.

I'd like to use a linked list to track post attributes and a hash table to track a user's likes (I'll be doing a lot of "for each attribute of this post, check if the user likes it"?). The trouble is I don't have any idea how I could store those data structures in a relational table. Is something like that even possible? If not, can you offer suggestions on alternative implementations?

Upvotes: 1

Views: 2307

Answers (1)

I'll talk specifically about SQL databases, because I've got a little more experience with them than with other kinds of databases.

A SQL database has essentially one data structure: the table. You really don't want to use tables to implement linked lists or hash tables. And you don't want to store linked lists or hash tables in a database.

The concerns that make you want to use a linked list (manage unbounded memory?) or a hash table (fast searches?) have already been taken care of by the people who designed and built the database management systems.

So you just need to build the right tables. You'll find that building tables is simple, but building them right might be far from easy. Google is your friend.

Upvotes: 2

Related Questions