I've got a table of
ID tag --- ------ 1 tagt 2 tagb 3 tagz 4 tagn
items table, I am using individuals tags in serialized format, comma delimited
ID field1 tags ---- ------ ----- 1 value1 tagt,tagb 2 value2 tagb 3 value3 tagb,tagn 4 value4
When I have to find products which have this tag, I intend to deserialize the tags. But I am not really sure how to get it done, and when it's better to possess a third table for associations rather between your tags and also the products.
Yes, personally, I'd make use of a third table for that item-tag association. It might be simpler and faster to find labeled messages and you might enforce that no same tag is going to be added two times towards the same message together with your database design.
Generally, one attempts to make use of the energy of relational database to a person's advantage. Quite simply, serializing and p-serializing a string each time any marking feature is utilized is both incredibly inefficient in addition to a poor design for some other reasons.
For instance, let's say an (undefined) tag
tagc is accidentally put into the
tags area of the
item? The code could be tough to debug.
Developing a third table that consists of records of connected IDs is a far greater option. Additionally, you can produce the
taggings table to appear something similar to this:
ID item_id tag_id tagger_id etc -------------------------------------------
and store meta-data together with each marking.
Becoming over-determined by strings for storing structured information is both inefficient and unmaintainable. To prevent "stringly typed" code, modeling the domain further is much better during these situations.
To describe wrong together with your marking approach, I am going to inform you a similarly problematic database:
table Students -------------------- Id grade names -- ----- ----- 1 Kindergarden timmy, james, sarah, suzie, etc... 2 first annie, chris, laura, etc... 3 second robert, kimmy, sarah, jason, etc...
This really is wrong its exactly the same reasons. You cannot so something with what they are called. You cannot count them, filter by them, as well as return one of them.
What if you wish to awesome stuff together with your tags later that you are not considering at this time?