WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Allow Duplicates

 
Goto page Previous  1, 2, 3
   Home -> Office other -> Table Design RSS
Next:  Sort a table by street name using Access 2007  
Author Message
acss

External


Since: Jun 27, 2007
Posts: 44



(Msg. 17) Posted: Thu Aug 20, 2009 10:48 am
Post subject: Re: Allow Duplicates [Login to view extended thread Info.]
Archived from groups: microsoft>public>access>tablesdbdesign (more info?)

Hello John,

I still could not get the results as using the fields you displayed:

INV-TABLE
InvID <Text, Primary Key>
InvCntry <Text, Primary Key>
<other fields>

INV-DETAILS TABLE
DetailID <Autonumber, Primary Key>
InvID <Text, matching INV-TABLE.InvID in size>
InvCntry <Text, matching INV-TABLE.InvCntry in size>
<other detail fields>

My understanding :
INV-TABLE
InvID----IS TEXT PRIMARY KEY
InvCntry---is part of a composite key consisting of InvID & InvCntry (set
InvCntry as unique-index-no duplicates

INV-DETAILS
DetailID --AUTONUMBER -If this is the autonumber should i have FK field as
number long integer in the INV-TABLE. ( Have tried this and it creates a one
to many from the details table. I need a one to many from the INV-TABLE to
the INV DETAILS TABLE.
InvID--set as index-allow duplicates--FK
InvCntry--set as index-allow duplicates--FK

I have tried yet not able to obtain referential integrity or the one to many
from Invoice table to the Invoice Details table. Is it imperative to have
referential Integrity for what i need?

Thank you for th support



"John W. Vinson" wrote:

> On Tue, 11 Aug 2009 10:09:01 -0700, acss <joekru98.DeleteThis@hotmail.com> wrote:
>
> >Hello John,
> >
> >I created a field called PRIME and assigned that as primary key then I
> >assigned both the InvID and InvCntry as composite keys. When clicking the
> >indexs icon it displays Prime as unique while the other two fields allows
> >duplicates. The same set up applys with the Details Table. I went into the
> >relationship window to drag and drop muliple fields to the details table and
> >this resulted in 3 relationship lines of one to many. I cannot set the
> >(enforce referential integrity on the relationship) yet in testing data entry
> >within the invoices table it accomplishes what i needed...it accepts
> >duplicate invoices as long as a different country is entered and rejects if
> >same invoice and same country is entered.
> >INV-TABLE
> >Prime----PK-text
> >InvID---Composite-text
> >InvCntry--Composite-text
> >
> >INV-DETAILS TABLE
> >Prime----PK-text
> >InvID---FK-text
> >InvCntry-FK-text
> >
> >Is this what you were referring to or at the very least a hint of progress?
>
> Again... *you are misunderstanding what a primary key is*.
>
> It's PRIMARY! It is - must be - *unique* within the table. It can occur once,
> and only once!
>
> Therefore, it's appropriate to have it as the primary key of the INV-TABLE but
> it is *WRONG* to have it as the primary key of the INV-DETAILS table. The
> INV-DETAILS table should have its *own*, separate, independent, unrelated
> primary key; it should have the PRIME field as a non-unique foreign key,
> related to the Prime field in a one-to-many relationship.
>
> What I had suggested is a multifield primary key:
>
> INV-TABLE
> InvID <Text, Primary Key>
> InvCntry <Text, Primary Key>
> <other fields>
>
> INV-DETAILS TABLE
> DetailID <Autonumber, Primary Key>
> InvID <Text, matching INV-TABLE.InvID in size>
> InvCntry <Text, matching INV-TABLE.InvCntry in size>
> <other detail fields>
>
> If you then open the Relationships window you can join InvID to InvID, and
> join InvCNtry to InvCntry; enforce relational integrity and you should get a
> one to many relationship.
>
> Creating a separate Prime field is an alternative; it could be an Autonumber
> in INV-TABLE, with a separate unique two-field index on InvID and InvCntry. In
> this approach you would have a Long Integer Prime field as a foreign key (NOT
> a primary key) in INV-DETAILS, and the InvID and InvCntry fields would not
> exist in the details table at all (since that would be redundant, and they can
> be found by linking to INV-TABLE).
>
> How are you assigning a value to the Prime field anyway?
>
> --
>
> John W. Vinson [MVP]
>
Back to top
Login to vote
John W. Vinson

External


Since: Jan 29, 2004
Posts: 4665



(Msg. 18) Posted: Fri Aug 21, 2009 11:43 am
Post subject: Re: Allow Duplicates [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Thu, 20 Aug 2009 10:48:01 -0700, acss <joekru98.TakeThisOut@hotmail.com> wrote:

>Hello John,
>
>I still could not get the results as using the fields you displayed:
>
>INV-TABLE
> InvID <Text, Primary Key>
> InvCntry <Text, Primary Key>
> <other fields>
>
>INV-DETAILS TABLE
> DetailID <Autonumber, Primary Key>
> InvID <Text, matching INV-TABLE.InvID in size>
> InvCntry <Text, matching INV-TABLE.InvCntry in size>
> <other detail fields>
>
>My understanding :
>INV-TABLE
>InvID----IS TEXT PRIMARY KEY
>InvCntry---is part of a composite key consisting of InvID & InvCntry (set
>InvCntry as unique-index-no duplicates

Incorrect.

InvCntry should be a unique index, no duplicates, ONLY if you want to enter
each country in the table ONLY ONCE. That is, if you have an item in Brazil,
that is the *only item in the entire table* that can be in Brazil.

My understanding - and maybe I'm mistaken - is that you want an InvID of "ABC"
in the US, an InvID of "ABC" in Brazil, and an InvID of "ABC" in Argentina;
and you may also want an InvID of "XYZ" in the US, Argentina and Kenya. Right?

If so, *neither* InvID *nor* InvCntry can be unique. There will be duplicates
in the table on both fields. What needs to be unique is the combination of the
two fields! That's what the two-field joint primary key does. Either field can
have duplicates (you can have product ABC in the US and in Argentina; you can
have products ABC and XYZ in Argentina) but the combination is unique (you
can't have ABC - United States in the table twice).

The only unique index in INV-DETAILS table should be the primary key, since
you say you want to have multiple details records for the ABC-United States
inventory item.



>
>INV-DETAILS
>DetailID --AUTONUMBER -If this is the autonumber should i have FK field as
>number long integer in the INV-TABLE.

Incorrect, and I never said that. The foreign key is in the *MANY* side table,
not the One side table.

> ( Have tried this and it creates a one
>to many from the details table. I need a one to many from the INV-TABLE to
>the INV DETAILS TABLE.
>InvID--set as index-allow duplicates--FK
>InvCntry--set as index-allow duplicates--FK


>I have tried yet not able to obtain referential integrity or the one to many
>from Invoice table to the Invoice Details table. Is it imperative to have
>referential Integrity for what i need?

Yes. And you would do it by having *two* join lines in the relationships
window: from INV-TABLE.INVID to INV-DETAILS.INVID, and from INV-TABLE.INVCNTRY
to INV-DETAILS.InvCntry. There would be no join line to DetailID.
--

John W. Vinson [MVP]
Back to top
Login to vote
Graham Mandeno

External


Since: Jun 10, 2009
Posts: 6



(Msg. 19) Posted: Sat Aug 22, 2009 1:05 am
Post subject: Re: Allow Duplicates [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> InvCntry---is part of a composite key consisting of InvID & InvCntry (set
> InvCntry as unique-index-no duplicates

No, if you make InvCntry a unique index then you will not be able to add two
invoices fron the same country!

Have you seen my posts from more than two weeks ago where I suggested using
a surrogate (autonumber) primary key and having the InvNum/InvCntry as a
secondary unique index? As I've explained before, I believe this is by far
the best approach.

--
Graham Mandeno [Access MVP]
Auckland, New Zealand

"acss" <joekru98.RemoveThis@hotmail.com> wrote in message
news:7AB46569-D3AE-4F51-8FCA-E974FF0E2C2F@microsoft.com...
> Hello John,
>
> I still could not get the results as using the fields you displayed:
>
> INV-TABLE
> InvID <Text, Primary Key>
> InvCntry <Text, Primary Key>
> <other fields>
>
> INV-DETAILS TABLE
> DetailID <Autonumber, Primary Key>
> InvID <Text, matching INV-TABLE.InvID in size>
> InvCntry <Text, matching INV-TABLE.InvCntry in size>
> <other detail fields>
>
> My understanding :
> INV-TABLE
> InvID----IS TEXT PRIMARY KEY
> InvCntry---is part of a composite key consisting of InvID & InvCntry (set
> InvCntry as unique-index-no duplicates
>
> INV-DETAILS
> DetailID --AUTONUMBER -If this is the autonumber should i have FK field as
> number long integer in the INV-TABLE. ( Have tried this and it creates a
> one
> to many from the details table. I need a one to many from the INV-TABLE to
> the INV DETAILS TABLE.
> InvID--set as index-allow duplicates--FK
> InvCntry--set as index-allow duplicates--FK
>
> I have tried yet not able to obtain referential integrity or the one to
> many
> from Invoice table to the Invoice Details table. Is it imperative to have
> referential Integrity for what i need?
>
> Thank you for th support
>
>
>
> "John W. Vinson" wrote:
>
>> On Tue, 11 Aug 2009 10:09:01 -0700, acss <joekru98.RemoveThis@hotmail.com> wrote:
>>
>> >Hello John,
>> >
>> >I created a field called PRIME and assigned that as primary key then I
>> >assigned both the InvID and InvCntry as composite keys. When clicking
>> >the
>> >indexs icon it displays Prime as unique while the other two fields
>> >allows
>> >duplicates. The same set up applys with the Details Table. I went into
>> >the
>> >relationship window to drag and drop muliple fields to the details table
>> >and
>> >this resulted in 3 relationship lines of one to many. I cannot set the
>> >(enforce referential integrity on the relationship) yet in testing data
>> >entry
>> >within the invoices table it accomplishes what i needed...it accepts
>> >duplicate invoices as long as a different country is entered and rejects
>> >if
>> >same invoice and same country is entered.
>> >INV-TABLE
>> >Prime----PK-text
>> >InvID---Composite-text
>> >InvCntry--Composite-text
>> >
>> >INV-DETAILS TABLE
>> >Prime----PK-text
>> >InvID---FK-text
>> >InvCntry-FK-text
>> >
>> >Is this what you were referring to or at the very least a hint of
>> >progress?
>>
>> Again... *you are misunderstanding what a primary key is*.
>>
>> It's PRIMARY! It is - must be - *unique* within the table. It can occur
>> once,
>> and only once!
>>
>> Therefore, it's appropriate to have it as the primary key of the
>> INV-TABLE but
>> it is *WRONG* to have it as the primary key of the INV-DETAILS table. The
>> INV-DETAILS table should have its *own*, separate, independent, unrelated
>> primary key; it should have the PRIME field as a non-unique foreign key,
>> related to the Prime field in a one-to-many relationship.
>>
>> What I had suggested is a multifield primary key:
>>
>> INV-TABLE
>> InvID <Text, Primary Key>
>> InvCntry <Text, Primary Key>
>> <other fields>
>>
>> INV-DETAILS TABLE
>> DetailID <Autonumber, Primary Key>
>> InvID <Text, matching INV-TABLE.InvID in size>
>> InvCntry <Text, matching INV-TABLE.InvCntry in size>
>> <other detail fields>
>>
>> If you then open the Relationships window you can join InvID to InvID,
>> and
>> join InvCNtry to InvCntry; enforce relational integrity and you should
>> get a
>> one to many relationship.
>>
>> Creating a separate Prime field is an alternative; it could be an
>> Autonumber
>> in INV-TABLE, with a separate unique two-field index on InvID and
>> InvCntry. In
>> this approach you would have a Long Integer Prime field as a foreign key
>> (NOT
>> a primary key) in INV-DETAILS, and the InvID and InvCntry fields would
>> not
>> exist in the details table at all (since that would be redundant, and
>> they can
>> be found by linking to INV-TABLE).
>>
>> How are you assigning a value to the Prime field anyway?
>>
>> --
>>
>> John W. Vinson [MVP]
>>
Back to top
Login to vote
JUNEBUG

External


Since: Sep 11, 2009
Posts: 1



(Msg. 20) Posted: Fri Sep 11, 2009 1:39 pm
Post subject: Re: Allow Duplicates [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hello - what would the criteria for deleting a duplicate record, e.g
PO#1, LINE 1, RECEIVED1
PO#1, LINE 1, SHIPPED1
I am looking to delete whatever is the Same PO#, Same LINE but
SHIPPED(instead of Received) I only need one record or RECEIVED.
thank you


"Graham Mandeno" wrote:

> Hi Joe (?)
>
> I'm confused. You say "The primary key is the invoice number as an
> autonumber" but you also said that the invoice number was in the imported
> data, so it can't be an autonumber!
>
> I suggest you add a new autonumber field named InvoiceID and make that your
> primary key. Then, make InvoiceNumber and Country both required fields and
> make them a composite unique key.
>
> To do this, open the Indexes window (View>Indexes) and in the first blank
> row, enter "InvoiceNumberCountry" as the index name and select InvoiceNumber
> as the field name. Then, in the index properties below, change Unique to
> "Yes". Now, in the next blank line, choose Country as the field name (but
> leave index name blank).
>
> --
> Good Luck Smile
>
> Graham Mandeno [Access MVP]
> Auckland, New Zealand
>
>
> "acss" <joekru98.RemoveThis@hotmail.com> wrote in message
> news:C085BA73-567F-4527-95ED-A084EC3E3670@microsoft.com...
> > Hello,
> > I am still working on this and i am curious as to how you create a unique
> > index on a combination of invoice and country field? The primary key is
> > the
> > invoice number as an autonumber so the table can not have more than one
> > primary key....can you eloborate for me please?
> >
> > "Noëlla Gabriël" wrote:
> >
> >> Hi,
> >>
> >> I always take an autonumber field as PK field. You can then create
> >> another
> >> unique index on the combination of the invoice number field and the
> >> country
> >> field
> >> --
> >> Kind regards
> >> Noëlla
> >>
> >>
> >> "acss" wrote:
> >>
> >> > i have a table for invoices and at times i receive a duplicate invoice
> >> > number
> >> > from another country. How do i set up a primary key (InvoiceID) and a
> >> > secondary key (country) that would allow a duplicate entry only if from
> >> > a
> >> > different country?
> >> >
> >> > Thanks
>
>
>
Back to top
Login to vote
Graham Mandeno

External


Since: Jun 10, 2009
Posts: 6



(Msg. 21) Posted: Sun Sep 13, 2009 8:05 pm
Post subject: Re: Allow Duplicates [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi JUNEBUG

You will need a query something like this:

Delete from tblOrders as O WHERE O.Status<>"SHIPPED" and
Exists (Select PO from tblOrders as X where X.PO=O.PO and X.Line=O.Line
and X.Status="SHIPPED")

In plain English: Delete from the table any record whose status is not
"SHIPPED" if there is a "SHIPPED" record in the table for the same PO and
Line number.

--
Good Luck Smile

Graham Mandeno [Access MVP]
Auckland, New Zealand

"JUNEBUG" <JUNEBUG.RemoveThis@discussions.microsoft.com> wrote in message
news:593F22D2-F0DC-4ADE-B817-00CCF02D1B79@microsoft.com...
> Hello - what would the criteria for deleting a duplicate record, e.g
> PO#1, LINE 1, RECEIVED1
> PO#1, LINE 1, SHIPPED1
> I am looking to delete whatever is the Same PO#, Same LINE but
> SHIPPED(instead of Received) I only need one record or RECEIVED.
> thank you
>
>
> "Graham Mandeno" wrote:
>
>> Hi Joe (?)
>>
>> I'm confused. You say "The primary key is the invoice number as an
>> autonumber" but you also said that the invoice number was in the imported
>> data, so it can't be an autonumber!
>>
>> I suggest you add a new autonumber field named InvoiceID and make that
>> your
>> primary key. Then, make InvoiceNumber and Country both required fields
>> and
>> make them a composite unique key.
>>
>> To do this, open the Indexes window (View>Indexes) and in the first blank
>> row, enter "InvoiceNumberCountry" as the index name and select
>> InvoiceNumber
>> as the field name. Then, in the index properties below, change Unique to
>> "Yes". Now, in the next blank line, choose Country as the field name
>> (but
>> leave index name blank).
>>
>> --
>> Good Luck Smile
>>
>> Graham Mandeno [Access MVP]
>> Auckland, New Zealand
>>
>>
>> "acss" <joekru98.RemoveThis@hotmail.com> wrote in message
>> news:C085BA73-567F-4527-95ED-A084EC3E3670@microsoft.com...
>> > Hello,
>> > I am still working on this and i am curious as to how you create a
>> > unique
>> > index on a combination of invoice and country field? The primary key is
>> > the
>> > invoice number as an autonumber so the table can not have more than one
>> > primary key....can you eloborate for me please?
>> >
>> > "Noëlla Gabriël" wrote:
>> >
>> >> Hi,
>> >>
>> >> I always take an autonumber field as PK field. You can then create
>> >> another
>> >> unique index on the combination of the invoice number field and the
>> >> country
>> >> field
>> >> --
>> >> Kind regards
>> >> Noëlla
>> >>
>> >>
>> >> "acss" wrote:
>> >>
>> >> > i have a table for invoices and at times i receive a duplicate
>> >> > invoice
>> >> > number
>> >> > from another country. How do i set up a primary key (InvoiceID) and
>> >> > a
>> >> > secondary key (country) that would allow a duplicate entry only if
>> >> > from
>> >> > a
>> >> > different country?
>> >> >
>> >> > Thanks
>>
>>
>>
Back to top
Login to vote
Display posts from previous:   
       Home -> Office other -> Table Design All times are: Eastern Time (US & Canada) (change)
Goto page Previous  1, 2, 3
Page 3 of 3

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
 Office
  Office Other
 Security
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET |
  • IT Support