RoB wrote:
I think you are right about the province.
no no :) In fact, I have table provinces in my ERD diagram, but in my
example I skip that table, because I think, it's not very important in my
question.
I wrote about 3 tables: providers (not provinces), customers and addresses
So why isn't there a relation between address and province?
I couldn't wrote all ERD diagram, because it's very big diagram (about 40-50
tables)
ok, I try explain (this time, I use 3 other example tables with province :)
:
coutries( country_id, country_code, country_name)
provinces( province_id, province_name, country_id) -- in this table PK
is (province_id, country_id)
addresses( addr_id, province_id, country_id) -- in this table
PK is (addr_id, province_id, country_id)
relation is simple: 1 country has N provinces, 1 province has N addresses
in this example, addresses PK is "good" PK, because all keys are related
with address, but it's not the smallest key, which can be used.
The smallest primary key is addr_id (because it's auto_increment key)
THAT'S YUR PRBLEM! You confuse a pseudokey (addr_id) with a real
Primary key. Until you understand the difference you will always have
this problem.
I would use something like this:
coutries( country_code, country_name)
-- in this table PK is country code (where country code is a
uniqure abbreviation, like USA, GER, PRC)
provinces( province_code, province_name, country_id)
-- in this table PK is (province_code, country_id) where province
code is a unique abbreviation (NT, CAN = Canada, for example)
clientaddresses( line1,line2,province_id, country_id)
-- in this table PK is (line1,line2, province_id,
country_id) where these represent the address as entered by the client
(so they might not necessarily be valid postal addresses)
In my previus example I tried show 3 tables, where provider_id isn't any
sense in table addresses (in my opinion)
Is there ever a need to know an address which doesn't have a customer?
No, address is always in relation with 1 customer
Can an address exist outside a province? (Do you have any customers
from outside your country?)
I have customers outisde me country. Addresses can't exist outside a
province, because I have countries and provinces table
So think about it at that higher level first and fix it there. Then
when you go back to building the tables, at least consider getting rid
of some of those ID keys. (Isn't there an abbreviation for the province
that could be used? I really cannot see any reason to use a ID for the
province, for example.)
exactly, I can't see any reason too :) but it's not my ERD diagram and I
decide ask in this group, what this group think about this solution
Then ask the data modeler why he's introducing pseudo keys into the
model. is he just an ACCESS programmer, or a real datamodeler? It's
isn't easy but sometimes you have to push back a bad data model. The
province ID adds no data integrity to your system. It doesn't save much
data space either. so why use it?
In comparison, and address ID might be justified on the grounds that
you have millions of clients and storing the full PK of the address
consumes too much space. Here the trade off is between a 32bit integer
ID and the size of the PK fields of address (say each line=60
characters, province code=4chars, and country code=4chars, for 128bytes
at least) so there is a savings of over 120bytes per customer row.
downside is the extra join when you need the actual address
information.
thanks for discusion, I haven't any other question.
best regard
RoB
Sounds like you have a long road ahead of you. Hope my comments help.
Ed
(I'm actually surprised no one else has commented on this thread. Maybe
they all went on Christmas vacation early?)