Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2010
    Posts
    5

    Unanswered: Achieving Inheritance/super-sub classes in MySQL

    Hi Everyone,

    I was wondering if anyone would be able to tell me the syntax to achieve inheritance in MySQL, For example:

    Table: Animal
    ^
    |
    |

    Table: Cat | Table: Dog
    Would this simply be a case of declaring the PK in Animal, e.g AnimalID, and repeating this in cat and dog?

    Finally, once I have achieved this, will the tables inherit the values inputted into the main animals table automatically, or will these be repeated?

    Many thanks for your time in advance - J

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by jacob_144 View Post
    Would this simply be a case of declaring the PK in Animal, e.g AnimalID, and repeating this in cat and dog?
    that's the simplest way, yes

    however, there is no "inheritance" of data values as you were hoping

    for additional information, search supertype/subtype
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2010
    Posts
    5
    That's fine, I expected that would be the case. Thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •