DEV Community

Discussion on: Best way to store array type data inside database?

Collapse
 
scottandrews98 profile image
Scott Andrews

Personally I would use the second approach but make a link table which can group all the tags together via a foreign key.

Cheers, Scott

Collapse
 
mittalyashu profile image
Yashu Mittal

I didn't understood the part about making a link table?

Could you please elaborate that?

Collapse
 
scottandrews98 profile image
Scott Andrews

So I would have two tables. The first one would contain the a primary key of post_id and the name or that post.

The second table would contain all the individual tags linked to that one post. You could then make a foreign key link to the first table.

Hope that makes sense. But think you’ve done this already in your second approach.

Good job

Thread Thread
 
mittalyashu profile image
Yashu Mittal

Right, but using the concept of foreign key we can only link single tab to the post table, not an array of tags. Right?

I might be wrong too, IDK