views:

57

answers:

2

I want a tag system like whats on SO but Im not sure how to implement this in the database. This is how i was going to implement it.

Here are my columns in the database

Article Table

  • ID
  • Title
  • TitleSlug
  • Date
  • UserID
  • Description
  • IsDeleted
  • TagID1
  • TagID2
  • TagID3
  • TagID4
  • TagID5
  • TagName1
  • TagName2
  • TagName3
  • TagName4
  • TagName5

Tag table

  • TagID
  • TagName

Is this a good way to implement tags in the database?

+2  A: 

Dupe: http://stackoverflow.com/questions/1480949/

Eimantas
+2  A: 

What you want is a many-to-many relationship table structure so something like:

Article Table

  • ID
  • Title
  • TitleSlug
  • Date
  • UserID
  • Description
  • IsDeleted

Tag table

  • TagID
  • TagName

Relationship Table

  • articleId
  • tagId

This way you can have unlimited relationships, where your example is limited to 5

Joshua Cauble