473,396 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Wide Primary Keys

I'm working on a system that is very address-centric and detection of
duplicate addresses is very important. As a result we have broken
addresses down into many parts (DDL below, but I've left out some
reference tables for conciseness), these being state, locality, street,
street number, and address. The breakdown is roughly consistent with
Australian addressing standards, we're working on finalising this.

Because we carry the primary key down each of the levels, this has
resulted in our address table having a very wide primary key (around
170 characters). We refer to addresses from a number of other tables
and although my instinct is to use this natural key in the other tables
I wonder if we should just put a unique index on the natural key,
create a surrogate primary key and use it in the other table. Any
thoughts?
CREATE TABLE dbo.States (
StateID varchar (3) NOT NULL ,
StateName varchar (50) NOT NULL ,

CONSTRAINT PK_AddressStates PRIMARY KEY NONCLUSTERED
(
StateID
)
)

CREATE TABLE dbo.Localities (
Locality varchar (46) NOT NULL ,
StateID varchar (3) NOT NULL ,
Postcode char (4) NOT NULL ,

CONSTRAINT PK_Localities PRIMARY KEY NONCLUSTERED
(
Locality,
StateID,
Postcode
),

CONSTRAINT FK_AddressLocalities_AddressStates FOREIGN KEY
(
StateID
) REFERENCES dbo.States (
StateID
)
)

CREATE TABLE dbo.Streets (
StreetName varchar (35) NOT NULL ,
StreetTypeID varchar (10) NOT NULL ,
StreetDirectionID varchar (2) NOT NULL ,
Locality varchar (46) NOT NULL ,
StateID varchar (3) NOT NULL ,
Postcode char (4) NOT NULL ,

CONSTRAINT PK_Streets PRIMARY KEY CLUSTERED
(
StreetName,
StreetTypeID,
StreetDirectionID,
Locality,
StateID,
Postcode
),

CONSTRAINT FK_Streets_Localities FOREIGN KEY
(
Postcode,
Locality,
StateID
) REFERENCES dbo.Localities (
Postcode,
Locality,
StateID
)
)

CREATE TABLE dbo.StreetNumbers (
StreetName varchar (35) NOT NULL ,
StreetTypeID varchar (10) NOT NULL ,
StreetDirectionID varchar (2) NOT NULL ,
Locality varchar (46) NOT NULL ,
StateID varchar (3) NOT NULL ,
Postcode char (4) NOT NULL ,
StreetNumber varchar (15) NOT NULL ,
BuildingName varchar (100) NOT NULL ,

CONSTRAINT PK_StreetNumbers PRIMARY KEY CLUSTERED
(
StreetName,
StreetTypeID,
StreetDirectionID,
Locality,
StateID,
Postcode,
StreetNumber
),

CONSTRAINT FK_StreetNumbers_Streets FOREIGN KEY
(
StreetName,
StreetTypeID,
StreetDirectionID,
Locality,
StateID,
Postcode
) REFERENCES dbo.Streets (
StreetName,
StreetTypeID,
StreetDirectionID,
Locality,
StateID,
Postcode
)
)

CREATE TABLE dbo.Addresses (
StreetName varchar (35) NOT NULL ,
StreetTypeID varchar (10) NOT NULL ,
StreetDirectionID varchar (2) NOT NULL ,
Locality varchar (46) NOT NULL ,
StateID varchar (3) NOT NULL ,
Postcode char (4) NOT NULL ,
StreetNumber varchar (15) NOT NULL ,
AddressTypeID varchar (6) NOT NULL ,
AddressName varchar (20) NOT NULL ,

CONSTRAINT PK_StreetNumberPrefixes PRIMARY KEY CLUSTERED
(
StreetName,
StreetTypeID,
StreetDirectionID,
Locality,
StateID,
Postcode,
StreetNumber,
AddressTypeID,
AddressName
),

CONSTRAINT FK_Addresses_StreetNumbers FOREIGN KEY
(
StreetName,
StreetTypeID,
StreetDirectionID,
Locality,
StateID,
Postcode,
StreetNumber
) REFERENCES dbo.StreetNumbers (
StreetName,
StreetTypeID,
StreetDirectionID,
Locality,
StateID,
Postcode,
StreetNumber
)
)

Jul 23 '05 #1
3 2323
William,

the most difficult issue is that each country has it's own scheme, and
most ppl here prob do not know the australian one(maybe you should
explain it so we can validate your model).

