PC Review


Reply
Thread Tools Rate Thread

Do I have to set the primary key to include primary key fields?

 
 
boooney
Guest
Posts: n/a
 
      14th Apr 2010
I have read that "in a junction table, you need to set the primary key to
include the primary key fields from the other two tables. "

If I do this, I keep getting the error message "the change you requested to
the table were not successful because they would create duplicate values in
the index, primary key, or relationship.

The only way I'm entering data is through a form based on a query which
automatically writes to all 3 tables (the junction and 2 parents) at once.

If I remove the primary keys in the junction tables, I no longer get the
error message. Am I going to regret this later?

Thanks.
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      14th Apr 2010
On Tue, 13 Apr 2010 17:46:01 -0700, boooney
<(E-Mail Removed)> wrote:

>I have read that "in a junction table, you need to set the primary key to
>include the primary key fields from the other two tables. "


Well, it's a good idea, but it's not in fact obligatory.

>If I do this, I keep getting the error message "the change you requested to
>the table were not successful because they would create duplicate values in
>the index, primary key, or relationship.


Sounds like you defined just one of the fields as the primary key, rather than
ctrl-clicking both fields and clicking the Key icon. Both foreign keys should
have the key icon next to them in table design view - not just one of them.

>The only way I'm entering data is through a form based on a query which
>automatically writes to all 3 tables (the junction and 2 parents) at once.


Generally a Very Bad Idea. Why not use the tools that Access provides - a form
based on one of the "one" side tables, and a subform based on the junction
table?

>If I remove the primary keys in the junction tables, I no longer get the
>error message. Am I going to regret this later?


Junction tables, plural? Are there more than one?

--

John W. Vinson [MVP]
 
Reply With Quote
 
boooney
Guest
Posts: n/a
 
      14th Apr 2010
John,

Thanks...actually I did originally define both fields as the primary key.

Basically, what I have is an invoice table, an invoice-source junction
table, and a source table. What I found was that when I added more than one
source to an invoice, I would get the error message. As you suggested, I do
have a a form
based on the "invoice" table, and a subform based on the invoice-source
junction
table. Here is the SQL query on which the form-subform is based:

SELECT jnct_Invoice_Source.Invoice_ID, jnct_Invoice_Source.Source_ID,
jnct_Invoice_Source.Amount, Source.Source_Name,
jnct_Invoice_Source.Initial_Source, jnct_Invoice_Source.Init_Source_Repaid,
jnct_Invoice_Source.jnct_Invoice_Source_ID
FROM Source INNER JOIN (Invoices INNER JOIN jnct_Invoice_Source ON
Invoices.Invoice_ID = jnct_Invoice_Source.Invoice_ID) ON Source.Source_ID =
jnct_Invoice_Source.Source_ID;

Thanks again for your help.





"John W. Vinson" wrote:

> On Tue, 13 Apr 2010 17:46:01 -0700, boooney
> <(E-Mail Removed)> wrote:
>
> >I have read that "in a junction table, you need to set the primary key to
> >include the primary key fields from the other two tables. "

>
> Well, it's a good idea, but it's not in fact obligatory.
>
> >If I do this, I keep getting the error message "the change you requested to
> >the table were not successful because they would create duplicate values in
> >the index, primary key, or relationship.

>
> Sounds like you defined just one of the fields as the primary key, rather than
> ctrl-clicking both fields and clicking the Key icon. Both foreign keys should
> have the key icon next to them in table design view - not just one of them.
>
> >The only way I'm entering data is through a form based on a query which
> >automatically writes to all 3 tables (the junction and 2 parents) at once.

>
> Generally a Very Bad Idea. Why not use the tools that Access provides - a form
> based on one of the "one" side tables, and a subform based on the junction
> table?
>
> >If I remove the primary keys in the junction tables, I no longer get the
> >error message. Am I going to regret this later?

>
> Junction tables, plural? Are there more than one?
>
> --
>
> John W. Vinson [MVP]
> .
>

 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      15th Apr 2010
On Wed, 14 Apr 2010 08:43:02 -0700, boooney
<(E-Mail Removed)> wrote:

>John,
>
>Thanks...actually I did originally define both fields as the primary key.
>
>Basically, what I have is an invoice table, an invoice-source junction
>table, and a source table. What I found was that when I added more than one
>source to an invoice, I would get the error message. As you suggested, I do
>have a a form
>based on the "invoice" table, and a subform based on the invoice-source
>junction
>table. Here is the SQL query on which the form-subform is based:
>
>SELECT jnct_Invoice_Source.Invoice_ID, jnct_Invoice_Source.Source_ID,
>jnct_Invoice_Source.Amount, Source.Source_Name,
>jnct_Invoice_Source.Initial_Source, jnct_Invoice_Source.Init_Source_Repaid,
>jnct_Invoice_Source.jnct_Invoice_Source_ID
>FROM Source INNER JOIN (Invoices INNER JOIN jnct_Invoice_Source ON
>Invoices.Invoice_ID = jnct_Invoice_Source.Invoice_ID) ON Source.Source_ID =
>jnct_Invoice_Source.Source_ID;
>
>Thanks again for your help.


No. Your subform is NOT "based on the invoice-source table". It is based on a
Query joining all three tables. That's why you're having the difficulty!

Change the Form's Recordsource to just the Invoice table - or a query sorting
the invoice table by date, or invoice number, or whatever's convenient; and
change the Subform's Recordsource to just jnct_Invoice_Source. Use InvoiceID
as the master/child link field, and use a combo box based on Source bound to
Source_ID so you can display the source name rather than the ID.

--

John W. Vinson [MVP]
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot create new primary partition - only 2 primary partitions on disk Vistanoob Windows Vista Performance 6 28th May 2009 05:13 PM
How to use BOOT.INI for two primary partitions? First Primary partiton is formatted David Welch Windows XP Help 8 3rd May 2009 01:59 AM
Does DriveImage 7 include the MBR in its image of a primary partition? Chris Windows XP General 9 18th Aug 2004 10:30 PM
Backing up primary winxp so secondary can be primary when needed? DrB Windows XP Setup 0 11th Jul 2004 02:49 AM
System primary account in the primary domain missing Pradeep Microsoft Windows 2000 Active Directory 1 15th May 2004 04:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:01 PM.