Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Separate PK in Jxn Tbl?

1 view
Skip to first unread message

Neil

unread,
Jan 22, 2008, 3:26:42 PM1/22/08
to
Whenever I've created junction tables in the past, I always made the PK of
the junction table the combined pks from the two other tables. Ex: Table1
PK=A; Table2 PK=B; Junction table consists of two fields, A and B, which
together comprise the PK for the junction table.

However, I just came across some code in which the person created a junction
table with a separate PK consisting of an autonumber field, and then the two
fields.

So I was wondering how others did junction tables -- with a standalone
autonumber PK, or with a PK consisting of the PKs of the tables being
joined? And, if a standalone PK, then why?

Thanks!

Neil


Phil Stanton

unread,
Jan 22, 2008, 3:43:54 PM1/22/08
to
I always use just the 2 primary keys but....
If I were a library lending 2 undiffentiatable copies of 1 book to the same
person, I suppose I would need an Autonumber PK plus A BookID and
BorrowerID.

Phil

"Neil" <nos...@nospam.net> wrote in message
news:6kslj.128$J41...@newssvr14.news.prodigy.net...

Roy Hann

unread,
Jan 22, 2008, 4:02:07 PM1/22/08
to
"Phil Stanton" <ph...@stantonfamily.co.uk> wrote in message
news:13pclc9...@corp.supernews.com...

>I always use just the 2 primary keys but....
> If I were a library lending 2 undiffentiatable copies of 1 book to the
> same person, I suppose I would need an Autonumber PK plus A BookID and
> BorrowerID.

Hmm. Not persuaded. At best you have concealed a problem with the business
process, at worst you have allowed the very same copy to be lent multiple
times without detection.

I say this with some passion, having come home to find my cash register
receipt shows a single bottle of gin got scanned twice.

Roy


David Cressey

unread,
Jan 22, 2008, 4:23:48 PM1/22/08
to

"Neil" <nos...@nospam.net> wrote in message
news:6kslj.128$J41...@newssvr14.news.prodigy.net...

> So I was wondering how others did junction tables -- with a standalone


> autonumber PK, or with a PK consisting of the PKs of the tables being
> joined? And, if a standalone PK, then why?

With a PK consisting of the FKs that reference the tables being joined.

Is that what you meant?


John W. Vinson

unread,
Jan 22, 2008, 4:35:14 PM1/22/08
to
On Tue, 22 Jan 2008 20:26:42 GMT, "Neil" <nos...@nospam.net> wrote:

>So I was wondering how others did junction tables -- with a standalone
>autonumber PK, or with a PK consisting of the PKs of the tables being
>joined? And, if a standalone PK, then why?

I've done both; the separate primary key is (strictly speaking) never
necessary, but it can be handy if the junction table is itself related
one-to-many to an additional table or tables. Access doesn't make multifield
foreign keys all that easy to use (e.g. you can't use them in a combobox
without some messy code).

If I do so, I will always specify a unique (non-primary) Index on the two
parent foreign key fields.

John W. Vinson [MVP]

Bob Badour

unread,
Jan 22, 2008, 5:01:13 PM1/22/08
to
Roy Hann wrote:

From that last anecdote, one can conclude one of two things: 1) gin was
only a small part of the overal liquor purchase or 2) you were too drunk
to notice.

Either way, you are a lush! ;)

Phil Stanton

unread,
Jan 22, 2008, 5:01:31 PM1/22/08
to
Does a bottle of Gin have a serial no? I am too poor to buy 2 at a time to
see if there is a different number Ah!

Phil

"Roy Hann" <spec...@processed.almost.meat> wrote in message
news:obednVDy8opSxAva...@pipex.net...

JOG

unread,
Jan 22, 2008, 5:05:08 PM1/22/08
to
On Jan 22, 8:43 pm, "Phil Stanton" <p...@stantonfamily.co.uk> wrote:
> I always use just the 2 primary keys but....
> If I were a library lending 2 undiffentiatable copies of 1 book to the same
> person, I suppose I would need an Autonumber PK plus A BookID and
> BorrowerID.

So, say that book was "war and peace" and it was john who took it out
on loan, then you would be recording the propositions:

John has on loan the book "War and Peace" and
John has on loan the book "War and peace"

Genius ;) This is actually a relatively serious design flaw, as you
are trying to state the exact same fact twice. If the two books that
John took out really are indiscernible, then the proposition we have
actually recognized is:

John has on loan 2 copies of the book "War and Peace"

Roy Hann

unread,
Jan 22, 2008, 7:18:13 PM1/22/08
to
"Bob Badour" <bba...@pei.sympatico.ca> wrote in message
news:479667ab$0$4030$9a56...@news.aliant.net...

> From that last anecdote, one can conclude one of two things: 1) gin was
> only a small part of the overal liquor purchase or 2) you were too drunk
> to notice.

Actually I got the kids to buy it on the way home from school. :-)

Roy


Neil

unread,
Jan 22, 2008, 7:45:14 PM1/22/08
to

"John W. Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
news:78ocp31i3n533hh06...@4ax.com...


Good to know. That makes sense, about needing the PK to refer separately to
the junction table, if that situation exists.


Tony Toews [MVP]

unread,
Jan 22, 2008, 8:41:04 PM1/22/08
to
"Neil" <nos...@nospam.net> wrote:

>However, I just came across some code in which the person created a junction
>table with a separate PK consisting of an autonumber field, and then the two
>fields.
>
>So I was wondering how others did junction tables -- with a standalone
>autonumber PK, or with a PK consisting of the PKs of the tables being
>joined? And, if a standalone PK, then why?

I always use an autonumber PK and a uniqui index set on the two FK fields.

Why? No particular good reason. One of my database rules is that all tables have
an autonumber primary key. It's also slightly easier to delete the record in code.

Now if I was to have a child table from the junction table then I would absolutely
use a autonumber primary key for ease of use when designing queries, forms and
reports.

The theorists will argue. I don't care.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

Larry Linson

unread,
Jan 22, 2008, 10:03:55 PM1/22/08
to
"Roy Hann" <spec...@processed.almost.meat> wrote

> Actually I got the kids to buy it on the way home from school. :-)

That could have happened where I grew up -- it was a dry county, but liquor
was available from bootleggers and a few people who ran their own stills.


Jamie Collins

unread,
Jan 23, 2008, 4:05:46 AM1/23/08
to
On Jan 23, 1:41 am, "Tony Toews [MVP]" <tto...@telusplanet.net> wrote:
> I always use an autonumber PK and a uniqui index set on the two FK fields.
>
> Why? No particular good reason. One of my database rules is that all tables have
> an autonumber primary key.
>
> The theorists will argue. I don't care.

Would you care for a pragmatist to offer a counter argument?

I never seek to add columns where an attribute does not exist in the
reality being modelled; sometimes I do end up adding something
'artificial' but only when there is a "good data modelling" reason for
doing so.

In the scenario described, there is a two-column "all key" table which
means it is in 5NF. From a "data modelling" point of view I can't see
a case for adding an 'artifical key'.

Jamie.

--

JOG

unread,
Jan 23, 2008, 9:20:24 AM1/23/08
to

To the OP, I agree with this point of view. Again from a totally
practical standpoint, it is nonsense adding an artificial key would
not "make it slightly easier to delete records", because when
something changes in the real world, you need that data that made up
the 'original' superkey to know which row to delete anyhow.

I'd ignore anyone who claims to be telling you based on a purely
"practical" /or/ purely theoretical standpoints. Its always important
to be aware of both extremes, and balance them in order to work out
how to best get the job done.

>
> Jamie.
>
> --

JOG

unread,
Jan 23, 2008, 9:42:01 AM1/23/08
to
On Jan 23, 2:20 pm, JOG <j...@cs.nott.ac.uk> wrote:
> On Jan 23, 9:05 am, Jamie Collins <jamiecoll...@xsmail.com> wrote:
>
>
>
> > On Jan 23, 1:41 am, "Tony Toews [MVP]" <tto...@telusplanet.net> wrote:
>
> > > I always use an autonumber PK and a uniqui index set on the two FK fields.
>
> > > Why? No particular good reason. One of my database rules is that all tables have
> > > an autonumber primary key.
>
> > > The theorists will argue. I don't care.
>
> > Would you care for a pragmatist to offer a counter argument?
>
> > I never seek to add columns where an attribute does not exist in the
> > reality being modelled; sometimes I do end up adding something
> > 'artificial' but only when there is a "good data modelling" reason for
> > doing so.
>
> > In the scenario described, there is a two-column "all key" table which
> > means it is in 5NF. From a "data modelling" point of view I can't see
> > a case for adding an 'artifical key'.
>
> To the OP, I agree with this point of view. Again from a totally
> practical standpoint, it is nonsense adding an artificial key would
> not "make it slightly easier to delete records", because when
> something changes in the real world, you need that data that made up
> the 'original' superkey to know which row to delete anyhow.

That should have read "from a totally practical standpoint, adding an


artificial key would not 'make it slightly easier to delete

records'".

Dustin W. Jones

unread,
Jan 23, 2008, 12:01:49 PM1/23/08
to

I've done both. I try to use natural keys where applicable, usually
both PK's as the primary for the junction table.

Tony Toews [MVP]

unread,
Jan 23, 2008, 2:45:56 PM1/23/08
to
Jamie Collins <jamiec...@xsmail.com> wrote:

>> The theorists will argue. I don't care.
>
>Would you care for a pragmatist to offer a counter argument?

You're no pragmatist.

tony

David Cressey

unread,
Jan 23, 2008, 4:41:54 PM1/23/08
to

"Tony Toews [MVP]" <tto...@telusplanet.net> wrote in message
news:ii6dp3tc3l2u8m4nv...@4ax.com...

> "Neil" <nos...@nospam.net> wrote:
>
> >However, I just came across some code in which the person created a
junction
> >table with a separate PK consisting of an autonumber field, and then the
two
> >fields.
> >
> >So I was wondering how others did junction tables -- with a standalone
> >autonumber PK, or with a PK consisting of the PKs of the tables being
> >joined? And, if a standalone PK, then why?
>
> I always use an autonumber PK and a uniqui index set on the two FK fields.
>
> Why? No particular good reason. One of my database rules is that all
tables have
> an autonumber primary key. It's also slightly easier to delete the
record in code.
>
> Now if I was to have a child table from the junction table then I would
absolutely
> use a autonumber primary key for ease of use when designing queries, forms
and
> reports.
>
> The theorists will argue. I don't care.
>

Sometimes, theory IS practical. (Some would say always). A pragmatic person
would at least listen to the arguments of theorists before dismissing them.

Bob Badour

unread,
Jan 23, 2008, 4:59:59 PM1/23/08
to
David Cressey wrote:

The theorists won't argue. The theorists will simply point out the
inherent stupidity of abdicating thought for simplistic recipes. The
invincibly ignorant won't care. They never do.

Brian Selzer

unread,
Jan 23, 2008, 7:33:20 PM1/23/08
to

"Tony Toews [MVP]" <tto...@telusplanet.net> wrote in message
news:ii6dp3tc3l2u8m4nv...@4ax.com...
> "Neil" <nos...@nospam.net> wrote:
>
>>However, I just came across some code in which the person created a
>>junction
>>table with a separate PK consisting of an autonumber field, and then the
>>two
>>fields.
>>
>>So I was wondering how others did junction tables -- with a standalone
>>autonumber PK, or with a PK consisting of the PKs of the tables being
>>joined? And, if a standalone PK, then why?
>
> I always use an autonumber PK and a uniqui index set on the two FK fields.
>
> Why? No particular good reason. One of my database rules is that all
> tables have
> an autonumber primary key. It's also slightly easier to delete the
> record in code.
>

Only an idiot would have a rule for no particularly good reason. Only an
imbecile would follow such a rule. A strong argument can be made for using
autonumber primary keys--especially if the target DBMS doesn't support FOR
EACH ROW triggers--but to just blythely add them for no particularly good
reason is a recipe for disaster. A clear understanding of how and when they
can be used and why is critical or you run the risk of a corrupt database.

lyle fairfield

unread,
Jan 23, 2008, 9:01:16 PM1/23/08
to
"Brian Selzer" <br...@selzer-software.com> wrote in
news:l1Rlj.2866$nK5....@nlpi069.nbdc.sbc.com:

> Only an idiot would have a rule for no particularly good reason. Only
> an imbecile would follow such a rule. A strong argument can be made
> for using autonumber primary keys--especially if the target DBMS
> doesn't support FOR EACH ROW triggers--but to just blythely add them
> for no particularly good reason is a recipe for disaster. A clear
> understanding of how and when they can be used and why is critical or
> you run the risk of a corrupt database.

We often follow certain practices which we may describe as rules. These
customs may simplify our work, or contribute to its success.
Tony is a very experienced Access developer; readers of Comp Databases Ms-
Access have benefited from his sharing that experience, sometimes in
encapsulated form, as when he describes a usual, customary, or generalized
course of action or behaviour as a rule.

I follow the same rule. Having an auto-number primary key in each table
simplifies the establishment of relationships among tables. In Access, the
primary key auto-number ensures that forms bound to the table will be
editable, although any unique non-null index will serve that purpose. In
scripts using ADO, the primary key auto-number provides an identifier for
update and delete actions.

Could you cite instances of databases typically used with Access that have
been corrupted by auto-number primary keys?

Larry Linson

unread,
Jan 23, 2008, 9:14:29 PM1/23/08
to
"David Cressey" <cres...@verizon.net> wrote

> Sometimes, theory IS practical. (Some would say always).
> A pragmatic person would at least listen to the arguments
> of theorists before dismissing them.

In this case, of course, it is immaterial, because Tony is correct that
Jamie is not a pragmatist, at least not demonstrably so in his posts that I
have observed. Is there a category of "argumentist"?

Larry


Tony Toews [MVP]

unread,
Jan 23, 2008, 11:43:57 PM1/23/08
to
"Brian Selzer" <br...@selzer-software.com> wrote:

>Only an idiot would have a rule for no particularly good reason. Only an
>imbecile would follow such a rule. A strong argument can be made for using
>autonumber primary keys--especially if the target DBMS doesn't support FOR
>EACH ROW triggers--but to just blythely add them for no particularly good
>reason is a recipe for disaster.

My reasons are, in my opinion, good reasons. Not great but good. You don't like
them? Tough.

>A clear understanding of how and when they
>can be used and why is critical or you run the risk of a corrupt database.

Umm, not that you care I'm sure but my web pages on Microsoft Access corruptions
http://www.granite.ab.ca/access/corruptmdbs.htm are the definitive resource on the
web. And there have never been any Access corruptions during to autonumber primary
keys that I can recall. And I've likely read just about every posting on that topic
in the last eight or ten years in the comp.databases.ms-access and the
microsoft.public.access.* newsgroups.

However my knowledge is practical not theoretical.

Tony Toews [MVP]

unread,
Jan 23, 2008, 11:44:25 PM1/23/08
to
Bob Badour <bba...@pei.sympatico.ca> wrote:

>>>The theorists will argue. I don't care.
>>
>> Sometimes, theory IS practical. (Some would say always). A pragmatic person
>> would at least listen to the arguments of theorists before dismissing them.
>
>The theorists won't argue. The theorists will simply point out the
>inherent stupidity of abdicating thought for simplistic recipes. The
>invincibly ignorant won't care. They never do.

Hey, I thought you had plonked me.

Brian Selzer

unread,
Jan 24, 2008, 2:03:49 AM1/24/08
to

"Tony Toews [MVP]" <tto...@telusplanet.net> wrote in message
news:6l5gp3hle4cn2lin1...@4ax.com...

> "Brian Selzer" <br...@selzer-software.com> wrote:
>
>>Only an idiot would have a rule for no particularly good reason. Only an
>>imbecile would follow such a rule. A strong argument can be made for
>>using
>>autonumber primary keys--especially if the target DBMS doesn't support FOR
>>EACH ROW triggers--but to just blythely add them for no particularly good
>>reason is a recipe for disaster.
>
> My reasons are, in my opinion, good reasons. Not great but good. You
> don't like
> them? Tough.
>

So now they're good reasons? In your earlier post, you said they weren't
good reasons. Can't you make up your mind? You also haven't stated your
reasons. How can I like them or not like them? I don't know them!

>>A clear understanding of how and when they
>>can be used and why is critical or you run the risk of a corrupt database.
>
> Umm, not that you care I'm sure but my web pages on Microsoft Access
> corruptions
> http://www.granite.ab.ca/access/corruptmdbs.htm are the definitive
> resource on the
> web. And there have never been any Access corruptions during to
> autonumber primary
> keys that I can recall. And I've likely read just about every posting on
> that topic
> in the last eight or ten years in the comp.databases.ms-access and the
> microsoft.public.access.* newsgroups.
>

I was not speaking of corruption due to disk failures; I was instead
referring to permitting garbage into the database due to the misuse of
auto-number primary keys.

> However my knowledge is practical not theoretical.
>

I gained most of my knowledge the hard way as well, but that doesn't mean
that one shouldn't seek to understand and apply the theory.

JOG

unread,
Jan 24, 2008, 5:24:17 AM1/24/08
to
On Jan 24, 7:03 am, "Brian Selzer" <br...@selzer-software.com> wrote:
> "Tony Toews [MVP]" <tto...@telusplanet.net> wrote in messagenews:6l5gp3hle4cn2lin1...@4ax.com...

>
> > "Brian Selzer" <br...@selzer-software.com> wrote:
>
> >>Only an idiot would have a rule for no particularly good reason.  Only an
> >>imbecile would follow such a rule.  A strong argument can be made for
> >>using
> >>autonumber primary keys--especially if the target DBMS doesn't support FOR
> >>EACH ROW triggers--but to just blythely add them for no particularly good
> >>reason is a recipe for disaster.
>
> > My reasons are, in my opinion, good reasons.  Not great but good.  You
> > don't like
> > them?  Tough.
>
> So now they're good reasons?  In your earlier post, you said they weren't
> good reasons.  Can't you make up your mind?  You also haven't stated your
> reasons.  How can I like them or not like them?  I don't know them!

No, it looks like Tony's reasons are secret, and may only be gleaned
from a romantic evening of fine wine and barry white.

>
> >>A clear understanding of how and when they
> >>can be used and why is critical or you run the risk of a corrupt database.
>
> > Umm, not that you care I'm sure but my web pages on Microsoft Access
> > corruptions

> >http://www.granite.ab.ca/access/corruptmdbs.htmare the definitive


> > resource on the
> > web.   And there have never been any Access corruptions during to
> > autonumber primary
> > keys that I can recall.  And I've likely read just about every posting on
> > that topic
> > in the last eight or ten years in the comp.databases.ms-access and the
> > microsoft.public.access.* newsgroups.
>
> I was not speaking of corruption due to disk failures; I was instead
> referring to permitting garbage into the database due to the misuse of
> auto-number primary keys.

An actual example I experience springs to mind - I have witnessed a
database where student projects were recorded via a schema of Project
Partners:{id:autonumber, RoleA:person, RoleB:person}, with PK(id).
None of the partnerships were aware of any "id" in the real world, and
simply submitted their partnership choices on paper to admin. A
clerical error resulted in 2/3 of the data being entered twice, which
left a lot of people flapping about the number of markers required
until the error was found. If the schema had used the natural {RoleA,
RoleB} key there would have been no issue.

But then for all I know, MS Access might allow duplicates anyhow....

>
> > However my knowledge is practical not theoretical.
>
> I gained most of my knowledge the hard way as well, but that doesn't mean
> that one shouldn't seek to understand and apply the theory.
>
>
>
> > Tony
> > --
> > Tony Toews, Microsoft Access MVP
> >   Please respond only in the newsgroups so that others can
> > read the entire thread of messages.
> >   Microsoft Access Links, Hints, Tips & Accounting Systems at
> >http://www.granite.ab.ca/accsmstr.htm

> >   Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/- Hide quoted text -
>
> - Show quoted text -

Jamie Collins

unread,
Jan 24, 2008, 6:09:32 AM1/24/08
to
On Jan 24, 10:24 am, JOG <j...@cs.nott.ac.uk> wrote:
> An actual example I experience springs to mind - I have witnessed a
> database where student projects were recorded via a schema of Project
> Partners:{id:autonumber, RoleA:person, RoleB:person}, with PK(id).
> None of the partnerships were aware of any "id" in the real world, and
> simply submitted their partnership choices on paper to admin. A
> clerical error resulted in 2/3 of the data being entered twice, which
> left a lot of people flapping about the number of markers required
> until the error was found. If the schema had used the natural {RoleA,
> RoleB} key there would have been no issue.

My experience, also. That's not to say that everyone who uses
autonumber PKs neglects to put constraints on alternate/candidate keys
but I do encounter autonumber problems frequently i.e. tables where
the only unique constraint/index is a PK on the autonumber column,
which actually *facilitates* the inclusion of duplicates by giving the
developer a false sense of security: "I've added a PK, I've done my
bit." Being able to uniquely identify duplicates is of no comfort to
me.

Who do we have to blame for this state of affairs? The Access
interface, IMO. If you omit to define the PK when creating a table in
Design View, upon saving you get prompted to add a primary key (good)
but instead of providing a way to choose existing columns, the offer
is to add an autonumber. If you haven't got a key to begin with,
autonumber cannot provide you with one unless you expose it to end
users which everyone says you shouldn't do (everyone except Tony
Toews, naturally <g>). The message even asserts that you need a PK to
be able to create Relationships that reference the table which isn't
true of Access Relationships (which are so vague they can even be
based on columns of different respective data types) nor Jet foreign
keys (which can be based on a unique constraint/index). BTW in Access
2007 you now just get given an autonumber PK by default, which you
would then have to go to the trouble to remove.

> it looks like Tony's reasons are secret, and may only be gleaned
> from a romantic evening of fine wine and barry white.

Hmm, I once tried this with Tony [TIC]: I spent hours cooking him his
favourite dish, getting the seasoning just right. And what does he do
when we've sat down? He picks up the salt and, just as he was about to
apply it to the food I'd lovingly prepared, I cried out, "Tony, aren't
you going to test it for seasoning first? I think you'll find it is
just fine." He replied, "I always add salt to my food. Why? No
particular good reason. One of my rules is that all food needs extra
salt." I was about to protest when he added, "You don't like my rules?
Tough. I don't care." Well, you can imagine how hurt I was, reader.
Not as much as Tony after I'd thrown him off the balcony, though.

Jamie.

--


Jamie Collins

unread,
Jan 24, 2008, 6:18:37 AM1/24/08
to
On Jan 24, 2:14 am, "Larry Linson" <boun...@localhost.not> wrote:
> > A pragmatic person would at least listen to the arguments
> > of theorists before dismissing them.
>
> In this case, of course, it is immaterial, because Tony is correct that
> Jamie is not a pragmatist, at least not demonstrably so in his posts that I
> have observed.

Care to back up your claim with some evidence?

No, you are mistaken. I *frequently* (to the point of boring people,
I'm sure) back up my assertions with Jet SQL code, VBA demos, links to
Microsoft articles and the Access Help, and stories from the field.
This thread is a good example of that.

> Is there a category of "argumentist"?

I think the word you are looking for is "critic".

Jamie.

--

Jamie Collins

unread,
Jan 24, 2008, 6:24:06 AM1/24/08
to
On Jan 24, 11:09 am, Jamie Collins <jamiecoll...@xsmail.com> wrote:
> > Tony's reasons are secret, and may only be gleaned
> > from a romantic evening of fine wine and barry white.
>
> Hmm, I once tried this with Tony [TIC]

I also tried it with Bob Badour [TIC] but he merely dismissed my
simplistic recipes and wanted more plonk.

Jamie.

--

lyle

unread,
Jan 24, 2008, 8:26:25 AM1/24/08
to
On Jan 24, 6:09 am, Jamie Collins <jamiecoll...@xsmail.com> wrote:

> He picks up the salt and, just as he was about to
> apply it to the food I'd lovingly prepared, I cried out, "Tony, aren't
> you going to test it for seasoning first? I think you'll find it is
> just fine." He replied, "I always add salt to my food. Why? No
> particular good reason. One of my rules is that all food needs extra
> salt."

Thank you. I've learned that Tony and I share two rules.

JOG

unread,
Jan 24, 2008, 8:47:40 AM1/24/08
to

I imagine he meant "antagonist" to be honest. But then, only seeing
this thread from c.d.t and not knowing the ms-access glitterati, I
have no idea as to whether he would be correct in such an assertion.

I just think you're all damn brave for using Access in the first
place.

>
> Jamie.
>
> --

Jamie Collins

unread,
Jan 24, 2008, 9:00:49 AM1/24/08
to
On Jan 24, 1:26 pm, lyle <lyle.fairfi...@gmail.com> wrote:
> Thank you. I've learned that Tony and I share two rules.

It was an analogy and meant to be taken with a pinch of salt ;-)

Jamie.

--

David Cressey

unread,
Jan 24, 2008, 1:43:21 PM1/24/08
to

"JOG" <j...@cs.nott.ac.uk> wrote in message
news:2b0cf2d3-8b8e-4dc5...@d4g2000prg.googlegroups.com...

On Jan 24, 7:03 am, "Brian Selzer" <br...@selzer-software.com> wrote:
(quote)

An actual example I experience springs to mind - I have witnessed a
database where student projects were recorded via a schema of Project
Partners:{id:autonumber, RoleA:person, RoleB:person}, with PK(id).
None of the partnerships were aware of any "id" in the real world, and
simply submitted their partnership choices on paper to admin. A
clerical error resulted in 2/3 of the data being entered twice, which
left a lot of people flapping about the number of markers required
until the error was found. If the schema had used the natural {RoleA,
RoleB} key there would have been no issue.

But then for all I know, MS Access might allow duplicates anyhow....

(/quote)

I have begun to mess around with MS Access, as a retirement hobby, after
working professionally with some SQL DBMS products.

AFAIK, MS Access enforces the no duplicates rule, and the no missing data
rule, for every PK that's declared. There are other ways to express these
constraints, but the easiest way to get them is to declare a PK.

For that reason, I prefer not to create a new ID with an autonumber for any
junction table. Tony have have his reasons for going the other way. Until
I know what they are, I remain unpersuaded.

The fact tables in a star schema have the same property as a junction table,
except that the number of FKs that are components of the PK may be larger
than 2, and generally is larger.


I've just started messing with star schemas in MS Access. It's too soon for
me to offer even a guess as to whether this is a smart idea or a stupid
idea. All I know is that it will provide some cheap amusement for my
retirement.


Jamie Collins

unread,
Jan 24, 2008, 3:36:18 PM1/24/08
to
On Jan 24, 6:43 pm, "David Cressey" <cresse...@verizon.net> wrote:
> I've just started messing with star schemas in MS Access. It's too soon for
> me to offer even a guess as to whether this is a smart idea or a stupid
> idea. All I know is that it will provide some cheap amusement for my
> retirement.

Please post you findings here ;)

Jamie.

--

Tony Toews [MVP]

unread,
Jan 24, 2008, 3:53:39 PM1/24/08
to
JOG <j...@cs.nott.ac.uk> wrote:

>I just think you're all damn brave for using Access in the first
>place.

Why? It works and works well. If you have too many users or remote users bolt on a
SQL Server backend. Now you can have thousands of users.

James A. Fortune

unread,
Jan 24, 2008, 6:00:36 PM1/24/08
to
Neil wrote:
> Whenever I've created junction tables in the past, I always made the PK of
> the junction table the combined pks from the two other tables. Ex: Table1
> PK=A; Table2 PK=B; Junction table consists of two fields, A and B, which
> together comprise the PK for the junction table.
>
> However, I just came across some code in which the person created a junction
> table with a separate PK consisting of an autonumber field, and then the two
> fields.
>
> So I was wondering how others did junction tables -- with a standalone
> autonumber PK, or with a PK consisting of the PKs of the tables being
> joined? And, if a standalone PK, then why?
>
> Thanks!
>
> Neil

