design with similar tables
I am setting up a database that represents different types of content. I have a link (think of it as a URL) that can point at different types of data over time, say a phone number, an email address, or a web page.
I figured I would make tables like:
- content_phone
- content_email
- content_url
I also then have a link table that needs to point at a particular type of content.
The content that a link can point to changes over time (time X it points at a URL time X + 1 it points at a phone number, etc...)
The content types have no fiel开发者_开发问答ds in common, and I do not expect that they ever will (not sure if that makes a difference).
I am stuck for a nice way to hook the link and the content type together.
EDIT:
There are a large number of unrelated tables for content types. Some tables may have 10 fields.
Create one parent table (e.g. called "Content") that has the key from the other content tables. That way you can always reference that one table elsewhere instead of several different possibilities. This avoids needing nullable columns. Example:
http://consultingblogs.emc.com/davidportas/archive/2007/01/08/Distributed-Keys-and-Disjoint-Subtypes.aspx
Super-type/subtype is usually recommended when there are some common fields between entities, but in your example it may be useful anyway.
Here are few examples of similar questions-answers:
- example 1
- example 2
- example 3
- example 4
It looks like you want to have a revision field in there
create table contact
person_id
phone ..
email ..
url ..
updated_at
)
then you can pull from the table as such
SELECT * FROM person JOIN contact ON ( person.id = contact.person_id ) ORDER BY contact.updated_at DESC LIMIT 1
-daniel
精彩评论