Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 4th, 2012, 09:28 PM
DrWorm's Avatar
DrWorm DrWorm is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2002
Location: Queensland, Australia
Posts: 827 DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level)DrWorm User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 18 h 34 sec
Reputation Power: 140
Table structure for extended objects

I'm curious if there is a pattern for storing programming objects in a database where one class may extend another.

So, for example, you might have an abstract class for a media that has nothing more than an ID property. Two other classes extend to for Flash media and Text media. These each have different properties, but they still have an ID which must be unique regardless of the type.

So when it comes to storing these media in the database, it would be kinda ugly to have one single table that describes all possible media types--especially as more and more types are created. It seems better to have a media table that stores an ID and a `type` and then have a separate table for each type.

But having a separate table for each type won't prevent a Flash media rowing being created with the same ID as a Text media.

So is there a better DB design that compliments this? Or is what i've described as good as it gets and then code must be used to ensure the same ID is not reused for different media.

I know I could also add a `type` column to each of the media type tables which can only contain one value, then make that a foreign key... but having a column that can only contain one value seems redundant.
__________________
Ooh, they have the Internet on computers now!

Reply With Quote
  #2  
Old June 5th, 2012, 12:49 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,376 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 35 m 25 sec
Reputation Power: 4140
Quote:
Originally Posted by DrWorm
but having a column that can only contain one value seems redundant.
redundant? not really

see http://consultingblogs.emc.com/davi...t-Subtypes.aspx
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Table structure for extended objects

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap