I’m having some trouble with using subtypes/supertypes in MySQL.
I use C# .NET to make an administration system for my local club, and I have some trouble making a nice database.
My database looks like this:
supertype:
========
Product
---------
Prod_id (PK)
Name
Barcode
and the subtype:
=======
Card
--------
Prod_id (FK)
Price
I have 3 subtypes, Cards, Weapons, Ammunition which are basically the same thing (though I store different things in them).
Maybe I’m overcomplicating things, but all I want to do is, when I create a new card, that a product is automatically generated (I use a trigger for that), and that the Cards.Prod_id gets set to the newly generated Product.Prod_Id.
How do I do this?
Is this the right way of using subtypes, or am I doing something completely wrong?
You may use trigger. But, there is another, I think better way:
MySQL example:
First INSERT wall add new product with autogenerated ID. The second, will get this new ID and use it for new Card record.
Using AUTO_INCREMENT