Assume I have a table that can have 0 or more tags:
TABLE: foo
- foo_id (PK)
TABLE: tag
- tag_id (PK)
- name
TABLE: foo_tag
- foo_tag_id (PK)
- foo_id (FK)
- tag_id (FK)
Questions:
- The above is the most common and simplest way to implement a tagging system that I have seen. I do realize that there are potential problems with tagging systems in terms of scalability. Am I going to have that here?
- Is there a way to do something like this in PHP or SQL: insert a new tag "bar". If "bar" does not exist, add it to the
tag
table and return the last inserted id. If "bar" does exist, do not add it and return the tag_id for it. - Is there a "proper" DB term for such a table describe in #2?