I'm trying to decide if I should push a specific column to its own table or if I should use another method or constraint of some sort.
Let's say I have a table like:
tbl_Location
LocationID PK int
Address varchar(100)
City varchar(50)
State varchar(50)
Another another table like:
tbl_Store
StoreID PK int
StoreName varchar(50)
LocationID int FK
Question 1: So a store is required to have a single location, not more than one. Is it overkill to push these into another table, and create a constraint that disables the same storeID to be in more than one row, such as:
tbl_StoreLocation
StoreID int
LocationID int
Question 2: Is there a benefit to still using a PK identity/auto increment column if I were to put this in its own table?
In a rare event, a location might be removed from the tbl_Location table. If it is removed, in method one ( all in one table ) I'll have to set the LocationID to NULL. Method two, I'll have to use cascade.
To further complicate things, stores can have products, and that LocationID is simply their default location. When creating a product it defaults to their LocationID from the tbl_Store, or if I break it into another table, the tbl_StoreLocation table. So that pushes this further, such as:
tbl_Product
ProductID PK int
StoreID FK int
ProductName varchar(50)
LocationID fk int <-----
Or should I again have (And each product can only have a single location):
tbl_ProductLocation
ProductID int
LocationID int
I read about the deeper phases of normalization but what I need help understanding is the time/benefit/structure analysis for something this simple.
What do you think?
For Question 1:
If a store is required to have a single location, not less than one and not more than one, so it is overkill to push relation between store and location into another table. But if a store can have not any location, as its location might be removed, you should use tbl_StoreLocation
table. In such case you should remove LocationID
column from tbl_Store
table.
For Question 2: Yes, there is a benefit to still using a PK identity/auto increment column if you were to put this in its own table. Why not? You still use it for relations.
A few words about products. You said - 'stores can have products' - so product relate to store but to location, so product location is its store location. Only if you change this business rule you need to redesign your database in correspondence.