I have a database that contains two tables:
The entries table contains posts that each have one or more tags. The problem is, each post can have any number of tags. In other words, I can't have a 'tag1', 'tag2', etc. column and do a LEFT JOIN.
How should I set up entries so that each post can have any number of tags?
If space is going to be an issue, have a 3rd table Tags(Tag_Id, Title) to store the text for the tag and then change your Tags table to be (Tag_Id, Item_Id). Those two values should provide a unique composite primary key as well. Show activity on this post.
The classic way to store it is via an embedded array of tags: { PictureUrl: ..., tags: [ "party", "man" ... ] } As long as number of tags is below a few houndreds its fine. You can index tags field with multi key index and simply search terms on tags.
you can store JSON array in mysql>=5.7 for tags like below : ["tag1","tag2",...] if you use an extra table for store tags , you need to join and search for adding a new tag , its bad way when we have too many tags in database !
The SQL tagging feature in Siebel Business Applications is a diagnostic tool that allows administrators to trace long-running or slow-performing queries back to the user or action that triggered it.
You need a mapping table.
Create a table called entries_tags
that contains two columns: entry_id
and tag_id
, with a multi-key on both entries.
This is called a many-to-many relationship.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With