Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 925401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:30:52+00:00 2026-05-15T19:30:52+00:00

If I have a class called animal, dog and fish is the subclass. The

  • 0

If I have a class called animal, dog and fish is the subclass.
The animal have attribute called “color”.
Dog have the attribute called “tail length”, and the fish don’t have this attribute.
Fish have the attribute called “weight”, the dog don’t have this attribute.

So, I want to design a database to store this information. What should I do? Here is some ideas:

Idea 1:
Making an animal table, and the table have type, to find what kind of animal, if it is a dog, just get the result from dog table.

Animal:
color:String
type:int

Type:
Dog:0
Fish:1

Dog:
TailLength:int

Fish:
Weight:int

Idea 2:
Store only Dog table and Fish table in the database, remove the animal table.

Dog:
Color: String
TailLength: int

Fish:
Color: String
Weight: int

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:30:53+00:00Added an answer on May 15, 2026 at 7:30 pm

    The two approaches you mentioned:

    • One table representing objects in the entire inheritance hierarchy, with all the columns you’d need for the entire hierarchy plus a “type” column to tell you which subclass a particular object is.
    • One table for each concrete class in your inheritance hierarchy, with duplicated schema.

    can be supplemented by two others:

    • One table for each class in your inheritance hierarchy – you now have an Animal table, and subclasses have tables with foreign keys that point to the common set of data in Animal.
    • Generic schema – have a table to store objects, and an attribute table to support any set of attributes attached to that object.

    Each approach has pros and cons. There’s a good rundown of them here:

    • http://www.agiledata.org/essays/mappingObjects.html#ComparingTheStrategies

    Also take a look at these SO topics:

    • Something like inheritance in database design
    • Help me to connect inheritance and relational concepts
    • Object-oriented-like structures in relational databases
    • How to do Inheritance Modeling in Relational Databases?
    • How do you effectively model inheritance in a database?

    Finally, it should be noted that there are object-oriented databases (aka object databases, or OODBMSes) out there that represent objects more naturally in the database, and could easily solve this problem, though I don’t think they’re as frequently used in the industry. Here are some links that describe such DBs as compared to relational (and other) DBs, though they won’t give you an entirely objective (heh) view on the matter:

    • What is the difference between graph-based databases and object-oriented databases?
    • “In defense of the RDBMS”, Gavin King, 2007
    • “The relational database needs no defense” (in support of OODBMSes), Ted Neward, 2007
    • Object Oriented Database – why most of the companies do not use them
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Trial which has_many results. Now What I want to
i have this class called MemoryManager, it is supposed to implement a simple smart
Let's say I have 2 instance of a class called 'Animal'. Animal has 3
I have a class called Animal which is a super-class and pure polymorphic. I
So I have this strucutre - an interface called Animal : public interface Animal
Suppose I have a class called Animal and an interface called AnimalTrainer. public interface
I have the following two classes: public class Animal { public Animal() { this(Animal->Horse);
I have an Animal class and an extension of Animal called AnimalExtension. public class
For example, I have a class called animals. I don't think I need to
If I have a class called Animal, and a derived class Bird : public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.