Simple DB Organization Question

J

J

I am putting together a DB for the first time and need some guidance
as to what would be the best way to setup my tables. My database will
include employees (some who work at home), stores (where employees
work, and where things are mailed), regional offices (where employees
work, and where things are mailed). So thinking about it I was going
to setup a table for people, stores, offices, and addresses and link
addresses to people, stores, and offices. Basically I need the
ability
to send things to a person at multiple addresses, some of which are
shared by multiple people.

Does this make sense?
 
J

John W. Vinson

I am putting together a DB for the first time and need some guidance
as to what would be the best way to setup my tables. My database will
include employees (some who work at home), stores (where employees
work, and where things are mailed), regional offices (where employees
work, and where things are mailed). So thinking about it I was going
to setup a table for people, stores, offices, and addresses and link
addresses to people, stores, and offices. Basically I need the
ability
to send things to a person at multiple addresses, some of which are
shared by multiple people.

Does this make sense?

I'd suggest treating stores and offices and home offices as being three
special cases of the same kind of entity, and put them in one table. I would
presume that each store/office/home office would have only one address, though
you can certainly design the tables to handle more.

You would then handle the many to many relationship with a third table, with
fields for the PersonID (who can be reached at this address) and LocationID
(where can they be reached).
 
K

Ken Sheridan

Taking things a little further it might be appropriate to break down the
table of address locations which John suggests. It really depends on how
much information in addition to the addresses themselves you want to store
about each location. You can regard Homes, Stores and Regional offices as
sub-types of a type Locations. Sub-types are characterized by sharing the
same attributes of their (super) type but not of its other sub-types. Each
location will have attributes in common, Street, City etc, but a store might
have different attributes to a regional office or home, e.g. StoreManagerID
referencing the Employees table's EmployeeID primary key column.

A type/sub-type is modelled by a on-to-one relationship type, so the type
Locations would have a LocationID as its primary key (this can be an
autonumber), while the sub-types homes, stores and regional offices would
also have LocationID as their primary keys. In each of these its also a
foreign key referencing the key of Locations, however, so can't be an
autonumber.

By breaking down the locations into a Locations table and separate Homes,
Stores and RegionalOffices tables in this way you don't have any columns in a
row for a home address which are inappropriate to it, and thus Null, as would
be the case with just a Locations table with a LocationType column. Of
course, if you only want to store address attributes common to all the
sub-types and no attributes which are specific to the home, stores or
regional offices entity types then a single Locations table with a
LocationType column is fine. Whichever way its done, however, the Employees
table would be related to the Locations table via a third table in the way
John describes.

Ken Sheridan
Stafford, England
 
J

J

Thanks for your suggestions gentleman! If wanted to complicate things
a little, and lets say wanted to treat the stores almost like
employees, because maybe they have a seperate shipping address and
seperate physical address, whats the best way to accomplish this?

What I have so far is as follows:

tbPeople - names, titles etc
tbStore - opening times, Previous years sales, Managers (linked to
tbPeople w/ EmployeeID)
tbAddress - street, city, state, zip, country (linked to tbCountry
with CountryID)
tbAddressType - Home, Office, StorePhysical, StoreMailing
tbAddressAssign - Has EmployeeID and AddressID so far, but need to
bring in StoreID some how
tbCountry - country names (to keep from misspelling country names)


Suggestions?

Thanks again for all the help so far!

J
 
K

Ken Sheridan

In the context of your original question I think you've pretty well answered
your own supplemaentary question. By introducing a StoreID foreign key
column in tbAddressAssign this table models a 3-way many-to-many relationship
type between stores, addresses and employees. I'd add a Position column to
the table as well. You can then record as few or as many employees per store
and their position, e.g. Manager. You can then remove the manager column
from tbStore. Also add an AddressType column to the table ( so it now models
a 4-way relationship type as the tbAddressType table is also referenced. You
can then assign different addresses to each employee and several addresses of
different type for one employee if necessary.

For an employee not based in a store you could leave the StoreID column
Null. Similarly to assign addresses of a particular type to a store rather
than via an employee at the store the EmployeeID column could be left Null.
You can then find a store's physical address for instance rather than one of
its employees' addresses by a query 'WHERE tbAddressAssign.EmployeeID IS
NULL'. This does create a problem in defining the primary key of the
tbAddressAssign table, though, as the key would normally be a composite one
of StoreID, EmployeeID, AddressID and AddressType. No part of a primary key
can be Null, however. The solution would be to have a N/A store and an N/A
employee in the stores and employees tables, each with their own StoreID and
EmployeeID values. Instead of leaving EmployeeID or StoreD Null, therefore,
you'd select the N/A employee or store as appropriate.

BTW your tbAddress table is not fully normalized. You only need to know the
city to know the state and country as city implies state which in turn
implies country, so you don't need state and country columns. Having all the
columns introduces redundancy, e.g. you might be told San Francisco is in
California several times if there is more than one store in San Francisco.
Similarly you'd be told that California is in the USA several times. This
opens up the possibility of inconsistent data being entered as its perfectly
possible to have San Francisco in Alabama or Texas in one or more rows. I'm
aware that the sample Northwind database stores data in this way, but the
fact is that it is not properly normalized, deliberately so for the sake of
simplicity I think, but nevertheless incorrectly. As it happens I posted a
demo file of how to handle this sort of data via correlated combo boxes


http://community.netscape.com/n/pfx...yMessages&tsn=1&tid=23626&webtag=ws-msdevapps


It uses the local administrative areas of parish, district and county in my
neck of the woods, but the principle is the same. One thing to note about
cities is that the names can be duplicated, so a unique numerical CityID
should be used. You can then distinguish Paris France from Paris Texas!

Normalizing the design like this does take us back to an earlier point,
though, as some countries don't have regional equivalents of a state, or as
in the UK some cities will be in a County (the nearest regional designation
here) and some won't; Stafford, where I live, is in the county of
Staffordshire for instance, but Liverpool where I was born is not in any
county, being a 'unitary' authority. I don't imagine Luxembourg has any
regions at all! The solution is, as with employees and stores, to again have
a N/A region for those countries which don't have regions or where a city
might not be in a region, each with its unique numeric primary key and a
foreign key referencing the countries table.

Finally I'd question the inclusion of previous years' sales in tbStore.
Sales data is best kept in a separate table which references tbStore via a
StoreID foreign key. By including dates in this table its easy to get sales
data for any year or possibly a shorter period of time, depending to what
level of detail the sales data is stored.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top