So there is one primary key so far used for IDs of locations.
Currently there are multiple tables (sheets) in Excel for the following
- Events (Location ID, Date, Title, Description)
- Animals (Location ID, Species, Name, Population)
- Restrictions (Location ID, Permits, Zone)
Is the above bad practice? From what I have read online you should not use the same primary key across multiple tables.
How should the tables be structured to follow "best practices", have it be one big database table or is it fine to leave in multiple tables?
Best Answer
As per mustaccio's comment, when you have the same
PrimaryKey
defined in each of yourTables
, that then guarantees a one-to-one relationship is enforced between eachTable
. In other words, based on the schema of yourTables
provided in your question, you won't ever be able to have more than one Animal at one Event, or more than one Restriction for a specific Animal, etc. They all share the sameunique
Location ID.If that meets your needs then your design is ok. But if you want to be able to have multiple Animals at multiple Events with varying Restrictions for different locations etc, then you might be better off with the following design:
Add a fourth
Table
called Locations with the Location IDPrimaryKey
.Remove the Location ID
PrimaryKey
(andunique constraint
) from all the othertables
and instead create aForeignKey
relationship between it and your Locationstable
on Location ID.Add a new
unique PrimaryKey
field to the Events, Animals, Restrictionstables
with the appropriate names (e.g. Event ID for the Eventstable
, Animal ID for the Animalstable
, etc).And to directly answer your main question, it's better to keep these as separate
Tables
. That is called database normalization and is important for query efficiency and elimination of unnecessary data redundancy. In general, separation of concerns should be split into separateTables
.