mysql - Shared Primary Key -


i guess semi-common question can't find in list of past questions. have set of tables products need share primary key index. assume following:

product1_table:     id,     name,     category,     ...other fields  product2_table:     id,     name,     category,     ...other fields  product_to_category_table:     product_id,     category_id 

clearly useful have shared index between 2 product tables. note, idea of keeping them separate because have largely different sets of fields beyond basics, share common categorization.

update:

a lot of people have suggested table inheritance (or gen-spec). option i'm aware of given in other database systems share sequence between tables hoping mysql had similar solution. shall assume doesn't based on responses. guess i'll have go table inheritance... thank all.

it's not common, no. there no native way share primary key. might in situation this:

product_table     id     name     category     general_fields...  product_type1_table:     id     product_id     product_type1_fields...  product_type2_table:     id     product_id     product_type2_fields...  product_to_category_table:     product_id     category_id 

that is, there 1 master product table has entries products , has fields generalize between types, , type-specified tables foreign keys master product table, have type-specific data.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -