Polymorphism in SQL database tables?

Posted by Patrick Daryll Glandien on Stack Overflow See other posts from Stack Overflow or by Patrick Daryll Glandien
Published on 2009-02-18T15:39:58Z Indexed on 2010/05/13 0:54 UTC
Read the original article Hit count: 393

Filed under:
|
|

I currently have multiple tables in my database which consist of the same 'basic fields' like:

name character varying(100),
description text,
url character varying(255)

But I have multiple specializations of that basic table, which is for example that tv_series has the fields season, episode, airing, while the movies table has release_date, budget etc.

Now at first this is not a problem, but I want to create a second table, called linkgroups with a Foreign Key to these specialized tables. That means I would somehow have to normalize it within itself.

One way of solving this I have heard of is to normalize it with a key-value-pair-table, but I do not like that idea since it is kind of a 'database-within-a-database' scheme, I do not have a way to require certain keys/fields nor require a special type, and it would be a huge pain to fetch and order the data later.

So I am looking for a way now to 'share' a Primary Key between multiple tables or even better: a way to normalize it by having a general table and multiple specialized tables.

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql