Showing posts with label address. Show all posts
Showing posts with label address. Show all posts

Wednesday, March 28, 2012

Normalizing Address Information...

THE LAYOUT:
I have two tables: "Applicant_T" and "StreetSuffix_T"

The "Applicant_T" table contains fields for the applicant's current address, previous address and employer address. Each address is broken up into parts (i.e., street number, street name, street suffix, etc.). For this discussion, I will focus on the street suffix. For each of the addresses, I have a street suffix field as follows:

[Applicant_T]
CurrSuffix
PrevSuffix
EmpSuffix

The "StreetSuffix_T" table contains the postal service approved street suffix names. There are two fields as follows:

[StreetSuffix_T]
SuffixID <--this is the primary key
Name

For each of the addresses in the Applicant_T table, I input the SuffixID of the StreetSuffix_T table.

THE PROBLEM:
I have never created a view that would require the primary key of one table to be associated with multiple fields of another table (i.e., SuffixID-->CurrSuffix, SuffixID-->PrevSuffix, SuffixID-->EmpSuffix). I want to create a view of the Applicant_T table that will show the suffix name from the StreetSuffix_T table for each of the suffix fields in the Applicant_T table. How is this done?I got the solution from another forum. It is as follows:


create view ApplicantAddresses
( currstreetnumber
, currstreetname
, ...
, currsuffixname
, prevsuffixname
, empsuffixname
)
as
select currstreetnumber
, currstreetname
, ...
, c.name
, p.name
, e.name
from Applicant_T
inner
join StreetSuffix_T c
on currsuffix = c.SuffixID
inner
join StreetSuffix_T p
on prevsuffix = p.SuffixID
inner
join StreetSuffix_T e
on empsuffix = e.SuffixID
|||Having the primary key of one table be associated with mulitple fields in another table is not unusual. However, it does bring a "Spock's raised eyebrow" indicating a table design that could be improved upon. To use the same lookup table more than once you just need to create table aliases so that the query can distinguish between the tables. You also need aliases in the Select clause so you can tell them apart.

SELECT dbo.StreetSuffix_T.Suffix AS CurrSuffix, StreetSuffix_T_1.Suffix AS PrevSuffix, StreetSuffix_T_2.Suffix AS EmpSuffix
FROM dbo.Applicant_T INNER JOIN
dbo.StreetSuffix_T ON dbo.Applicant_T.CurrSuffix = dbo.StreetSuffix_T.SuffixID INNER JOIN
dbo.StreetSuffix_T StreetSuffix_T_1 ON dbo.Applicant_T.PrevSuffix = StreetSuffix_T_1.SuffixID INNER JOIN
dbo.StreetSuffix_T StreetSuffix_T_2 ON dbo.Applicant_T.EmpSuffix = StreetSuffix_T_2.SuffixID

However, the design of Applicant_T seems a bit suspect since you have multiple addresses. Maybe today you want current, former, and employer addresses but in the future you might need another one (spouses employer address, delivery address, second employer address, whatever). With your current design you'd need to add a bunch of new columns whenever you add a new address type.

It may be better to have a separate table that just handles addresses. It might have two keys, one to link back to the applicant_T table and another for the type of address held in that record. (0=current address, 1=previous address, 100=employer address, 1000=dog groomers address).|||McMurdoStation,

You are right. In my pursuit of a solution to a short-term issue, I neglected to consider the longer-term impact of my decision. I am going to change the table design.

Thanks for your input :)|||Yeah, you save less than a byte to normalize that, and lose tons of rotations in the joins.

Sacrifice space for efficiency in runtimes every once in awhile.|||The idea of normalization isn't to save space. If normalizing causes performance bottlenecks you can do things to address that. But that problem is easier to address when and if necessary than having a data model that can't handle change.|||In my particular case, scalability is of high importance. Normalizing the addresses in the manner McMurdoStation suggested, provides such scalability.

Normalize this data