Whenever I have multiple key fields, natural or not, I create an
AutoNumber PK for pragmatic reasons. The main reason is that it makes
it easier to create the joins. The theorists are champions at joining
tables and don't have to be concerned with the complexity of the SQL
they write. If I convert an Access table over to SQLServer I add even
another field as a primary key, usually prefixed with SS (Gasp!).

I keep Jamie's advice in the back of my mind, about how enforcing
constraints at the table level is better than enforcing them through
code, but where I work, no one is going to access the table data using
anything other than Access so I am able to take the high road at my
leisure. Maybe my coding practice just needs to catch up with my
philosophy. Theoretically, the idea of using natural keys is more
intellectually satisfying, but for now the lure of simpler joins is
winning out. Lately, I've increased the amount of normalization in one
of my databases and the joins got even more complicated, adding about a
line or so in the SQL view in Access for every new query using those
tables. Queries involving many to many relationships often add
additional tables later and highlight the need to keep joins as simple
as possible.

James A. Fortune
MPAP...@FortuneJames.com

Bob Badour

unread,
Jan 24, 2008, 6:40:21 PM1/24/08
to
James A. Fortune wrote:

> Neil wrote:
>
>> Whenever I've created junction tables in the past, I always made the
>> PK of the junction table the combined pks from the two other tables.
>> Ex: Table1 PK=A; Table2 PK=B; Junction table consists of two fields, A
>> and B, which together comprise the PK for the junction table.
>>
>> However, I just came across some code in which the person created a
>> junction table with a separate PK consisting of an autonumber field,
>> and then the two fields.
>>
>> So I was wondering how others did junction tables -- with a standalone
>> autonumber PK, or with a PK consisting of the PKs of the tables being
>> joined? And, if a standalone PK, then why?
>>
>> Thanks!
>>
>> Neil
>
> Whenever I have multiple key fields, natural or not, I create an
> AutoNumber PK for pragmatic reasons. The main reason is that it makes
> it easier to create the joins. The theorists are champions at joining
> tables and don't have to be concerned with the complexity of the SQL
> they write.

Anyone who writes SQL is a theorist regardless whether the person is
smart enough and educated enough to realise it.


If I convert an Access table over to SQLServer I add even
> another field as a primary key, usually prefixed with SS (Gasp!).

There is no stopping the invincibly ignorant. -- DT


> I keep Jamie's advice in the back of my mind, about how enforcing
> constraints at the table level is better than enforcing them through
> code, but where I work, no one is going to access the table data using
> anything other than Access so I am able to take the high road at my
> leisure.

Uh huh. ::rolls eyes::


Maybe my coding practice just needs to catch up with my
> philosophy. Theoretically, the idea of using natural keys is more
> intellectually satisfying, but for now the lure of simpler joins is
> winning out.

You sound like one of these programmers who writes shitty, buggy code to
avoid a few keystrokes.


Lately, I've increased the amount of normalization in one
> of my databases and the joins got even more complicated,

Define "amount of normalization". Do you even have a clue what it is?


adding about a
> line or so in the SQL view in Access for every new query using those
> tables. Queries involving many to many relationships often add
> additional tables later and highlight the need to keep joins as simple
> as possible.

An intelligent, informed person would always follow the design principle
of "As simple as possible and no simpler." I don't see what that has to
do with joining tables (or relations for that matter) other than perhaps
the ability to even recognize complexity when one sees it.

Following the above design principle, one would not needlessly increase
complexity with additional arbitrary columns and keys.

David W. Fenton

unread,
Jan 24, 2008, 7:44:28 PM1/24/08
to
JOG <j...@cs.nott.ac.uk> wrote in
news:2b0cf2d3-8b8e-4dc5...@d4g2000prg.googlegroups.com
:

> But then for all I know, MS Access might allow duplicates
> anyhow....

Any database engine can have the schema defined in a way that will
allow duplicates. This is not an issue of the db engine in use, but
of the skill of the operator in association with the requirements of
the application the database is used with.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

David W. Fenton

unread,
Jan 24, 2008, 7:45:51 PM1/24/08
to
JOG <j...@cs.nott.ac.uk> wrote in
news:ffbc6130-a98c-4177...@t1g2000pra.googlegroups.com
:

> I just think you're all damn brave for using Access in the first
> place.

That just goes to show you haven't got a clue about what MS Access
actually is.

Typical.

Larry Daugherty

unread,
Jan 24, 2008, 8:04:51 PM1/24/08
to
This boil up is a variation of the "Autonumber vs. Natural Key"
religious wars that sweep the Access groups on even numbered(?) years.
In the meantime OP is probably trying to hide the matches with which
he started the fires....

Until this thread, I thought that I might be the only person in the
world who reflexively entered an Autonumber PK into *every* table I
design. My reasons for using Autonumber PKs is practical and based on
experience.

As for using them in junction tables, I once stopped and thought about
it. I couldn't see a risk in either using them or not using them.
Since Autonumber PKs had saved me countless hours of re-work in normal
tables, my bias was and is to use them. I don't revisit that decision
every time I create a junction table, I just do it. Apparently, Tony
Toews went through similar reasoning. I didn't ask anyone's advice or
permission. It is not necessary that anyone else be persuaded to use
any method I adopt.

It has never caused me the least problem. There has been no
revelation in this thread that would cause me to even revisit the
decision.

In the one reported instance of a "problem", the Autonumber PK along
with the two FKs wasn't the issue. That configuration simply spewed
different erroneous data from the erroneous data that would be spewed
by sticking with natural keys alone. As reported, the problem in that
case was erroneous data entry not a flawed schema.

My advice to OP and to everyone else is to use which ever mode seems
best to him or her.

HTH
--
-Larry-
--

"Phil Stanton" <ph...@stantonfamily.co.uk> wrote in message
news:13pclc9...@corp.supernews.com...
> I always use just the 2 primary keys but....
> If I were a library lending 2 undiffentiatable copies of 1 book to
the same
> person, I suppose I would need an Autonumber PK plus A BookID and
> BorrowerID.
>
> Phil
>
> "Neil" <nos...@nospam.net> wrote in message
> news:6kslj.128$J41...@newssvr14.news.prodigy.net...

Bob Badour

unread,
Jan 24, 2008, 8:08:24 PM1/24/08
to
Larry Daugherty wrote:
> This boil up is a variation of the "Autonumber vs. Natural Key"
> religious wars that sweep the Access groups on even numbered(?) years.
> In the meantime OP is probably trying to hide the matches with which
> he started the fires....
>
> Until this thread, I thought that I might be the only person in the
> world who reflexively entered an Autonumber PK into *every* table I
> design. My reasons for using Autonumber PKs is practical and based on
> experience.

Bullshit! Ignorance, stupidity and laziness are not practical.

[snip]

Tony Toews [MVP]

unread,
Jan 24, 2008, 8:13:47 PM1/24/08
to
"Larry Daugherty" <Larry.NoSpa...@verizon.net> wrote:

>This boil up is a variation of the "Autonumber vs. Natural Key"
>religious wars that sweep the Access groups on even numbered(?) years.
>In the meantime OP is probably trying to hide the matches with which
>he started the fires....

<chuckle> Yup, it's amazing how this all happens. To me the particularly amusing
part is that we're generally quite civil in our discussions that stay in the Access
groups.

I'm saddened, although not surprised, at the comments from a few regulars from the
c.d.theory newsgroup using words such as idiot, imbecile and invincibly ignorant.

JOG

unread,
Jan 24, 2008, 8:35:22 PM1/24/08
to
On Jan 24, 8:53 pm, "Tony Toews [MVP]" <tto...@telusplanet.net> wrote:
> JOG <j...@cs.nott.ac.uk> wrote:
> >I just think you're all damn brave for using Access in the first
> >place.
>
> Why?

I was tempted to simply reply:

"avoiding using Access is just a rule I have. Why? No good reason. The
access fanboys will argue. I don't care"

...but, hey that sort of sentiment would surely just be peurile, and
discourage useful discussion would it not?

> It works and works well. If you have too many users or remote users bolt on a
> SQL Server backend. Now you can have thousands of users.

Or I could just use a decent database architecture in the first place
(and I am lucky enough to be able to), that can cope with more that 10
users (I mean 255 *cough*). Thats why I salute your dedication in the
face of all that superior db technology. I mean, we all know that the
client really wants to use oracle, and yet its you that stoutly has to
deal with his corner cutting as best you can.

I certainly don't mean to upset you....Well okay, maybe there's just a
bit of friendly ribbing in there ;)

>
> Tony
> --
> Tony Toews, Microsoft Access MVP
> Please respond only in the newsgroups so that others can
> read the entire thread of messages.

> Microsoft Access Links, Hints, Tips & Accounting Systems athttp://www.granite.ab.ca/accsmstr.htm

Larry Daugherty

unread,
Jan 24, 2008, 8:42:44 PM1/24/08
to
Every dog gets one bite. Then they go into the bs/Kill file.

Did you note the net contribution to the subject at hand? Their
commentary serves only to identify and characterize *themselves*

My hope is to make meaningful contributions to those who are actually
developing applications or learning to do so.

Keep up the good work!
--
-Larry-
--

"Tony Toews [MVP]" <tto...@telusplanet.net> wrote in message
news:fmdip39pv9vtpetuk...@4ax.com...

lyle fairfield

unread,
Jan 24, 2008, 8:51:10 PM1/24/08
to
Bob Badour <bba...@pei.sympatico.ca> wrote in news:4799368c$0$4065
$9a56...@news.aliant.net:

> Bullshit! Ignorance, stupidity and laziness are not practical.

If you’re feeling angry because you can’t program or design databases well,
perhaps you could describe your problems here, instead of posting streams
of invective. I’m sure that Tony, James or Larry will be able to simplify
the concepts required and suggest solutions suitable even for someone who
seems so backward and confused.

Hope this helps!

Bob Badour

unread,
Jan 24, 2008, 8:56:06 PM1/24/08
to
Larry Daugherty wrote:

> Every dog gets one bite. Then they go into the bs/Kill file.
>
> Did you note the net contribution to the subject at hand? Their
> commentary serves only to identify and characterize *themselves*
>
> My hope is to make meaningful contributions to those who are actually
> developing applications or learning to do so.

Your hope is futile in the face of your ignorance and laziness.


> Keep up the good work!

I'll try.


"Tony Toews [MVP]" <tto...@telusplanet.net> wrote in message
news:fmdip39pv9vtpetuk...@4ax.com...

>> "Larry Daugherty" <Larry.NoSpa...@verizon.net> wrote:
>>
>
>>> >This boil up is a variation of the "Autonumber vs. Natural Key"
>>> >religious wars that sweep the Access groups on even numbered(?) years.
>>> >In the meantime OP is probably trying to hide the matches with which
>>> >he started the fires....
>
>>
>> <chuckle> Yup, it's amazing how this all happens. To me the
particularly amusing
>> part is that we're generally quite civil in our discussions that
stay in the Access
>> groups.

Ignorance is bliss.


>> I'm saddened, although not surprised, at the comments from a few
regulars from the
>> c.d.theory newsgroup using words such as idiot, imbecile and
invincibly ignorant.

Precious few pleasant ways exist to express unpleasant truths. However,
intellectual honesty requires the expression of truths regardless of
appeal to oneself or to others.

Tony Toews [MVP]

unread,
Jan 24, 2008, 9:06:17 PM1/24/08
to
JOG <j...@cs.nott.ac.uk> wrote:

>> Why?
>
>I was tempted to simply reply:
>
>"avoiding using Access is just a rule I have. Why? No good reason. The
>access fanboys will argue. I don't care"
>
>...but, hey that sort of sentiment would surely just be peurile, and
>discourage useful discussion would it not?

<chuckle>

>> It works and works well. If you have too many users or remote users bolt on a
>> SQL Server backend. Now you can have thousands of users.
>
>Or I could just use a decent database architecture in the first place
>(and I am lucky enough to be able to), that can cope with more that 10
>users (I mean 255 *cough*). Thats why I salute your dedication in the
>face of all that superior db technology. I mean, we all know that the
>client really wants to use oracle, and yet its you that stoutly has to
>deal with his corner cutting as best you can.

But in many situations why go to the extra effort of Oracle or <cough> SQL Server
required? I seldom create systems that will be used by more than ten people. Using
Access in such an environment is a simpler install and simple updating. No DBA
required and very little IT admin.

>I certainly don't mean to upset you....Well okay, maybe there's just a
>bit of friendly ribbing in there ;)

<smile>

Tony Toews [MVP]

unread,
Jan 24, 2008, 9:24:07 PM1/24/08
to
Bob Badour <bba...@pei.sympatico.ca> wrote:

> >> <chuckle> Yup, it's amazing how this all happens. To me the
>particularly amusing
> >> part is that we're generally quite civil in our discussions that
>stay in the Access
> >> groups.
>
>Ignorance is bliss.

Politeness goes a long way.

Tony Toews [MVP]

unread,
Jan 24, 2008, 9:23:52 PM1/24/08
to
JOG <j...@cs.nott.ac.uk> wrote:

>I was tempted to simply reply:
>
>"avoiding using Access is just a rule I have. Why? No good reason. The
>access fanboys will argue. I don't care"
>
>...but, hey that sort of sentiment would surely just be peurile, and
>discourage useful discussion would it not?

BTW I didn't realize that there were people in the theory newsgroup who actually
wanted to discuss the issues in a reasonable fashion.

Bob Badour

unread,
Jan 24, 2008, 10:07:37 PM1/24/08
to
lyle fairfield wrote:

> Bob Badour <bba...@pei.sympatico.ca> wrote in news:4799368c$0$4065
> $9a56...@news.aliant.net:
>
>>Bullshit! Ignorance, stupidity and laziness are not practical.
>
> If you�re feeling angry because you can�t program or design databases well,

Your question suffers the fallacy of many questions. First, I don't feel
angry at all. Second, I can do both very well. Are you feeling angry
because you can't program or design databases well?


> perhaps you could describe your problems here, instead of posting streams
> of invective. I�m sure that Tony, James or Larry will be able to simplify
> the concepts required and suggest solutions suitable even for someone who
> seems so backward and confused.

Since they are simpletons, I have no doubt they would simplify the
concepts ... beyond all recognition.


> Hope this helps!

Ed Prochak

unread,
Jan 24, 2008, 10:54:20 PM1/24/08
to

Tony Toews [MVP] wrote:


> "Neil" <nos...@nospam.net> wrote:
>
> >However, I just came across some code in which the person created a junction
> >table with a separate PK consisting of an autonumber field, and then the two
> >fields.
> >
> >So I was wondering how others did junction tables -- with a standalone
> >autonumber PK, or with a PK consisting of the PKs of the tables being
> >joined? And, if a standalone PK, then why?
>

> I always use an autonumber PK and a uniqui index set on the two FK fields.
>
> Why? No particular good reason. One of my database rules is that all tables have
> an autonumber primary key. It's also slightly easier to delete the record in code.
>
> Now if I was to have a child table from the junction table then I would absolutely
> use a autonumber primary key for ease of use when designing queries, forms and
> reports.
>
> The theorists will argue. I don't care.
>
> Tony

Why introduce an autonumber as a PK when you don't need to? This
design is broken as noted in the discussion on library book example.
Why make the application code work harder than it has to? Let the DBMS
do the work that it is good at.

Note I'm no theorist. I'm a stuck in the trenches Software Engineer.
There are times to use an autonumber PK. But in this case I would say
you are fooling yourself in thinking this is good design practice.

Ed

Brian Selzer

unread,
Jan 25, 2008, 5:01:40 AM1/25/08
to

"Tony Toews [MVP]" <tto...@telusplanet.net> wrote in message
news:fmdip39pv9vtpetuk...@4ax.com...
> "Larry Daugherty" <Larry.NoSpa...@verizon.net> wrote:
>
>>This boil up is a variation of the "Autonumber vs. Natural Key"
>>religious wars that sweep the Access groups on even numbered(?) years.
>>In the meantime OP is probably trying to hide the matches with which
>>he started the fires....
>
> <chuckle> Yup, it's amazing how this all happens. To me the
> particularly amusing
> part is that we're generally quite civil in our discussions that stay in
> the Access
> groups.
>
> I'm saddened, although not surprised, at the comments from a few regulars
> from the
> c.d.theory newsgroup using words such as idiot, imbecile and invincibly
> ignorant.
>

Are we feeling a bit abused? Do we need a pity party? All together now,
1...2...3.... There, now, did that make poor little Tony feel any better?

Please don't lump me in with Badour. I rarely use the terms, 'idiot' and
'imbecile,' but (and I think if you'll reexamine it dispassionately, you'll
agree) your original statement in this thread was, in my opinion, pretty
idiotic. Oh, and by the way, you still haven't shared your reasons. What
are you afraid of?

JOG

unread,
Jan 25, 2008, 7:59:31 AM1/25/08
to
On Jan 25, 2:23 am, "Tony Toews [MVP]" <tto...@telusplanet.net> wrote:
> JOG <j...@cs.nott.ac.uk> wrote:
> >I was tempted to simply reply:
>
> >"avoiding using Access is just a rule I have. Why? No good reason. The
> >access fanboys will argue. I don't care"
>
> >...but, hey that sort of sentiment would surely just be peurile, and
> >discourage useful discussion would it not?
>
> BTW I didn't realize that there were people in the theory newsgroup who actually
> wanted to discuss the issues in a reasonable fashion.

Then consider yourself corrected ;) One person's posting style does
not a news group make (and FWIW if you can get past that posting style
there is a lot of value to be had imo). I had a look at your own
website and saw the effort you have put in to help other people, so
kudos for that. But this is partly why I was so suprised at your
"That's my rule, no good reason and if anyone disagrees sod 'em" post.

I have given an example of where using an artifical key broke a
database, and I'd stoutly argue that _hidden_ attributes are
dangerous, period. I'm dubious as to how they simplify queries (they
may shorten them, but not reduce their complexity as far as I can
see), but I can also think of instances where they opposite would be
the case. However, I am of course happy to be illuminated by some
examples, if any access people want to convince me that using
artificial keys on every table I create is a good thing...

J.

>
> Tony
> --
> Tony Toews, Microsoft Access MVP
> Please respond only in the newsgroups so that others can
> read the entire thread of messages.

> Microsoft Access Links, Hints, Tips & Accounting Systems athttp://www.granite.ab.ca/accsmstr.htm

Jamie Collins

unread,
Jan 25, 2008, 9:12:03 AM1/25/08
to
On Jan 24, 11:00 pm, "James A. Fortune" <MPAPos...@FortuneJames.com>
wrote:

> Whenever I have multiple key fields, natural or not, I create an
> AutoNumber PK for pragmatic reasons. The main reason is that it makes
> it easier to create the joins. The theorists are champions at joining
> tables and don't have to be concerned with the complexity of the SQL
> they write.

Word to the wise: 'theorists' hate SQL.

> Queries involving many to many relationships often add
> additional tables later and highlight the need to keep joins as simple
> as possible.

I think I'm with Bob Badour (gulp!) on the issue of complexity,
though: if you think more columns in the ON clause makes a SQL join
more 'complex' then I think you could be looking at things wrong.
Having more characters to type increases the risk of typos? More
columns mean you may omit one in error? The SQL engine may be twice as
slow in handling two columns rather than one? Is it more 'complex' to
split a post address into 'subatomic' columns (address lines from
postal code/zip etc)?

Surely the issue you allude to (I think) is the one that Access
Relationships (as distinct from Jet foreign keys) were invented to
solve? i.e. you pre-define the join columns and 'join type' (inner
join, left outer join or right outer join) and the join clause gets
written as SQL for you when you drop the tables into the Query Builder
thing. I would have thought the 'theorists' would love the fact that
you also create foreign keys in the same Relationships dialog i.e. you
end up with a natural join (not having to explicitly specify the
columns yourself) because one table references the other.

[I tend to be dismissive of tools that write SQL code for me but I
think I should perhaps review my stance e.g. I still write all my SQL
Server procs by hand whereas I have tasked myself to investigate CRUD
generators. But, for the time being, ...] As a SQL coder myself, I
find it more annoying that I have to create multiple joins to get the
'natural key' values, having to discover what the 'artificial key'
columns are in the first place.

> Lately, I've increased the amount of normalization in one
> of my databases and the joins got even more complicated, adding about a
> line or so in the SQL view in Access for every new query using those
> tables.

Bad luck: I think you might have got way with "reduced the amount of
denormalization" ;-) In this thread I've already broken my personal
rule (!!) about not mentioning normalization [formulated because the
average 'replier' around here thinks "fully normalized" is BCNF, which
they think is 3NF anyhow, and doesn't pay much attention to anomalies
that normalization doesn't address, unless the 'asker' mentions
storing calculations...]

> I keep Jamie's advice in the back of my mind, about how enforcing
> constraints at the table level is better than enforcing them through
> code

..and best to do it in both places! Bear in mind that it's a rule of
thumb i.e. "strict rules modified in practise." Checking something in
the in front end allows you to give timely user feedback and could
save them some keying, not to mention a database roundtrip. Checking
in the database catches anything neglected in the front end by
omission of validation or introduction of bugs. In practice, some
things are better done in one place but not the other: contrast the
validation of the basic pattern of an email address with the
verification that an addressable entity can be contacted at that email
address; I don't think it would be sensible to put the latter test
into a table constraint, even if it were possible.

Jamie.

--

Jamie Collins

unread,
Jan 25, 2008, 9:17:04 AM1/25/08
to
On Jan 23, 12:45 am, "Neil" <nos...@nospam.net> wrote:
> > I've done both; the separate primary key is (strictly speaking) never
> > necessary, but it can be handy if the junction table is itself related
> > one-to-many to an additional table or tables. Access doesn't make
> > multifield
> > foreign keys all that easy to use (e.g. you can't use them in a combobox
> > without some messy code).
>
> Good to know. That makes sense, about needing the PK to refer separately to
> the junction table, if that situation exists.

Why do you say "needing the PK"? JohnV no doubt makes a good case when
considering bound controls in Access but I would point out that he
also said the PK is "never necessary, but it can be handy".

Jamie.

--

Jamie Collins

unread,
Jan 25, 2008, 9:54:27 AM1/25/08
to
On Jan 25, 1:13 am, "Tony Toews [MVP]" <tto...@telusplanet.net> wrote:
> I'm saddened, although not surprised, at the comments from a few regulars from the
> c.d.theory newsgroup using words such as idiot

"Clearly the person is an idiot and is better off employed at a 7-11."
http://groups.google.com/group/microsoft.public.access.conversion/msg/163c373772d787d3

"One idiot student once emailed me"
http://groups.google.com/group/microsoft.public.access.modulesdaovba/msg/4d5e152c11a9e0a3

"tell him he's an idiot"
http://groups.google.com/group/microsoft.public.access/msg/31c0abc7b367656d

"This person is an idiot."
http://groups.google.com/group/microsoft.public.access/msg/6fedf72a4680cf25

"But no, some idiot manager at Mickeysoft..."
http://groups.google.com/group/microsoft.public.access.forms/msg/222d3ed992e9a2ec

Jamie.

--

Jamie Collins

unread,
Jan 25, 2008, 10:10:13 AM1/25/08
to
On Jan 25, 12:59 pm, JOG <j...@cs.nott.ac.uk> wrote:
> I had a look at your own
> website and saw the effort you have put in to help other people, so
> kudos for that. But this is partly why I was so suprised at your
> "That's my rule, no good reason and if anyone disagrees sod 'em" post.

I too would like to pay tribute here to Tony Toews Access MVP, he does
help a lot of people and does not deserve a hard time (same for Larry
Linson, great guy, kind of the grandfather of this group, I like to
think, though I still wonder what I did to offend him). I too read his
website a while back and there's some good stuff in there and some
links to some great chuckle-some comedy. Which leads me nicely...

Sorry to spoil anyone's fund but am I the only one to spot the
duplicitous (pun intended, natch) nature of this post and other
similar ones recently i.e. where he *seems* to treat people he should
care about (community regulars, newbies, his own clients, etc) with
contempt? I think he knew he was lighting the blue touch paper of this
thread by saying, "I don't care" and I might be partly responsible for
this because I did kind of give him a good response to the same trick
last week. Come on people, lighten up! Tony is being light-hearted,
tickling your ribs. And I congratulate him for it, things can get dull
around here :)

Jamie.

--

rkc

unread,
Jan 25, 2008, 4:59:18 PM1/25/08
to

Oops.

CDMAP...@fortunejames.com

unread,
Jan 25, 2008, 5:31:38 PM1/25/08
to

What part of simpler don't you understand :-). Only one expression in
the ON is simpler. Needing less indexes is simpler. Not having to
look for your multi-key fields is easier, although your point that
Relationships can handle that is valid. If the AutoNumber key has a
one-to-one relationship with the multi-key fields then it's fine to
use it. There's no down side that I can see. I also like to rely on
coding to detect inconsistent data rather than on error trapping, so I
have to check the multi-key values anyway before adding a new record.
I think that your idea about enforcing constraints at both the table
level and in code is an excellent idea. The OP wanted to know what
people did and why. I still don't see any reason put forward for me
to change to a multi-field key. Are totals queries easier when multi-
field keys are used? BTW, "reduced the amount of denormalization"
works just as well. Real databases experience denormalizing
influences.

James A. Fortune
CDMAP...@FortuneJames.com

Sylvain Lafontaine fill the blanks, no spam please

unread,
Jan 26, 2008, 2:46:20 AM1/26/08
to
To that, I would add that the increased simplicity of using a surrogate (or
artificial or autonumber) key as the primary key in place of a composite key
is only half their advantage.

The biggest problem that I have with composite keys is that they share the
same fundamental problem as natural keys: using them as the primary key is
allowing the fact that a primary key can change its value over time. IMHO,
a primary key should never be allowed to change its value once it has been
created; a assumption which will forbid the use of a composite key in many
cases. (Of course, if you don't mind to see a primary key changing its
value after its creation then you are not concerned by this argument.).

This is not only a theoritical argument as many interfaces - like Access -
won't like to see a primary key that could change it value. But even if you
take out such interfaces out of the equation, the use of a surrogate key for
all tables reveals itself to be advantageous in many database problems. For
example, if you want to add a log of all changes to a table, it's much more
easier to design it if the table use a surrogate key for its primary key
than a natural key or a composite key.

Personally, I stopped using natural keys and composite keys many years ago
and probably that something like half of my problems with the design of
databases have vanished with them. On these occasions when I was called to
work on a problematic database, chances was much higher to see that the
problems were associated with the use of natural keys and/or composite keys
than with the use of a surrogate keys and the solutions were usually much
more complicated to solve in the first case than in the second case.

Also, I've remember some peoples who have done like me and have stopped
using natural and composite keys in favor of the exclusive use of surrogate
keys but I don't remember anyone doing the opposite; ie. going from the use
of surrogate keys to the use of natural and composite keys.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


<CDMAP...@fortunejames.com> wrote in message
news:a12c7757-aea7-4d11...@n20g2000hsh.googlegroups.com...

Brian Selzer

unread,
Jan 26, 2008, 3:45:44 AM1/26/08
to

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:uTvWO%23%23XIH...@TK2MSFTNGP04.phx.gbl...

> To that, I would add that the increased simplicity of using a surrogate
> (or artificial or autonumber) key as the primary key in place of a
> composite key is only half their advantage.
>
> The biggest problem that I have with composite keys is that they share the
> same fundamental problem as natural keys: using them as the primary key is
> allowing the fact that a primary key can change its value over time.
> IMHO, a primary key should never be allowed to change its value once it
> has been created; a assumption which will forbid the use of a composite
> key in many cases. (Of course, if you don't mind to see a primary key
> changing its value after its creation then you are not concerned by this
> argument.).
>

This argument has an inherent fallacy in it. Just because a key is composed
from multiple columns doesn't necessarily mean that its values can be
different in different database states. For example, in an Inventory table
that has the key, {ItemKey, WarehouseKey}, with references to an Item table
and a Warehouse table respectively, the combination values that comprise
each key value can never change from database state to database state. A
particular combination of values identifies a particular individual in the
Universe of Discourse in /every/ database state in which it appears. It can
/never/ identify any other individual. Therefore, it should be obvious that
adding an additional autonumber primary key in this instance would be
superfluous, since each {ItemKey, WarehouseKey} combination already rigidly
designates a distinct individual in the Universe of Discourse.

The same can be said for many natural keys. For example, suppose you have a
table, Queue, that has an integer key, {Position}. Each value for Position
rigidly designates a distinct individual in the Universe of Discourse (3
always means "third in line" in any database state in which there are 3 or
more elements), so therefore there is no need for an additional autonumber
primary key.

Roy Hann

unread,
Jan 26, 2008, 5:08:27 AM1/26/08
to
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:uTvWO%23%23XIH...@TK2MSFTNGP04.phx.gbl...
> To that, I would add that the increased simplicity of using a surrogate
> (or artificial or autonumber) key as the primary key in place of a
> composite key is only half their advantage.
>
> The biggest problem that I have with composite keys is that they share the
> same fundamental problem as natural keys: using them as the primary key is
> allowing the fact that a primary key can change its value over time.
> IMHO, a primary key should never be allowed to change its value once it
> has been created; a assumption which will forbid the use of a composite
> key in many cases. (Of course, if you don't mind to see a primary key
> changing its value after its creation then you are not concerned by this
> argument.).

I have decided not to respond to this post in detail because there isn't a
single point it makes that I agree with (as stated). I really don't know
where to start. One specific comment I will make is that my progression has
been the opposite of yours. I once used synthetic keys everywhere, but now
try to limit my use of them, with wholly beneficial effects. That may be
why I write about this with the fervor of a born-again convert.

I would have a lot more sympathy for these kinds of claims if the people
making them would give any hint that they know what the alternatives are,
and why their solutions make sense within application development tools.
For example, I don't think I've ever seen anyone enthusing about the liberal
use of synthetic keys who also noted that they are aware of the possibility
of declaring a foreign key constraint WITH ON UPDATE CASCADE. If you can
persuade me you've looked at it and had to reject for reasons X, Y, and Z, I
can respect that. Or tell me you know about it but your particular product
doesn't support it and I can respect that. Or tell me that you understand
that the DBMS handles the problem almost trivially but the application
development tools make you write extra code and I can respect that.

And what is all this tripe about composite keys making the SQL more complex?
If I bodge up my tables with a spurious third synthetic key (skey) so that
instead of writing:

select i.description, b.cause_of_damage
from orderitems i left join breakages b
using (ordernr,itemnr)

I can instead write:

select i.description, b.cause_of_damage
from orderitems i left join breakages b
on i.skey = b.skey

How much easier is THAT?? And at what cost?

If you don't convince me that you properly understand the problems, and
crucially, where the problems *really* lie, then you aren't going to
convince me that your solutions are anything but cut-and-paste rote-learned
hackery that seems elegant/sensible only to those with limited knowledge of
very limited products. You have to establish that you are credible.
Merely claiming years and years of experience (as others have) could just
mean they've been successfully getting away with being incompetent--and
goodness knows, that happens, so they won't get the benefit of the doubt.

Roy


Neil

unread,
Jan 26, 2008, 5:57:14 AM1/26/08
to
Bob,

Here's a programming tip for you: prozac.


"Bob Badour" <bba...@pei.sympatico.ca> wrote in message
news:479941ba$0$4039$9a56...@news.aliant.net...

Neil

unread,
Jan 26, 2008, 6:00:06 AM1/26/08
to

"Jamie Collins" <jamiec...@xsmail.com> wrote in message
news:08ac2bd3-dcb5-47d4...@c23g2000hsa.googlegroups.com...


OK, I'll rephrase:

"That makes sense, about the PK coming in handy to refer spearately to the

junction table, if that situation exists."

Better? :-)


Neil

unread,
Jan 26, 2008, 6:00:43 AM1/26/08
to

"Larry Daugherty" <Larry.NoSpa...@verizon.net> wrote in message
news:urlnw2uX...@TK2MSFTNGP04.phx.gbl...

> In the meantime OP is probably trying to hide the matches with which
> he started the fires....
>

Indeed. :-|


David Cressey

unread,
Jan 26, 2008, 7:26:13 AM1/26/08
to

<CDMAP...@fortunejames.com> wrote in message
news:a12c7757-aea7-4d11...@n20g2000hsh.googlegroups.com...
On Jan 25, 9:12 am, Jamie Collins <jamiecoll...@xsmail.com> wrote:
(quote)

What part of simpler don't you understand :-). Only one expression in
the ON is simpler. Needing less indexes is simpler. Not having to
look for your multi-key fields is easier, although your point that
Relationships can handle that is valid. If the AutoNumber key has a
one-to-one relationship with the multi-key fields then it's fine to
use it. There's no down side that I can see. I also like to rely on
coding to detect inconsistent data rather than on error trapping, so I
have to check the multi-key values anyway before adding a new record.
I think that your idea about enforcing constraints at both the table
level and in code is an excellent idea. The OP wanted to know what
people did and why. I still don't see any reason put forward for me
to change to a multi-field key. Are totals queries easier when multi-
field keys are used? BTW, "reduced the amount of denormalization"
works just as well. Real databases experience denormalizing
influences.

(end quote)

Simplicity is in the eye of the beholder.

I think it's simpler to rely on constraints enforced by the DBMS to prevent
duplicate entries
than it is to write code to accomplish the same thing.

When you want to delete an entry form a junction table, you almost always
know the two FKs that uniquely determine the entry to be deleted. You
almost never know the value of the superflous surrogate key. So it's simple
to use the two FK's as the criterion for deletion than it is to look up the
ID field, and then use that as the basis for deletion.

The above comment depends entirely on how you go about organizing you code.
I like to keep my code simple. At least "simple" in my own eyes.

The use of multi-key fields in star schemas doesn't make individual queries
any simpler. But it expands by orders of magnitude the number of different
combinations that can be used as selection criteria when computing totals or
other aggregates. This makes the entire system simpler, on a lerger scale.

I realize that star schema discussions may be out of place in MS access
newsgroups. The same is true in c.d.t. There is almost nothing of
theoretical interest in star schemas.


Bob Badour

unread,
Jan 26, 2008, 11:07:29 AM1/26/08
to
Roy Hann wrote:

> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
> wrote in message news:uTvWO%23%23XIH...@TK2MSFTNGP04.phx.gbl...
>
>>To that, I would add that the increased simplicity of using a surrogate
>>(or artificial or autonumber) key as the primary key in place of a
>>composite key is only half their advantage.
>>
>>The biggest problem that I have with composite keys is that they share the
>>same fundamental problem as natural keys: using them as the primary key is
>>allowing the fact that a primary key can change its value over time.
>>IMHO, a primary key should never be allowed to change its value once it
>>has been created; a assumption which will forbid the use of a composite
>>key in many cases. (Of course, if you don't mind to see a primary key
>>changing its value after its creation then you are not concerned by this
>>argument.).
>
>
> I have decided not to respond to this post in detail because there isn't a
> single point it makes that I agree with (as stated). I really don't know
> where to start.

That, in a nutshell, is Date's _Principle of Incoherence_.

I have found some people can work for 10 years and get a year's
experience 10 times.

Bob Badour

unread,
Jan 26, 2008, 11:58:23 AM1/26/08
to
Hi Sylvain,

First, let me thank you for being so kind as to volunteer the
information that you are a Most Vociferous Person (MVP). It does a fair
service to the world when the self-aggrandizing ignorants self-declare
that information.

Sylvain Lafontaine wrote:

> To that, I would add that the increased simplicity of using a surrogate (or
> artificial or autonumber) key as the primary key in place of a composite key
> is only half their advantage.

At this point, a prudent man would Plonk! you while mentally citing
Date's _Principle of Incoherence_. Never the prudent man, instead, I
observe the absurdity of your suggestion that adding features,
structures or attributes increases simplicity. What nonsense!


> The biggest problem that I have with composite keys is that they share the
> same fundamental problem as natural keys: using them as the primary key is
> allowing the fact that a primary key can change its value over time. IMHO,
> a primary key should never be allowed to change its value once it has been
> created; a assumption which will forbid the use of a composite key in many
> cases.

I find your absolutism foolish suggesting ignorance and/or stupidity.

The design criteria for keys are: uniqueness, irreducibility,
simplicity, stability and familiarity (in no particular order). If any
criterion is absolute, it is uniqueness not stability.


(Of course, if you don't mind to see a primary key changing its
> value after its creation then you are not concerned by this argument.).
>
> This is not only a theoritical argument as many interfaces - like Access -
> won't like to see a primary key that could change it value.

It is not a theoretical argument at all. You simply regurgitate
ignorance and stupidity.

[remaining nonsense snipped]

Plonk!

Bob Badour

unread,
Jan 26, 2008, 12:05:12 PM1/26/08
to
David Cressey wrote:

> <CDMAP...@fortunejames.com> wrote in message
> news:a12c7757-aea7-4d11...@n20g2000hsh.googlegroups.com...
> On Jan 25, 9:12 am, Jamie Collins <jamiecoll...@xsmail.com> wrote:
> (quote)
> What part of simpler don't you understand :-). Only one expression in
> the ON is simpler. Needing less indexes is simpler. Not having to
> look for your multi-key fields is easier, although your point that
> Relationships can handle that is valid. If the AutoNumber key has a
> one-to-one relationship with the multi-key fields then it's fine to
> use it. There's no down side that I can see. I also like to rely on
> coding to detect inconsistent data rather than on error trapping, so I
> have to check the multi-key values anyway before adding a new record.
> I think that your idea about enforcing constraints at both the table
> level and in code is an excellent idea. The OP wanted to know what
> people did and why. I still don't see any reason put forward for me
> to change to a multi-field key. Are totals queries easier when multi-
> field keys are used? BTW, "reduced the amount of denormalization"
> works just as well. Real databases experience denormalizing
> influences.
>
> (end quote)
>
> Simplicity is in the eye of the beholder.

I tend to disagree. I suspect one can quantify simplicity and complexity.


> I think it's simpler to rely on constraints enforced by the DBMS to prevent
> duplicate entries
> than it is to write code to accomplish the same thing.

Using the dbms uses fewer tools, fewer concepts, fewer computational
models, fewer structures, fewer machines. I suggest the observed
simplicity is more than a matter of perspective or opinion.

[further demonstrations of simplicity snipped]

Marshall

unread,
Jan 26, 2008, 2:48:16 PM1/26/08
to
On Jan 26, 4:26 am, "David Cressey" <cresse...@verizon.net> wrote:
>
> When you want to delete an entry form a junction table, you almost always
> know the two FKs that uniquely determine the entry to be deleted. You
> almost never know the value of the superflous surrogate key. So it's simple
> to use the two FK's as the criterion for deletion than it is to look up the
> ID field, and then use that as the basis for deletion.

Yes, exactly.

One of the greatest benefits, and one of the fundamental
differences between how SQL treats data and how
(most) conventional programming languages treat data
is that in SQL we specify data by its value, instead of by
location. I often observe that superfluous keys in the field
are an attempt to make SQL data have an address, to
make it behave the way the programmer's mental model
(perhaps influenced by years of using pointers) does.


Marshall

Sylvain Lafontaine fill the blanks, no spam please

unread,
Jan 26, 2008, 6:38:55 PM1/26/08
to
Your argument about the use of a DRI WITH ON UPDATE CASCADE is an
interesting argument and one that come back often; however it's not a silver
buller. First of all, it's another level of complexity that you must add to
the design of your database; ie, you must make sure that they are all there
and no one is missing. Second, this DRI cannot be used with cyclic
relationship with SQL-Server but with Oracle, you can. (From your example,
I believe that you are working with Oracle). On SQL-Server, you must use
triggers to implement such a feature when there is a cyclic relationship.
Of course, when you are dealing with tens and hundreds of relationships,
this can quickly translate into a nightmare. There is also the qestion of
the diminution of performance and of general design: when you have to update
multiples records on multiple tables for what should be the change of a
single value in a single table make it hard to believe that this is a proper
normalized database design and this situation quickly worsen if you have to
take into account the correspondance with backups, reports and linked
databases; all systems for which there is no automatic DRI.

But why make it simpler when you can make it harder?

Finally, I don't understand your example at all. You are introducing us to
the NATURAL JOIN and USING statement that have been introduced by Oracle in
its 9i version (also in MySQL and Postgres, I believe) but I fail to see
what this has to do with the subject of this thread; the use of a separate
PK in a junction table and its highly related topic, ie. the use of natural
keys versus the use of surrogate keys. There is no relationship at all
between a NATURAL JOIN and a natural key and the Natural Join can be used as
easily with a surrogate key than with a natural key. The only thing that is
important with the Natural Join is the name of the key. (BTW, if you were
to ask me what I'm thinking about this little monstruosity, I would tell you
that this is a perfect example of a Pandora box.).

And finally, a for your request of asking me to convince you that I'm
properly understand the problem here of to etablish that I'm credible: I can
tell you that I have absolutely no intention of doing it and that I have
absolutely no interest at all about what you are thinking of me. The only
things that are of interest to me are the arguments that I'm seeing posted
here - whatever the people who might write them - but for someone who has
just make a confusion between a natural key and the NATURAL JOIN, asking for
such a thing make it looks very strange.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC

E-mail: sylvain aei ca (fill the blanks, no spam please)


"Roy Hann" <spec...@processed.almost.meat> wrote in message
news:w5adnaS22JoBmwba...@pipex.net...

James A. Fortune

unread,
Jan 26, 2008, 9:09:57 PM1/26/08
to

Personally, I don't take the natural keys out either, so they can still
be used for the deletion. The thought of giving the SQL data an address
and following a programmer's mental model did not enter into my thinking
at all. I am not trying to give the data an order either. You've been
listening to Celko too much. Because of his overall manner, which I
find quite offensive, I don't even want to listen to him when he's right
:-). Is the AutoNumber primary key a denormalization of the schema?
Yes. Is it added for a reason? Yes again. I'm still waiting for a
cogent reason for me to go to using natural keys.

James A. Fortune
MPAP...@FortuneJames.com

JOG

unread,
Jan 26, 2008, 9:35:33 PM1/26/08
to
On Jan 27, 2:09 am, "James A. Fortune" <MPAPos...@FortuneJames.com>
wrote:

* Artificial keys allow you to enter the exact same statement of fact
twice. This would simply be nonsense.
* Artificial keys allows a tuple at t1 and a tuple at t2 to be
corresponded to each other, even if they don't have a _single_
attribute from the real world in common. This would also simply be
nonsense.
* Referencing an artificial key in a child table can complicates
queries - and not just with a longer restrict clause, but with a whole
extra join that may well have been unrequired if a natural key had
been used.

So not one, but three cogent reasons of the top of my head. I wouldn't
say there are never cases when an artificial key is useful, but they
certainly shouldn't be hidden, and adding them blindly to every
relation is surely just a bit silly. Regards, J.

>
> James A. Fortune
> MPAPos...@FortuneJames.com

James A. Fortune

unread,
Jan 26, 2008, 10:06:39 PM1/26/08
to

Access programmers use forms to interact with the data. If I follow
Jamie's advice and constrain the data at both the table level and in
code, then your points make more sense. Right now, they're just
arguments for me not to constrain the data at the table level because
the reasons you gave might make natural keys preferable in that
situation :-).


> * Referencing an artificial key in a child table can complicates
> queries - and not just with a longer restrict clause, but with a whole
> extra join that may well have been unrequired if a natural key had
> been used.

I don't agree with that point. The child table can contain the
AutoNumber primary key from the main table as a foreign key if desired.
I don't see how using the natural key fields requires less joins than
that. Maybe an example would help me understand what you mean.

>
> So not one, but three cogent reasons of the top of my head. I wouldn't
> say there are never cases when an artificial key is useful, but they
> certainly shouldn't be hidden, and adding them blindly to every
> relation is surely just a bit silly. Regards, J.

Did I imply that that's what I do?

James A. Fortune
MPAP...@FortuneJames.com


Bob Badour

unread,
Jan 26, 2008, 10:16:49 PM1/26/08
to
James A. Fortune wrote:

So, you object to Celko's style but consider him right?!? That's a new
one. ::rolls eyes::


Is the AutoNumber primary key a denormalization of the schema?
> Yes.

You are an ignoramus. You don't even have a clue what normalization is.
The addition of an attribute to act as a simple, stable key does not
affect the normal form in any way shape or manner.


Is it added for a reason? Yes again. I'm still waiting for a
> cogent reason for me to go to using natural keys.

It's the familiarity, stupid. The design criteria for keys are (and I
repeat): uniqueness, irreducibility, stability, simplicity and
familiarity (in no particular order.)

Brian Selzer

unread,
Jan 26, 2008, 11:35:19 PM1/26/08
to

"JOG" <j...@cs.nott.ac.uk> wrote in message
news:274f1803-9fe8-4801...@i72g2000hsd.googlegroups.com...

Not exactly. Artificial key values are simply names assigned to individuals
in the Universe of Discourse. I would think that it should be possible to
have many different names for the same thing: considering the fact that
there are a great many different languages, there must therefore be a great
many words for each thing.

> * Artificial keys allows a tuple at t1 and a tuple at t2 to be
> corresponded to each other, even if they don't have a _single_
> attribute from the real world in common. This would also simply be
> nonsense.

I wouldn't call it nonsense. It is not necessary that every property that
an individual exemplifies be represented in the database--only those
properties that are relevant to the problem at hand need be included. In
that event, if a particular individual is assigned a name at t1, and then if
the values for all of the properties that are relevant to the problem at
hand at t1 are compared to those from the individual with the same name at
t2, it is possible for all of those properties to be different. That isn't
nonsense, it just is, given the inherent incompleteness of the information
in the database.

> * Referencing an artificial key in a child table can complicates
> queries - and not just with a longer restrict clause, but with a whole
> extra join that may well have been unrequired if a natural key had
> been used.
>

You left one out. In a table that has multiple natural keys, when an
artificial key is added, which key values are its values surrogates for?

Brian Selzer

unread,
Jan 27, 2008, 12:39:55 AM1/27/08
to

"James A. Fortune" <MPAP...@FortuneJames.com> wrote in message
news:%23xDvuHJ...@TK2MSFTNGP06.phx.gbl...

Well, that's just dumb. Checks in code can reduce database round-trips, and
therefore can improve performance, but are not and cannot be a substitute
for constraints on the tables. It is the constraints on the tables that
keeps garbage out of the database.

>
>> * Referencing an artificial key in a child table can complicates
>> queries - and not just with a longer restrict clause, but with a whole
>> extra join that may well have been unrequired if a natural key had
>> been used.
>
> I don't agree with that point. The child table can contain the AutoNumber
> primary key from the main table as a foreign key if desired. I don't see
> how using the natural key fields requires less joins than that. Maybe an
> example would help me understand what you mean.
>

An extra join may be needed if the natural key from the parent table is used
in a restrict clause. If all you have is the artificial key from the parent
table, then you have to join in order to access the natural key columns.
With natural keys, the natural key values from the parent table also appear
in the child table, so there isn't any need to join. Bottom line: joins of
artificial keys are typically faster than joins of natural keys due to the
size of the comparands, but with natural keys, fewer joins may be needed..

CDMAP...@fortunejames.com

unread,
Jan 27, 2008, 1:01:08 AM1/27/08
to
On Jan 27, 12:39 am, "Brian Selzer" <br...@selzer-software.com> wrote:
> "James A. Fortune" <MPAPos...@FortuneJames.com> wrote in messagenews:%

> > Access programmers use forms to interact with the data.  If I follow
> > Jamie's advice and constrain the data at both the table level and in code,
> > then your points make more sense.  Right now, they're just arguments for
> > me not to constrain the data at the table level because the reasons you
> > gave might make natural keys preferable in that situation :-).
>
> Well, that's just dumb.  Checks in code can reduce database round-trips, and
> therefore can improve performance, but are not and cannot be a substitute
> for constraints on the tables.  It is the constraints on the tables that
> keeps garbage out of the database.

If the users only access the tables through forms, conforming to best
practices in Access, how are they going to get garbage into the
tables? Now if you're trying to keep Jamie and his Excel SQL out of
your database, that's another story :-).

> >> * Referencing an artificial key in a child table can complicates
> >> queries - and not just with a longer restrict clause, but with a whole
> >> extra join that may well have been unrequired if a natural key had
> >> been used.
>
> > I don't agree with that point.  The child table can contain the AutoNumber
> > primary key from the main table as a foreign key if desired. I don't see
> > how using the natural key fields requires less joins than that.  Maybe an
> > example would help me understand what you mean.
>
> An extra join may be needed if the natural key from the parent table is used
> in a restrict clause.  If all you have is the artificial key from the parent
> table, then you have to join in order to access the natural key columns.
> With natural keys, the natural key values from the parent table also appear
> in the child table, so there isn't any need to join.  Bottom line: joins of
> artificial keys are typically faster than joins of natural keys due to the
> size of the comparands, but with natural keys, fewer joins may be needed..

If you're planning on using a natural key column in the child table as
part of a join then doesn't it make sense to include that field in the
child table?

Still waiting...

James A. Fortune
CDMAP...@FortuneJames.com

Brian Selzer

unread,
Jan 27, 2008, 2:13:11 AM1/27/08
to

<CDMAP...@fortunejames.com> wrote in message
news:db4e7666-f9ef-4c72...@k39g2000hsf.googlegroups.com...

On Jan 27, 12:39 am, "Brian Selzer" <br...@selzer-software.com> wrote:
> "James A. Fortune" <MPAPos...@FortuneJames.com> wrote in messagenews:%

> > Access programmers use forms to interact with the data. If I follow
> > Jamie's advice and constrain the data at both the table level and in
> > code,
> > then your points make more sense. Right now, they're just arguments for
> > me not to constrain the data at the table level because the reasons you
> > gave might make natural keys preferable in that situation :-).
>
> Well, that's just dumb. Checks in code can reduce database round-trips,
> and
> therefore can improve performance, but are not and cannot be a substitute
> for constraints on the tables. It is the constraints on the tables that
> keeps garbage out of the database.

>>>>>
If the users only access the tables through forms, conforming to best
practices in Access, how are they going to get garbage into the
tables? Now if you're trying to keep Jamie and his Excel SQL out of
your database, that's another story :-).
<<<<<

There can be several forms that access the same table, so you would have to
duplicate the code behind each form that accesses a table, or you can get
garbage into the database.

> >> * Referencing an artificial key in a child table can complicates
> >> queries - and not just with a longer restrict clause, but with a whole
> >> extra join that may well have been unrequired if a natural key had
> >> been used.
>
> > I don't agree with that point. The child table can contain the
> > AutoNumber
> > primary key from the main table as a foreign key if desired. I don't see
> > how using the natural key fields requires less joins than that. Maybe an
> > example would help me understand what you mean.
>
> An extra join may be needed if the natural key from the parent table is
> used
> in a restrict clause. If all you have is the artificial key from the
> parent
> table, then you have to join in order to access the natural key columns.
> With natural keys, the natural key values from the parent table also
> appear
> in the child table, so there isn't any need to join. Bottom line: joins of
> artificial keys are typically faster than joins of natural keys due to the
> size of the comparands, but with natural keys, fewer joins may be needed..

If you're planning on using a natural key column in the child table as
part of a join then doesn't it make sense to include that field in the
child table?

Still waiting...


A typical schema with artificial keys:

Customer {CustomerKey, CustomerNo, ...}
Key {CustomerKey}, Key {CustomerNo}

Item {ItemKey, ItemNo, ...}
Key {ItemKey}, Key {ItemNo}

CI {CustomerItemKey, CustomerKey, ItemKey, CustomerItemNo}
Key {CustomerItemKey}, Key {CustomerKey, ItemKey}
CI[ItemKey] IN Item[ItemKey]
CI[CustomerKey] IN Customer[CustomerKey]

SOLine {SOLineKey, SOKey, SOLineNo, CustomerItemKey, Quantity, Price}
Key {SOLineKey}, Key {SOKey, SOLineNo}
SOLine[CustomerItemKey] IN CI[CustomerItemKey]


A typical schema with natural keys

Customer {CustomerNo, ...}
Key {CustomerNo}

Item {ItemNo, ...}
Key {ItemNo}

CI {CustomerNo, ItemNo, CustomerItemNo}
KEY {CustomerNo, ItemNo}
CI[CustomerNo] IN Customer[CustomerNo]
CI[ItemNo] IN Item[ItemNo]

SOLine {SO#, SOLineNo, CustomerNo, ItemNo, Quantity, Price}
SOLine[CustomerNo, ItemNo] IN CI[CustomerNo, ItemNo]


Now write a query that returns how many of item '12345' were sold to
customer '4321'

It should be obvious that with the natural keys, no joins are
necessary--it's just a simple select from SOLine since all of the
information is actually /in/ SOLine; whereas, with the artifical keys,
several joins are required because in order to query by item number and
customer number, SOLine must be joined to CI which must then be joined to
Customer and Item.

Roy Hann

unread,
Jan 27, 2008, 6:53:55 AM1/27/08
to
"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:%23zkseSH...@TK2MSFTNGP05.phx.gbl...

> Your argument about the use of a DRI WITH ON UPDATE CASCADE is an
> interesting argument and one that come back often;

Really? I can put my hand on my heart and say I've never seen anyone
suggest it when they cross-post to comp.databases.theory. I don't doubt it
has come up, but I do doubt it is often.

> however it's not a silver buller.

I implicitly allowed that it is not a silver bullet by actually suggesting
the kinds of reasons one might exclude it.

> First of all, it's another level of complexity that you must add to the
> design of your database; ie, you must make sure that they are all there
> and no one is missing.

Of course one must make sure "they are all there"; you are absolutely right.
But it absurd to suggest doing that is "another level of complexity". It is
trivial to do it, and trivial to check that you've done it by querying the
DB catalogs.

> Second, this DRI cannot be used with cyclic relationship with SQL-Server
> but with Oracle, you can. (From your example, I believe that you are
> working with Oracle).

I'm not. But the fact that you are distinguishing the behaviour of
particular products gets close to the real problem. The real problem is
that the products we use are all more or less defective, but instead of
clamouring to have them fixed (by establishing suitable standards and
following them) we promote workarounds as if they are actually desirable. I
have no problem at all with people describing workarounds for defects but I
have a major problem when it is implied that the workaround is some kind of
best-practice or even desirable.

> On SQL-Server, you must use triggers to implement such a feature when
> there is a cyclic relationship. Of course, when you are dealing with tens
> and hundreds of relationships, this can quickly translate into a
> nightmare. There is also the qestion of the diminution of performance and
> of general design: when you have to update multiples records on multiple
> tables for what should be the change of a single value in a single table
> make it hard to believe that this is a proper normalized database design

First of all, updates to keys should be very rare. A fundamental property
of a well-chosen key is that it is reasonably stable. Imposing the little
self-discipline required to make sure you choose stable keys is
inconsequential when compared to the overall database design effort.

Secondly, even having to update hundreds of tables to amend a key is only
about the same effort required to insert all those rows in the first place.
Against the background of work the system does all the time, that will be
inconsequential. (Of course, if you unwisely choose a key that is not
stable, your argument would be more nearly correct. But that is why the
long-standing advice has been to avoid keys that are not stable.)

> and this situation quickly worsen if you have to take into account the
> correspondance with backups, reports and linked databases; all systems for
> which there is no automatic DRI.

I don't entirely agree with all these reasons, but as I said in my earlier
post, there often *are* good reasons why one might not be able to use ON
UPDATE CASCADE in a particular product and I will take your word for it that
these reasons apply with the product you use. My challenge to you was to
signal you know that, and you have now done so.

> But why make it simpler when you can make it harder?

Hm.

> Finally, I don't understand your example at all. You are introducing us
> to the NATURAL JOIN and USING statement that have been introduced by
> Oracle in its 9i version (also in MySQL and Postgres, I believe) but I
> fail to see what this has to do with the subject of this thread; the use
> of a separate PK in a junction table and its highly related topic, ie. the
> use of natural keys versus the use of surrogate keys. There is no
> relationship at all between a NATURAL JOIN and a natural key and the
> Natural Join can be used as easily with a surrogate key than with a
> natural key.

I am confused about your argument here. I was giving counter-example to
disprove the claim that composite keys make the SQL code more complex, which
was being presented as an argument to introduce yet more, spurious,
synthetic/surrogate keys. In fact if you read my example carefully, you
will have seen that I talked explicitly about *three* synthetic keys because
I aware I was already using two (order number and item number).

> The only thing that is important with the Natural Join is the name of the
> key. (BTW, if you were to ask me what I'm thinking about this little
> monstruosity, I would tell you that this is a perfect example of a Pandora
> box.).

Well, I have to admit that I'm not over-fond of relying on names to imply
that two columns represent the same thing, so in fact I never use that
syntax. I do prefer to assert all the conditions on all the key columns
explicitly and I just don't notice the few extra keystrokes when it's a
composite key. But on the other hand, I find it monstrous when I see two or
more distinct names for colunms that do represent the same thing.

> And finally, a for your request of asking me to convince you that I'm
> properly understand the problem here of to etablish that I'm credible: I
> can tell you that I have absolutely no intention of doing it

And yet you have greatly increased your credibility with this post. I still
disagree with what you've said, but I can see you know more about what
you're talking about than it seemed before. Before, I thought you were
ignorant and uncurious. Now I see you are merely wrong. :-)

> and that I have absolutely no interest at all about what you are thinking
> of me.

That's very healthy. You shouldn't.

>The only things that are of interest to me are the arguments that I'm
>seeing posted here - whatever the people who might write them - but for
>someone who has just make a confusion between a natural key and the NATURAL
>JOIN, asking for such a thing make it looks very strange.

I make no such confusion, and a quick glance at my earlier post will confirm
it.

Roy


Bob Badour

unread,
Jan 27, 2008, 8:16:08 AM1/27/08
to
Roy Hann wrote:
> "Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
> wrote in message news:%23zkseSH...@TK2MSFTNGP05.phx.gbl...

[snip]

>>And finally, a for your request of asking me to convince you that I'm
>>properly understand the problem here of to etablish that I'm credible: I
>>can tell you that I have absolutely no intention of doing it
>
> And yet you have greatly increased your credibility with this post.

I disagree. You give him too much credit.


I still
> disagree with what you've said, but I can see you know more about what
> you're talking about than it seemed before. Before, I thought you were
> ignorant and uncurious. Now I see you are merely wrong. :-)

I suspect that is wishful thinking on your part.

David Cressey

unread,
Jan 27, 2008, 8:36:20 AM1/27/08
to

"Marshall" <marshal...@gmail.com> wrote in message
news:4fad9541-6eda-4ceb...@z17g2000hsg.googlegroups.com...


> an attempt to make SQL data have an address

Exactly. Literally hundreds of attempts to sell snake oil in c.d.t. can be
reduced to precisely this statement. We've all said variations of the
above, but I've never seen it put so succintly.

As far as the MS Access newsgroups that this discussion is posted to, I
can't speak to how well your summary extends to their mental model. But
many of them seem to write as if
contents as determined by address were the fundamental paradigm of data.

David Cressey

unread,
Jan 27, 2008, 8:46:41 AM1/27/08
to

"James A. Fortune" <MPAP...@FortuneJames.com> wrote in message
news:%23y9kCoI...@TK2MSFTNGP03.phx.gbl...

> Personally, I don't take the natural keys out either, so they can still
> be used for the deletion.

There are really two issues being discussed in a single discussion here.

The issue of synthetic keys versus natural keys is one issue. The issue of
a composite PK in a junction table, made up of FKs, versus a new simple key
is a separable issue.

Please note that, if the two FKs under discussion both reference synthetic
PKs, all of your arguments concerning the problems of dealing with natural
keys become moot.

If we have three tables, Students, Courses, and Enrollments, where
enrollments is a junction between Students and Courses, we could have a
synthetic key, StudentID for students, and a synthetic key, CourseID, for
Courses.

The question then remains which is simpler. To define enrollments with a
composite key
(StudentID, CourseID), or to define a new synthetic key, EnrollmentID.
Neither of these two solutions uses natural keys.

I prefer to se natural keys whenever possible, but I use synthetic keys
when natural ones just won't do. When do natural keys fail to do the job?
When the poeple who control them are mismanaging them.

David Cressey

unread,
Jan 27, 2008, 8:53:52 AM1/27/08
to

"Brian Selzer" <br...@selzer-software.com> wrote in message
news:MOUmj.1465$uE....@newssvr22.news.prodigy.net...

> Well, that's just dumb. Checks in code can reduce database round-trips,
and
> therefore can improve performance, but are not and cannot be a substitute
> for constraints on the tables. It is the constraints on the tables that
> keeps garbage out of the database.

The idea of keeping garbage out of the database takes on an entirely
different meaning if you are dealing with hundreds of programs written in
COBOL, Java, or anything in between accessing a single Oracle database on
the one hand. On the other hand, if you are a developer creating a self
contained MS Access database cum application (tables, queries, forms,
reports, modules, etc.) all in one file, the same issues arise, but they
are resolved quite differently.

I'm not saying either one is "right" or "wrong". I'm just suggesting why an
objection that makes perfect sense to you and me might be lost on the MS
Access community.

Rick Brandt

unread,
Jan 27, 2008, 9:18:16 AM1/27/08
to
David Cressey wrote:
> The idea of keeping garbage out of the database takes on an entirely
> different meaning if you are dealing with hundreds of programs
> written in COBOL, Java, or anything in between accessing a single
> Oracle database on the one hand. On the other hand, if you are a
> developer creating a self contained MS Access database cum
> application (tables, queries, forms, reports, modules, etc.) all in
> one file, the same issues arise, but they are resolved quite
> differently.
>
> I'm not saying either one is "right" or "wrong". I'm just suggesting
> why an objection that makes perfect sense to you and me might be lost
> on the MS Access community.
^
some of

I think if a thorough poll was done it would show that the majority of
professional Access developers (those that make their living at it) would agree
that data integrity rules should be enforced by the database engine wherever
that is possible.

The fact is that Access is a tool predominantly for *users*, not developers, and
Microsoft appears determined with each subsequent version to make that more the
case. The majority of changes make it easier to do things incorrectly because
that makes the program easier to use for people who have no idea what they are
doing. Since that group vastly outnumbers the other one can hardly argue with
their logic from a business standpoint.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com

JOG

unread,
Jan 27, 2008, 10:06:07 AM1/27/08
to
On Jan 27, 2:18 pm, "Rick Brandt" <rickbran...@hotmail.com> wrote:
> David Cressey wrote:
> > The idea of keeping garbage out of the database takes on an entirely
> > different meaning if you are dealing with hundreds of programs
> > written in COBOL, Java, or anything in between accessing a single
> > Oracle database on the one hand. On the other hand, if you are a
> > developer creating a self contained MS Access database cum
> > application (tables, queries, forms, reports, modules, etc.) all in
> > one file, the same issues arise, but they are resolved quite
> > differently.
>
> > I'm not saying either one is "right" or "wrong". I'm just suggesting
> > why an objection that makes perfect sense to you and me might be lost
> > on the MS Access community.
>
> ^
> some of
>
> I think if a thorough poll was done it would show that the majority of
> professional Access developers (those that make their living at it) would agree
> that data integrity rules should be enforced by the database engine wherever
> that is possible.

Well thank goodness for that! For a scary moment I though Sylvian's
views were representative of the access community as a whole, and that
you guys didn't think that data integrity should be enforced primarily
by the db engine.

>
> The fact is that Access is a tool predominantly for *users*, not developers, and
> Microsoft appears determined with each subsequent version to make that more the
> case. The majority of changes make it easier to do things incorrectly because
> that makes the program easier to use for people who have no idea what they are
> doing. Since that group vastly outnumbers the other one can hardly argue with
> their logic from a business standpoint.

My fear though is that many db developers cut their teeth using
Access. If bad practices are encouraged just because access doesn't
handle many concurent users, and tends to manage data where it's
unlikely one will hit the pitfalls that artificial keys can lay, when
developers graduate up to larger server systems they may well carry
those mistakes on with them.

I certainly don't think developers should excuse sloppy RDBMS design
just because they are using access (and of course I'm sure many of the
professionals here wouldn't dream of doing so, despite others
laxness).

JOG

unread,
Jan 27, 2008, 10:29:40 AM1/27/08
to
On Jan 27, 3:06 am, "James A. Fortune" <MPAPos...@FortuneJames.com>

I'd suggest you read Rick's comments James. To be honest, its database
101 really that shared databases should handle data integrity
centrally. But I'm glad you see the logic of not allowing duplicates,
etc
(I've encountered people who don't...)

>
> > * Referencing an artificial key in a child table can complicates
> > queries - and not just with a longer restrict clause, but with a whole
> > extra join that may well have been unrequired if a natural key had
> > been used.
>
> I don't agree with that point. The child table can contain the
> AutoNumber primary key from the main table as a foreign key if desired.
> I don't see how using the natural key fields requires less joins than
> that. Maybe an example would help me understand what you mean.

No probs, although off the top of my head its gonna be a bit
contrived. With an artificial key:

Marriages {id, husband, wife, date}
Kids_from_Marriage {from_id, name, birth}

A query that asks "fetch me all the children whose mother is x"
obviously requires an equijoin, matching Marriages.id and
Kids.from_id. However with the original natural keys:

Marriages {id, husband, wife, date}
Kids_from_Marriage {mother, father, name, birth}

The same query is a simple select. That certainly seems a lot less
complicated to me ;)

>
>
> > So not one, but three cogent reasons of the top of my head. I wouldn't
> > say there are never cases when an artificial key is useful, but they
> > certainly shouldn't be hidden, and adding them blindly to every
> > relation is surely just a bit silly. Regards, J.
>
> Did I imply that that's what I do?

Erm, thats the impression you seem to give. Tony Toes certainly stated
he encouraged blindly adding artificial keys to everything. However
with duplicates, the extra reason's that Brian has given, the above
examples and the recommendations from access pro's that you shouldn't
rely on code to maintain integrity, I hopefully can assume that you've
at least seen the strength of the arguments.

>
> James A. Fortune
> MPAPos...@FortuneJames.com

Marshall

unread,
Jan 27, 2008, 1:16:32 PM1/27/08
to
On Jan 26, 6:09 pm, "James A. Fortune" <MPAPos...@FortuneJames.com>
wrote:

> Marshall wrote:
> > On Jan 26, 4:26 am, "David Cressey" <cresse...@verizon.net> wrote:
>
> >>When you want to delete an entry form a junction table, you almost always
> >>know the two FKs that uniquely determine the entry to be deleted. You
> >>almost never know the value of the superflous surrogate key. So it's simple
> >>to use the two FK's as the criterion for deletion than it is to look up the
> >>ID field, and then use that as the basis for deletion.
>
> > Yes, exactly.
>
> > One of the greatest benefits, and one of the fundamental
> > differences between how SQL treats data and how
> > (most) conventional programming languages treat data
> > is that in SQL we specify data by its value, instead of by
> > location. I often observe that superfluous keys in the field
> > are an attempt to make SQL data have an address, to
> > make it behave the way the programmer's mental model
> > (perhaps influenced by years of using pointers) does.
>
> Personally, I don't take the natural keys out either, so they
> can still be used for the deletion.

Since natural keys are data that needs to be managed, this
is an unsurprising claim. I don't throw out the data I'm supposed
to be managing either. Also consider this thread is about junction
tables. Imagine what you would have left if you threw out the
natural key of a junction table: nothing! Just the capriciously
introduced surrogate key in a table by its lonesome self.

Perhaps I've just stumbled into a sanity check for table
design: every projection of a table should have a meaningful
predicate. (Do I hear JOG's ears pricking up?) In a junction
table in which a surrogate key has been introduced, what's
the meaning of the projection of the table over the s.k. column?
Oops!


> The thought of giving the SQL data an address and
> following a programmer's mental model did not enter
> into my thinking at all.

Your not being consciously aware of it doesn't mean
it didn't happen. The mind doesn't work like that.


> You've been listening to Celko too much.

Who? ;-)


Marshall

Marshall

unread,
Jan 27, 2008, 1:18:55 PM1/27/08
to
On Jan 26, 10:01 pm, CDMAPos...@fortunejames.com wrote:
>
> If the users only access the tables through forms, conforming to best
> practices in Access, how are they going to get garbage into the
> tables?

Users aren't the only ones who update tables.


Marshall

Marshall

unread,
Jan 27, 2008, 1:25:35 PM1/27/08
to
On Jan 26, 11:13 pm, "Brian Selzer" <br...@selzer-software.com> wrote:
>
> There can be several forms that access the same table, so you would have to
> duplicate the code behind each form that accesses a table, or you can get
> garbage into the database.

Right. And then you need to change a constraint, and you modify the
code and you remember to update three out of the four forms that
implement the check, and you get garbage in the database. Or
any of a number of other things that can go wrong.


Marshall

Marshall

unread,
Jan 27, 2008, 1:30:59 PM1/27/08
to
On Jan 27, 5:53 am, "David Cressey" <cresse...@verizon.net> wrote:
> "Brian Selzer" <br...@selzer-software.com> wrote in message
>
> > Well, that's just dumb. Checks in code can reduce database round-trips,
> and
> > therefore can improve performance, but are not and cannot be a substitute
> > for constraints on the tables. It is the constraints on the tables that
> > keeps garbage out of the database.
>
> The idea of keeping garbage out of the database takes on an entirely
> different meaning if you are dealing with hundreds of programs written in
> COBOL, Java, or anything in between accessing a single Oracle database on
> the one hand. On the other hand, if you are a developer creating a self
> contained MS Access database cum application (tables, queries, forms,
> reports, modules, etc.) all in one file, the same issues arise, but they
> are resolved quite differently.
>
> I'm not saying either one is "right" or "wrong". I'm just suggesting why an
> objection that makes perfect sense to you and me might be lost on the MS
> Access community.

There's another approach to enforcing constraints: just tell your
users not to do that. In the hierarchy of what works, it comes
below checks in client code, but above manually inserting
garbage at design-time. It also has the advantage of being
even lower performance overhead for the software. Note
that centrally enforced declarative integrity constraints
are an endpoint in this hierarchy.


Marshall

Brian Selzer

unread,
Jan 27, 2008, 1:56:52 PM1/27/08
to

"Marshall" <marshal...@gmail.com> wrote in message
news:24e63bab-1720-4762...@y5g2000hsf.googlegroups.com...

I think you're jumping the gun, Marshall. Since a surrogate key value is
just a name, what a projection over the s.k. column would leave you with is
a set of names, and the only meaning that can be derived from each element
is that there is an individual that has been so named and due to domain
closure that that individual actually exists.

Sylvain Lafontaine fill the blanks, no spam please

unread,
Jan 27, 2008, 2:23:06 PM1/27/08
to
>> Your argument about the use of a DRI WITH ON UPDATE CASCADE is an
>> interesting argument and one that come back often;
>
> Really? I can put my hand on my heart and say I've never seen anyone
> suggest it when they cross-post to comp.databases.theory. I don't doubt
> it has come up, but I do doubt it is often.

Oh, the word "often" is all relative here. Of course, in a newsgroup about
Access and/or SQL-Server, you won't see it coming very often because these
two databases don't offer support for DRI updating on cyclic relationships.
What you are more likely to see would be people complaining about the
absence of such support in SQL-Server. However, I suppose that many of
those peoples who are making this complaint have probably the use of natural
keys behind their mind (the other strong possibility beeing the use of some
form of replication); so this close the circle. I've also suppose that on
other newsgroups dedicated to systems like Oracle, the discussion about this
point is probably much more heated.

I should also add that if I remember correctly, this one was a feature that
has been promised to be released with SQL-Server 2000 but that it didn't
make the last cut and a lot of people were angry about that. Nowadays, in
regard to the next release of SQL-Server 2008, peoples seem to be more
interested with features such as the integration with .NET and other big
stuff like that than to know if Katmai will offer support for this or not.

> First of all, updates to keys should be very rare. A fundamental property
> of a well-chosen key is that it is reasonably stable. Imposing the little
> self-discipline required to make sure you choose stable keys is
> inconsequential when compared to the overall database design effort.

This is the big problem with natural keys. When the theory was first
elaborated, the point was that a natural key never change its value. That
was the point that was making the choice of a natural key on par with the
use of a surrogate key as the primary key of a table. However, like anyone
have discovered with experience, a natural key can change its value under a
set of various circonstances. One could argue that if a key can change its
value, than it's not a natural key but as you know, this argument bring
nothing in regard to help you choosing a natural key.

Now, how it's important the fact that the update to a key should be very
rare? To me, there is a big difference between 0 and 1 time but there is
not between 1 and 1 million times. If you have to put code in order to take
into account the fact that the key can change its value, it should be the
same code if the key change its value one single time for the life of the
database or multiple times each day. In many cases, you are even placed in
the situation where there is a strong possibility that the key will never
change its value a single time for the whole lifetime of the database but
that you must take into account the possibility that it might do so.

Of course, there are many possible solutions: put a lot of DRI/triggers and
other pieces of code; forbid any change (and make the clients unhappy on
many occasions); suggest to delete the records and recreate them from
scratch or even rebuild the whole database; etc.; etc. but why bother with
all these in the first place?

To me, the use of natural keys is like someone bringing me a box full of
Damocles' swords: he would usually tell me to be very careful when I will
put these on the ceiling. Later, when he will come back and see the empty
ceiling and ask me why, I would answer him that I've put the box in the
garbage bin but if he want them, he can bring the box home for free; at the
condition that I'll never see them again. The fact that some theorists like
these swords too is of no interest to me. If they like them, they too can
bring them home for free but at the same condition, that I'll never them
again.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)


"Roy Hann" <spec...@processed.almost.meat> wrote in message

news:HKqdneWeJ7ZO7QHa...@pipex.net...

Rob

unread,
Jan 27, 2008, 2:45:35 PM1/27/08
to
On Jan 22, 1:26 pm, "Neil" <nos...@nospam.net> wrote:
> Whenever I've created junction tables in the past, I always made the PK of
> the junction table the combined pks from the two other tables. Ex: Table1
> PK=A; Table2 PK=B; Junction table consists of two fields, A and B, which
> together comprise the PK for the junction table.
>
> However, I just came across some code in which the person created a junction
> table with a separate PK consisting of an autonumber field, and then the two
> fields.
>
> So I was wondering how others did junction tables -- with a standalone
> autonumber PK, or with a PK consisting of the PKs of the tables being
> joined? And, if a standalone PK, then why?
>
> Thanks!
>
> Neil

I don't claim to know more about db theory than the cdt regulars, or
to have more experience than the many practioners who have contributed
to this thread.

I do know that the debate over relationship representations has been
going on for years, neither side giving any ground. Some aspects of it
are never addressed. For example, making the two foreign keys in a
junction table a composite PRIMARY key prohibits NULL values from
either key, but declaring a separate surrogate primary key together
with a UNIQUE constraint on the two-foreign-key-composite-key does
allow NULL values for either (or both!). This can be useful for
representing unrelated entity tuples, either childless parents or
orphans.

Practioners in the audience may be interested in this page:

http://www.sfdbs.com/toplevel/fasttrack/fasttrack.shtml

of my website in which I describe an entirely new way to represent
relationships. Or this page:

http://www.sfdbs.com/solopages/relcardtypes.shtml

where the representational capabilities of this new representation
(called Aggregate-Link) are compared to the two more traditional
representations.

Please note, I am not suggesting the use of this representation for
conventional database design. Merely consider it new, and possibly
interesting. (It may not be possible to deploy Aggregate-Link in MS
Access.)

The theorists have already had a field day dumping on this new
representation in this thread:

http://groups.google.com/group/comp.databases.theory/browse_frm/thread/036514365a600841#

But most theorists seem to be immune to the practical considerations
of IT. In particular, they don't begin to understand that IT
employers' appreciation for Access is based on cost, not beauty.

Rob

David W. Fenton

unread,
Jan 27, 2008, 3:27:07 PM1/27/08
to
CDMAP...@fortunejames.com wrote in
news:db4e7666-f9ef-4c72...@k39g2000hsf.googlegroups.co
m:

> If the users only access the tables through forms, conforming to
> best practices in Access, how are they going to get garbage into
> the tables?

What if there's more than one application built on top of the
database?

I, too, agree that one should put as much of the data logic in the
back end as possible.

However, that doesn't mean I use natural keys very often. I'm
definitely opposed to compound keys for any table whose PK will be a
foreign key in another table. It causes myriad problems of all sorts
(been there, done that), and despite its being theoretically
correct, just doesn't work well in practice.

Just consider one scenario:

You need to build criteria for a query-by-form interface. That means
that to query on the PK of a table with a compound PK, you end up
needing to have multiple fields in your WHERE clause. And if you're
querying multiple records in the table with the compound PK, you'll
need a complex nested OR in your WHERE clause.

I know perfectly well that theoretically speaking you're not
supposed to let your application drive the design of your schema,
but this is a case where common sense tells me that following theory
leads to enormously difficult application logic problems.

Natural keys are great for tables with a single-column natural PK.

Otherwise, surrogate keys make building an application substantially
easier.

And, BTW, I would, of course, advocate that any natural key that is
not used as the PK should naturally have a unique index on it.

And any natural key that can't have a unique index (because some
fields need to be Null) was never a candidate for PK in the first
place, and would have to have had uniqueness enforced in the
application in some fashion anyway.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/

David W. Fenton

unread,
Jan 27, 2008, 3:33:13 PM1/27/08
to
JOG <j...@cs.nott.ac.uk> wrote in
news:c4699a61-e76f-4ff3...@e10g2000prf.googlegroups.co
m:

> I certainly don't think developers should excuse sloppy RDBMS
> design just because they are using access (and of course I'm sure
> many of the professionals here wouldn't dream of doing so, despite
> others laxness).

What *are* you talking about?

Any mistakes in schema design that you can make in Access, you can
make in any other RDBMS.

I would agree that there are many places that the wizards in Access
and the sample databases encourage sub-optimal practices. But most
professional developers aren't using either wizards or the sample
databases as their models for developing their own applications.

If your impression of Access comes from futzing with it for 10
minutes and from encountering kludged-together apps created by your
company receptionist, then you just haven't a clue what Access
offers, either as an application development platform or as a data
store (using its native Jet engine).

This is a schema question, and that is orthogonal to Access, because
Access is an application development platform. If you use Jet for
your data store, then Jet is relevant to the discussion. But you can
use any data store that offers an ISAM or ADO or ODBC drivers, and
that means all your schema issues are completely divorced from
Access itself.

That you can't seem to keep this distinction clear in your mentions
of Access demonstrates pretty clearly that you are completely
clueless about Access and really aren't in any position to be making
disparaging comments about it.

-CELKO-

unread,
Jan 27, 2008, 3:36:33 PM1/27/08
to
>> If I were a library lending 2 undiffentiatable copies of 1 book to the same person, I suppose I would need an Autonumber PK plus A BookID and BorrowerID. <<

No, you would fire your librarian for failure to keep an accession
number or copy number as part of the book's identifier. And the book
should be identified by an ISBN.


David W. Fenton

unread,
Jan 27, 2008, 3:39:50 PM1/27/08
to
JOG <j...@cs.nott.ac.uk> wrote in
news:5afa9a80-f1c5-4ede...@s12g2000prg.googlegroups.co
m:

> No probs, although off the top of my head its gonna be a bit
> contrived. With an artificial key:
>
> Marriages {id, husband, wife, date}
> Kids_from_Marriage {from_id, name, birth}
>
> A query that asks "fetch me all the children whose mother is x"
> obviously requires an equijoin, matching Marriages.id and
> Kids.from_id. However with the original natural keys:
>
> Marriages {id, husband, wife, date}
> Kids_from_Marriage {mother, father, name, birth}
>
> The same query is a simple select. That certainly seems a lot less
> complicated to me ;)

Assuming you've got some form of CASCADE UPDATE on your enforced
relationship, that will work.

But it's repeating a huge amount of data, and adding a bunch more
indexes to keep updated. Perhaps these are insignificant issues to
*you* and *your* apps, but my clients' apps (some using Jet, some
using SQL Server, some using MySQL) don't perform so well when you
add in all the overhead.

And it all leaves aside the question of how you know that
husband/wife/date is always going to be unique. I think that on any
given day in the US, there are plenty of marriages in which those
three values will be identical. You could add place. But then, in
large cities, that might not be enough. So use Postal Code in place
of place, and that might do the trick, although in large cities that
might not do it, either.

Given that I can foresee a reasonable possibility of a collision on
this candidate key as currently defined, I'd think long and hard on
whether to use it or not.

And it's one of the main problems any time you're storing data about
people in a data table -- you often lack pieces of the information,
and you run a high risk of collisions between people with the same
names.

And that fact of the real-world entities being modelled makes
finding a natural key that will work as a PK a very hard task.

David W. Fenton

unread,
Jan 27, 2008, 3:43:27 PM1/27/08
to
Marshall <marshal...@gmail.com> wrote in
news:24e63bab-1720-4762...@y5g2000hsf.googlegroups.com
:

> Since natural keys are data that needs to be managed, this
> is an unsurprising claim. I don't throw out the data I'm supposed
> to be managing either. Also consider this thread is about junction
> tables. Imagine what you would have left if you threw out the
> natural key of a junction table: nothing! Just the capriciously
> introduced surrogate key in a table by its lonesome self.
>
> Perhaps I've just stumbled into a sanity check for table
> design: every projection of a table should have a meaningful
> predicate. (Do I hear JOG's ears pricking up?) In a junction
> table in which a surrogate key has been introduced, what's
> the meaning of the projection of the table over the s.k. column?
> Oops!

Junction tables that:

1. include nothing but the foreign keys of the tables they are
joining,

AND

2. have no child tables

need not surrogate key.

Since I use surrogate keys in most of my schemas, most junction
tables are two-columns, and those two columns are the PK.

Once I did have a schema where there was a child table to the
junction table, and in that case, I wish I'd had a surrogate key (it
was a pure natural key design, actually, and the worst project I've
ever worked on; no one to blame but myself, as I designed the schema
from scratch), as it made it awfully difficult to work with that
table that was a child of the junction table.

David W. Fenton

unread,
Jan 27, 2008, 3:45:11 PM1/27/08
to
Rob <rmps...@gmail.com> wrote in
news:0a65204e-068c-4e77...@d70g2000hsb.googlegroups.co
m:

> I do know that the debate over relationship representations has
> been going on for years, neither side giving any ground. Some
> aspects of it are never addressed. For example, making the two
> foreign keys in a junction table a composite PRIMARY key prohibits
> NULL values from either key, but declaring a separate surrogate
> primary key together with a UNIQUE constraint on the
> two-foreign-key-composite-key does allow NULL values for either
> (or both!). This can be useful for representing unrelated entity
> tuples, either childless parents or orphans.

Er, why go to all that trouble? You can represent the same childless
parents by simply omitting a record in the junction table.

It is loading more messages.
0 new messages