开发者

Structuring a list of tags for each event

开发者 https://www.devze.com 2023-03-27 18:29 出处:网络
I\'m creating a开发者_开发问答 website(PHP + MySQL based) with a list events. I currently have the events stored in a database called \'events\'.

I'm creating a开发者_开发问答 website(PHP + MySQL based) with a list events.

I currently have the events stored in a database called 'events'.

I want each event to have a list of tags. I'm not sure if I should...

  1. Store all the tags as one value in a MySQL sorted like...(tag1,tag2,tag3)

OR

  1. Create a seperate database called event_tags and have a row for each tag. The tag would then include the event_id of the event it was refering to.

Or

  1. Something better I havn't thought of?


Why not just creating separate table for these tags, so when you change tag name, you wouldn't need to change all values in all rows.

and use another table to link the event table with tag table. So basically you have these tables: events, tags, event_tags (here you need to make event and tag columns as a unique key)

It would look like this :

Event table:

|ID|Event |
|1 |first |
|2 |second|

Tag table:

|ID|Tag|
|1 |c# |
|2 |c++|

Event_tag table:

|Event|Tag|
|1    |1  |
|1    |2  |
|2    |2  |


I think it's up to you. If you think your tags will be repeated, you'd better create a tags table and then using an external table to join them. Else you can simply create tags referencing the event's id.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号