How would you normalize this data into a useable database?
Customer Name City Contact Address
Contact First Name Contact Phone Number Contact Fax Number
Billing Address Country Contact Email
Customer Number Contact Title User Name
Contact Last Name Shipping Address Password
Postal Code Contact Cell Phone User Role PrivilegePut it in a table?
<billsahiker@.yahoo.com> wrote in message
news:1192905303.503854.262450@.i13g2000prf.googlegroups.com...
> How would you normalize this data into a useable database?
> Customer Name City Contact Address
> Contact First Name Contact Phone Number Contact Fax Number
> Billing Address Country Contact Email
> Customer Number Contact Title User Name
> Contact Last Name Shipping Address Password
> Postal Code Contact Cell Phone User Role Privilege
>|||On Oct 20, 1:18 pm, "Jay" <s...@.nospam.org> wrote:
> Put it in a table?
> <billsahi...@.yahoo.com> wrote in message
> news:1192905303.503854.262450@.i13g2000prf.googlegroups.com...
>
> > How would you normalize this data into a useable database?
> > Customer Name City Contact Address
> > Contact First Name Contact Phone Number Contact Fax Number
> > Billing Address Country Contact Email
> > Customer Number Contact Title User Name
> > Contact Last Name Shipping Address Password
> > Postal Code Contact Cell Phone User Role Privilege- Hide quoted text -
> - Show quoted text -
Two or more tables, and indicate primary and foreign keys. This was a
test item and that is all the information given.|||<billsahiker@.yahoo.com> wrote in message
news:1192908678.033282.164490@.k35g2000prh.googlegroups.com...
> On Oct 20, 1:18 pm, "Jay" <s...@.nospam.org> wrote:
>> Put it in a table?
>> <billsahi...@.yahoo.com> wrote in message
>> news:1192905303.503854.262450@.i13g2000prf.googlegroups.com...
>>
>> > How would you normalize this data into a useable database?
>> > Customer Name City Contact Address
>> > Contact First Name Contact Phone Number Contact Fax Number
>> > Billing Address Country Contact Email
>> > Customer Number Contact Title User Name
>> > Contact Last Name Shipping Address Password
>> > Postal Code Contact Cell Phone User Role Privilege- Hide quoted text -
>> - Show quoted text -
> Two or more tables, and indicate primary and foreign keys. This was a
> test item and that is all the information given.
>
How about doing your own homework...
--
David Portas|||Why do you assume it is school work? It was a job application test I
took yesterday.
> How about doing your own homework...
> --
> David Portas- Hide quoted text -
> - Show quoted text -|||Ah, because you told the truth, I will help. And there is little difference
between an employment test and homework. You should have said so in the
first place.
Basically, it looks like they got together and looked for ways to screw
applicants up. They probably thought they were being cute mixing up and
eleminating necessary attributes too.
The first thing that jumps out is that you're storing people and addresses,
so that's two tables:
People is 1-to-many to Addresses (more on addresses later).
Second (and it's glaring): "Customer Name" vs. "Contact First Name" &
"Contact Last Name"
These columns should be: "Prefix", "First Name", "Middle Name",
"Last Name" & "Suffix".
(Mr. John Adam Smith, Sr)
Third Customers have "User Role Privilege", "User Name" and Password,
Contacts do not. Therefore, some people have attributes that others do not.
This suggests storing Customers and Contacts seperatly.
--
If you take the list of attributes they provided and arrange it, more things
become apparent:
Customer Number
User Name
Password
User Role Privilege
Customer Name
Billing Address
City
Postal Code
Country
Shipping Address
Contact Title
Contact First Name
Contact Last Name
Contact Address
Contact Phone Number
Contact Cell Phone
Contact Fax Number
Contact Email
Comments:
"Billing Address" and "Shipping Address" are clearly attributes of the
Customer. However, "City", "Postal Code" (Zip Code) & "Country" are vague.
Are they for Billing, Shipping, or Contact. In fact, you really need those
for each address. Same for attributes that appear in Contact, you should
have those for Customers too. In general, they really messed with the
attribute list.
Also, what "State" is the address in?
People (not including addresses):
There are two approaches here: store the "Contact" as attributes in
Customer, or create three tables: Customer, Contact & People, where "People"
is the parent table. You'll probably have to define your own PK for people
too and store it as a FK in Customer alone with the Customer Only info.
Addresses:
Create a seperate address table with all approporiate attributes. Then
you need a way to link people to addresses. You can do this by adding a
column to one of the people tables, or creating a many-to-many relationship
between people/customer/contact tables and addresses.
Since you have three distinct address types, you might want an AddressType
column in addresses constrained either by a lookup table, or a check
constraint. There are pluses and minuses for each. I prefer lookup tables,
but I'm a 3NF+ bigot.
Well, that covers the basics. Can you normalize the tables now?
<billsahiker@.yahoo.com> wrote in message
news:1192905303.503854.262450@.i13g2000prf.googlegroups.com...
> How would you normalize this data into a useable database?
> Customer Name City Contact Address
> Contact First Name Contact Phone Number Contact Fax Number
> Billing Address Country Contact Email
> Customer Number Contact Title User Name
> Contact Last Name Shipping Address Password
> Postal Code Contact Cell Phone User Role Privilege
>

Friday, March 23, 2012

Non-US address

Someone told me that some non-US address do not have State/Province, and
some might not have Postal Code. Is this true?J wrote:
> Someone told me that some non-US address do not have State/Province, and
> some might not have Postal Code. Is this true?

Yes. And some might have things that aren't in a US address. For example:

3-1, Kudan-minami 1-chome
Chiyoda-ku,
Tokyo, Japan 102-8660

Chiyoda-ku has no US equivalent and not no equivalent for state.
Tokyo is in Kanto but you won't find that in the normal address
listing.
--
Daniel A. Morgan
http://www.psoug.org
damorgan@.x.washington.edu
(replace x with u to respond)|||Check out

http://www.upu.int/post_code/en/pos...countries.shtml|||J (jungnaja@.hotmail.com) writes:
> Someone told me that some non-US address do not have State/Province, and
> some might not have Postal Code. Is this true?

Yes, here in the outside world things are rough. You know, for our tiny
little country it would be preposterous to have a thing like states. Many
US states have a bigger population than we have. Besides, by tradition
this is a centralised country where the national government strongly
regulates what counties and municiplaties should do. In theory they are
free to set their on tax level, but the government meddles there as well.
On top of that, county and municiplatity borders changes sometimes, so
it would not be good for addresses.

We do have postal codes. And to make you feel a little more like home,
they are even five digit ones. However, there are really rough places
like the UK where the postal codes looks entirely different.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp