A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

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



 
 
Thread Tools Display Modes
  #1  
Old April 14th, 2010, 01:46 AM posted to microsoft.public.access.tablesdbdesign
boooney
external usenet poster
 
Posts: 14
Default Do I have to set the primary key to include primary key fields?

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.
  #2  
Old April 14th, 2010, 03:11 AM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Do I have to set the primary key to include primary key fields?

On Tue, 13 Apr 2010 17:46:01 -0700, boooney
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]
  #3  
Old April 14th, 2010, 04:43 PM posted to microsoft.public.access.tablesdbdesign
boooney
external usenet poster
 
Posts: 14
Default Do I have to set the primary key to include primary key fields

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
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]
.

  #4  
Old April 15th, 2010, 12:17 AM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Do I have to set the primary key to include primary key fields

On Wed, 14 Apr 2010 08:43:02 -0700, boooney
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]
 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:49 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.