e.g. what is a locality? a city town or village? Does a whole city has
exactly 1 postal code (this is implied in your model).

Can you deduce a street from a postal code or vice versa or both? Again
your model suggests this. Realise this contradicts locality constraint!

You have a table for addresses and streetnumbers, but this is
superfluous, if you have all streetnumbers why would you need extra
addresses? your current schema shows that you can have 2 different
addresses referencing the same streetnumber (which is in fact the
*real* address in my opinion), is this by design?

Pls elaborate fon your model first

DM Unseen

Jul 23 '05 #2
I replied the other day but it seems to have vanished. I apologise if
anyone is getting this for the second time. Addressing your points
individually:
e.g. what is a locality? a city town or village? Does a whole city has
exactly 1 postal code (this is implied in your model).
A locality is really a delivery area. In cities it is a suburb and in
towns the whole town is likely to be a locality. For example,
Indooroopilly (a suburb of Brisbane, Queensland) has the post code
4068. Boonah (a town in Queensland) has the post code 4310.
Can you deduce a street from a postal code or vice versa or both? Again
your model suggests this. Realise this contradicts locality constraint!
The order if this key was incorrect, it should be:

Locality,
StateID
Postcode
You have a table for addresses and streetnumbers, but this is
superfluous, if you have all streetnumbers why would you need extra
addresses? your current schema shows that you can have 2 different
addresses referencing the same streetnumber (which is in fact the
*real* address in my opinion), is this by design?


A street number is for example:

123 Fake Street, Springfield...
45 Fake Street, Springfield...

Whereas an address is:

Unit 5, 123 Fake Street, Springfield...
Shop 12A, 123 Fake Street, Springfield...
Level 14, 45 Fake Street Springfield...

So this is correct, there are multiple addresses within a street
number. The overall hierarchy is:

State (Queensland)
+Locality (Indooroopilly, Queensland 4068)
++Steet (Station Road, Indooroopilly, Queensland 4068)
+++Street Number (1 Station Road, Indooroopilly, Queensland 4068)
++++Address (Unit 1, 1 Station Road, Indooroopilly, Queensland 4068)

Jul 23 '05 #3
OK this makes it clear,

It seems your model is not correct, you need to realise what *defines*
a postal code (it seems a locality defines a postal code, btw in
Holland a street,city and house number define a postal code, and a
postal code and an number define an adress)

It should be

State (Queensland)

+Locality (Indooroopilly, Queensland 4068) PK Postal Code, PK
(Locality,StateID)
++Steet (Station Road, 4068) PK (Street, Postal Code)
+++Street Number(1,Station Road, 4068) PK(Street, Postal Code, Number)
++++Address (Unit 1, 1 Station Road, 4068) PK(all fields)

the question is do you want to be exaustive, if not you can skip street
and streetnumber tables as well

DM Unseen

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Philip Yale | last post by:
I'm probably going to get shot down with thousands of reasons for this, but I've never really heard or read a convincing explanation, so here goes ... Clustered indexes are more efficient at...
7
by: Ilan Sebba | last post by:
I am trying to add a record using SQL. My problem is that the primary keys are foreign keys, and these foreign keys are autonumbers. I therefore do not know the primary keys of the record I am...
5
by: Geoff Cayzer | last post by:
At http://www.blueclaw-db.com/tips_tricks.htm I came across a section which is included below and was hoping for some comment on the article. -------------- Almost never use this auto-number...
7
by: Philip | last post by:
Hey all, (Access 2000) I've been having a horror story with this design problem. My Database is Structured like This: AUTHORS, BOOKS, PAGES. Those are the Tables and each Item in each table...
18
by: Thomas A. Anderson | last post by:
I am a bit confused in creating a composite primary key. I have three table with two of the tables containing primary keys. I have two of the tables (each with a primary key) having one to many...
1
by: GGerard | last post by:
Hello I'm trying to find the best way to set indexes and primary keys on MSAccess tables What are the advantages and disadvantages of indexes and primary keys? What fields should be indexed?...
9
by: sonal | last post by:
Hi all, I hv started with python just recently... and have been assigned to make an utility which would be used for data validations... In short we take up various comma separated data files for...
115
by: LurfysMa | last post by:
Most of the reference books recommend autonum primary keys, but the Access help says that any unique keys will work. What are the tradeoffs? I have several tables that have unique fields. Can...
2
by: Danny | last post by:
Hello, We imported a bunch of tables from a database and realized that the primary keys weren't copied to the destination db. In order to re- create the keys, we need to know which tables have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.