I am using Oracle. I have two tables:
Cat (cat_ID, cat_name, cat_age, cat_strength)
Dog (dog_ID, dog_name, dog_age)
Sometimes I need to get all pets into one query result. I was thinking of creating an animal_seq sequence that can be used by both Cat and Dog tables so that they never have duplicate IDs across tables and then when joined can be easily searched/queried whatever.
Is this bad practice? If so, why? Are there better ways to design the tables (eg just one Animal table, or multiple inheritence). Personally, I try to avoid inheritence due to the performance issues of joins.
Having a single sequence is totally acceptable and safe. Oracle ensures multiple reads to a sequence always returns a unique value so you shouldn’t have any problems with duplicate keys.
If the the schema between CAT and DOG is truly unique and an additional animal entity will also be unique, I would keep separate tables. If you are going to maintain the same information about cats, dogs, monkeys, etc., I would recommend putting them into a single ANIMAL table. You’ll have to give more information about the application/database for us to know what to recommend.