I'm designing a relational database, and I would like to know best practice for the following problem:
I have a table called "links", which contains URLs.
Most of my other tables relate to objects which appear throughout my site, such as "news", "music", "banners" - and these are joined with one-to-many or many-to-many relationships in the usual way. So far so good...
The links table (link_id) can apply to almost ANY of my objects. For example, "news" could have many "link_id, one "link_id" could apply to many "music". Many "banners" could share many "link_id" - links are important to my site!
I can think of two solutions for this :
1) create a junction table for each new object to which "link_id" applies, thus creating dozens of new tables, and adding new ones each time I add an new object to my application.
>##*Table: links_to_news*##
>##*Table: links_to_music*##
>##*Table: links_to_banners*##
> etc... etc... etc...
2) reference the table name in a single new table, and create a join, ie:
>##Table: links##
>| link_id | link_url |
>##*Table: links_to_tables* ##
>*| link_id | a_table_name | id_within_that_table |*
> ##Table: news##
>| news_id | news_text |
> ##Table : music ##
>| music_id | music_text |
Both of these methods seem a little bit clunky to me. So is there a correct way to do what I need? Thanks.