I am trying to design a database that stores the following:
- Franchise Name (string)
- Employee Count (integer)
- Locations (zip-code)
The problem I am having is the potential size of the database (all potential franchises, as well as locations) and how to design the database so that the zip-codes for a specific franchise can be stored in the same cell. Is this possible to have a cell that has something like “95432, 12345, 92534, 68723” and can be queried and modified to add or delete zip-codes with a query? I want to be able to regularly do something like:
SELECT franchiseName
FROM database
WHERE zipCode = "12345"
and then obviously, display all franchises that have a location in that zip-code. I wouldn’t want to create a separate tuple for each zip-code right? Wouldn’t something like:
Pizza Hut, 23, 95432
Pizza Hut, 12, 12345
Pizza Hut, 07, 92534
Pizza Hut, 15, 68723
be considered bad design because of the potential number of duplicate Franchise names? (imagine McDonald’s alone)
Any help is appreciated
Basically you’re defining a many-to-many relationship. The common practice in this situation is to work with a table containing all the Locations and a mapping table. This mapping table contains the id of the franchise and one of the location. Using joins, you could get all the information you need and there would be no data duplication.