loading...

re: Best way to store array type data inside database? VIEW POST

FULL DISCUSSION
 

Hmm, did you discard creating another table? What was the reason behind?

 

What do you mean by creating another table?

In the second option I am creating another table name tags to store the connection between the posts and tags.

 

I'm sorry, I totally missed. I just though that you would storage the array in a varchar (or any lob type) using JSON o separating it with |.

I would go for this three tables: posts, tags and post_tags (Or any naming you like).

posts --> All the posts
tags --> A master table with all the tags
post_tags --> A table with a post_id and tag_id to do the many to many relationship.

A table with a post_id and tag_id to do the many to many relationship.

You mean a single row of post_tags can contain multiple tags_id column.

I mean something like:

posts

post_id other_value
1 something
2 something
3 something

tags

tag_id tag_text
1 tag1
2 tag2
3 tag3

post_tags

post_id tag_id
1 1
1 2
2 3
3 1
3 2
3 3
code of conduct - report abuse