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  

multiple field, primary key



 
 
Thread Tools Display Modes
  #1  
Old March 4th, 2009, 03:24 PM posted to microsoft.public.access.tablesdbdesign
Jim[_52_]
external usenet poster
 
Posts: 5
Default multiple field, primary key

I have tblAccounts, where I have the following (each field will be
sorted on):

field1 long integer
field2 long integer
field3 text (this field can be null-see below)

Field1 & "-" & Field2 & Field3 = Field4 (text), which is the primary
key.

thus,
10 & "-" 200 & AH = Account# 10-200AH

The primary key (10-200AH) is the foreign key in several other tables.

My question is, would it be better to have field1,field2,field3 a
"multiple field primary key", which would mean that I would need to
require a zero in field3 if null and just display "" (blank) for
field3 in any reports. Thats why I didn't make the 3 fields a primary
key to begin with, because of nulls in field3.

But, I'm revisting my design for two reasons. First, in making any
queries, I have to be sure to add the "breakdown" of the account
number in order to sort correctly. Second, I have a Form where user
enters field1, field2, field3, and the afterupdate event of each is:

Field4 = Field1 & "-" & Field2 & Field3

But, I've run across a couple of instances where user somehow mananged
to not fill in complete account or whatever strange thing happened,
and the PK field (field4) didn't get updated properly.

Any suggestions would be appreciated

Thanks, Jim
  #2  
Old March 4th, 2009, 04:28 PM posted to microsoft.public.access.tablesdbdesign
Michael Gramelspacher
external usenet poster
 
Posts: 482
Default multiple field, primary key

On Wed, 04 Mar 2009 08:24:25 -0700, Jim wrote:

I have tblAccounts, where I have the following (each field will be
sorted on):

field1 long integer
field2 long integer
field3 text (this field can be null-see below)

Field1 & "-" & Field2 & Field3 = Field4 (text), which is the primary
key.

thus,
10 & "-" 200 & AH = Account# 10-200AH

The primary key (10-200AH) is the foreign key in several other tables.

My question is, would it be better to have field1,field2,field3 a
"multiple field primary key", which would mean that I would need to
require a zero in field3 if null and just display "" (blank) for
field3 in any reports. Thats why I didn't make the 3 fields a primary
key to begin with, because of nulls in field3.

But, I'm revisting my design for two reasons. First, in making any
queries, I have to be sure to add the "breakdown" of the account
number in order to sort correctly. Second, I have a Form where user
enters field1, field2, field3, and the afterupdate event of each is:

Field4 = Field1 & "-" & Field2 & Field3

But, I've run across a couple of instances where user somehow mananged
to not fill in complete account or whatever strange thing happened,
and the PK field (field4) didn't get updated properly.

Any suggestions would be appreciated

Thanks, Jim


CREATE TABLE Table1 (
partA LONG NOT NULL,
partB LONG NOT NULL,
partC TEXT(50) DEFAULT "" NOT NULL,
PRIMARY KEY (partA, partB, partC)
);

Drop the Field4 as it is a computed field and can be computed on the fly anytime needed.

Just a suggestion.
  #3  
Old March 4th, 2009, 08:22 PM posted to microsoft.public.access.tablesdbdesign
Jim[_52_]
external usenet poster
 
Posts: 5
Default multiple field, primary key

On Wed, 04 Mar 2009 10:28:47 -0600, Michael Gramelspacher
wrote:

On Wed, 04 Mar 2009 08:24:25 -0700, Jim wrote:

I have tblAccounts, where I have the following (each field will be
sorted on):

field1 long integer
field2 long integer
field3 text (this field can be null-see below)

Field1 & "-" & Field2 & Field3 = Field4 (text), which is the primary
key.

thus,
10 & "-" 200 & AH = Account# 10-200AH

The primary key (10-200AH) is the foreign key in several other tables.

My question is, would it be better to have field1,field2,field3 a
"multiple field primary key", which would mean that I would need to
require a zero in field3 if null and just display "" (blank) for
field3 in any reports. Thats why I didn't make the 3 fields a primary
key to begin with, because of nulls in field3.

But, I'm revisting my design for two reasons. First, in making any
queries, I have to be sure to add the "breakdown" of the account
number in order to sort correctly. Second, I have a Form where user
enters field1, field2, field3, and the afterupdate event of each is:

Field4 = Field1 & "-" & Field2 & Field3

But, I've run across a couple of instances where user somehow mananged
to not fill in complete account or whatever strange thing happened,
and the PK field (field4) didn't get updated properly.

Any suggestions would be appreciated

Thanks, Jim


CREATE TABLE Table1 (
partA LONG NOT NULL,
partB LONG NOT NULL,
partC TEXT(50) DEFAULT "" NOT NULL,
PRIMARY KEY (partA, partB, partC)
);

Drop the Field4 as it is a computed field and can be computed on the fly anytime needed.

Just a suggestion.


Seems logical. It's bothered me that I set it up this way in the
first place, but fortunately I believe I can change it pretty easy.

Thanks.
  #4  
Old March 4th, 2009, 10:36 PM posted to microsoft.public.access.tablesdbdesign
Steve[_57_]
external usenet poster
 
Posts: 598
Default multiple field, primary key

I always recommend a primary key of autonumber for ALL tables just to avoid
the problem you describe and other problems. I recommend:
TblAccount
AccountID
Account

When you need to enter an account in any form then, all you need is a
combobox that has TblAccount as its rowsource. When you do that the only
mistake that an user can make is to fail to enter an account. That too can
be eliminated by making the AccountID required in your form.

Steve



"Jim" wrote in message
...
I have tblAccounts, where I have the following (each field will be
sorted on):

field1 long integer
field2 long integer
field3 text (this field can be null-see below)

Field1 & "-" & Field2 & Field3 = Field4 (text), which is the primary
key.

thus,
10 & "-" 200 & AH = Account# 10-200AH

The primary key (10-200AH) is the foreign key in several other tables.

My question is, would it be better to have field1,field2,field3 a
"multiple field primary key", which would mean that I would need to
require a zero in field3 if null and just display "" (blank) for
field3 in any reports. Thats why I didn't make the 3 fields a primary
key to begin with, because of nulls in field3.

But, I'm revisting my design for two reasons. First, in making any
queries, I have to be sure to add the "breakdown" of the account
number in order to sort correctly. Second, I have a Form where user
enters field1, field2, field3, and the afterupdate event of each is:

Field4 = Field1 & "-" & Field2 & Field3

But, I've run across a couple of instances where user somehow mananged
to not fill in complete account or whatever strange thing happened,
and the PK field (field4) didn't get updated properly.

Any suggestions would be appreciated

Thanks, Jim



  #5  
Old March 4th, 2009, 10:52 PM posted to microsoft.public.access.tablesdbdesign
Jim[_52_]
external usenet poster
 
Posts: 5
Default multiple field, primary key

uhh, I'm a bit confused. So you're recommending to keep it as I've
done, but add a (PK) autonumber field?

Thanks.


On Wed, 4 Mar 2009 17:36:44 -0500, "Steve"
wrote:

I always recommend a primary key of autonumber for ALL tables just to avoid
the problem you describe and other problems. I recommend:
TblAccount
AccountID
Account

When you need to enter an account in any form then, all you need is a
combobox that has TblAccount as its rowsource. When you do that the only
mistake that an user can make is to fail to enter an account. That too can
be eliminated by making the AccountID required in your form.

Steve



"Jim" wrote in message
.. .
I have tblAccounts, where I have the following (each field will be
sorted on):

field1 long integer
field2 long integer
field3 text (this field can be null-see below)

Field1 & "-" & Field2 & Field3 = Field4 (text), which is the primary
key.

thus,
10 & "-" 200 & AH = Account# 10-200AH

The primary key (10-200AH) is the foreign key in several other tables.

My question is, would it be better to have field1,field2,field3 a
"multiple field primary key", which would mean that I would need to
require a zero in field3 if null and just display "" (blank) for
field3 in any reports. Thats why I didn't make the 3 fields a primary
key to begin with, because of nulls in field3.

But, I'm revisting my design for two reasons. First, in making any
queries, I have to be sure to add the "breakdown" of the account
number in order to sort correctly. Second, I have a Form where user
enters field1, field2, field3, and the afterupdate event of each is:

Field4 = Field1 & "-" & Field2 & Field3

But, I've run across a couple of instances where user somehow mananged
to not fill in complete account or whatever strange thing happened,
and the PK field (field4) didn't get updated properly.

Any suggestions would be appreciated

Thanks, Jim


  #6  
Old March 5th, 2009, 01:50 AM posted to microsoft.public.access.tablesdbdesign
Steve[_57_]
external usenet poster
 
Posts: 598
Default multiple field, primary key

No, I'm suggesting a table that looks like:
TblAccount
AccountID
AccountNumber
AccountDescription

where a sample account would look like:
1 10-200AH Widget AH Purchase

AccountID would serve as a foreign key in other tables as needed.

Jim, if you post a description of the process you are trying to recprd in
your database and the relevant tables with their fields, I can help you much
more.

Steve



"Jim" wrote in message
...
uhh, I'm a bit confused. So you're recommending to keep it as I've
done, but add a (PK) autonumber field?

Thanks.


On Wed, 4 Mar 2009 17:36:44 -0500, "Steve"
wrote:

I always recommend a primary key of autonumber for ALL tables just to
avoid
the problem you describe and other problems. I recommend:
TblAccount
AccountID
Account

When you need to enter an account in any form then, all you need is a
combobox that has TblAccount as its rowsource. When you do that the only
mistake that an user can make is to fail to enter an account. That too can
be eliminated by making the AccountID required in your form.

Steve



"Jim" wrote in message
. ..
I have tblAccounts, where I have the following (each field will be
sorted on):

field1 long integer
field2 long integer
field3 text (this field can be null-see below)

Field1 & "-" & Field2 & Field3 = Field4 (text), which is the primary
key.

thus,
10 & "-" 200 & AH = Account# 10-200AH

The primary key (10-200AH) is the foreign key in several other tables.

My question is, would it be better to have field1,field2,field3 a
"multiple field primary key", which would mean that I would need to
require a zero in field3 if null and just display "" (blank) for
field3 in any reports. Thats why I didn't make the 3 fields a primary
key to begin with, because of nulls in field3.

But, I'm revisting my design for two reasons. First, in making any
queries, I have to be sure to add the "breakdown" of the account
number in order to sort correctly. Second, I have a Form where user
enters field1, field2, field3, and the afterupdate event of each is:

Field4 = Field1 & "-" & Field2 & Field3

But, I've run across a couple of instances where user somehow mananged
to not fill in complete account or whatever strange thing happened,
and the PK field (field4) didn't get updated properly.

Any suggestions would be appreciated

Thanks, Jim




  #7  
Old March 5th, 2009, 03:05 AM posted to microsoft.public.access.tablesdbdesign
[email protected]
external usenet poster
 
Posts: 1
Default multiple field, primary key

Thanks, but think I got it figured out now.

Jim


On Wed, 4 Mar 2009 20:50:13 -0500, "Steve"
wrote:

No, I'm suggesting a table that looks like:
TblAccount
AccountID
AccountNumber
AccountDescription

where a sample account would look like:
1 10-200AH Widget AH Purchase

AccountID would serve as a foreign key in other tables as needed.

Jim, if you post a description of the process you are trying to recprd in
your database and the relevant tables with their fields, I can help you much
more.

Steve



"Jim" wrote in message
.. .
uhh, I'm a bit confused. So you're recommending to keep it as I've
done, but add a (PK) autonumber field?

Thanks.


On Wed, 4 Mar 2009 17:36:44 -0500, "Steve"
wrote:

I always recommend a primary key of autonumber for ALL tables just to
avoid
the problem you describe and other problems. I recommend:
TblAccount
AccountID
Account

When you need to enter an account in any form then, all you need is a
combobox that has TblAccount as its rowsource. When you do that the only
mistake that an user can make is to fail to enter an account. That too can
be eliminated by making the AccountID required in your form.

Steve



"Jim" wrote in message
...
I have tblAccounts, where I have the following (each field will be
sorted on):

field1 long integer
field2 long integer
field3 text (this field can be null-see below)

Field1 & "-" & Field2 & Field3 = Field4 (text), which is the primary
key.

thus,
10 & "-" 200 & AH = Account# 10-200AH

The primary key (10-200AH) is the foreign key in several other tables.

My question is, would it be better to have field1,field2,field3 a
"multiple field primary key", which would mean that I would need to
require a zero in field3 if null and just display "" (blank) for
field3 in any reports. Thats why I didn't make the 3 fields a primary
key to begin with, because of nulls in field3.

But, I'm revisting my design for two reasons. First, in making any
queries, I have to be sure to add the "breakdown" of the account
number in order to sort correctly. Second, I have a Form where user
enters field1, field2, field3, and the afterupdate event of each is:

Field4 = Field1 & "-" & Field2 & Field3

But, I've run across a couple of instances where user somehow mananged
to not fill in complete account or whatever strange thing happened,
and the PK field (field4) didn't get updated properly.

Any suggestions would be appreciated

Thanks, Jim


  #8  
Old March 9th, 2009, 05:05 PM posted to microsoft.public.access.tablesdbdesign
Jim[_52_]
external usenet poster
 
Posts: 5
Default multiple field, primary key

On Wed, 04 Mar 2009 10:28:47 -0600, Michael Gramelspacher
wrote:

On Wed, 04 Mar 2009 08:24:25 -0700, Jim wrote:

I have tblAccounts, where I have the following (each field will be
sorted on):

field1 long integer
field2 long integer
field3 text (this field can be null-see below)

Field1 & "-" & Field2 & Field3 = Field4 (text), which is the primary
key.

thus,
10 & "-" 200 & AH = Account# 10-200AH

The primary key (10-200AH) is the foreign key in several other tables.

My question is, would it be better to have field1,field2,field3 a
"multiple field primary key", which would mean that I would need to
require a zero in field3 if null and just display "" (blank) for
field3 in any reports. Thats why I didn't make the 3 fields a primary
key to begin with, because of nulls in field3.

But, I'm revisting my design for two reasons. First, in making any
queries, I have to be sure to add the "breakdown" of the account
number in order to sort correctly. Second, I have a Form where user
enters field1, field2, field3, and the afterupdate event of each is:

Field4 = Field1 & "-" & Field2 & Field3

But, I've run across a couple of instances where user somehow mananged
to not fill in complete account or whatever strange thing happened,
and the PK field (field4) didn't get updated properly.

Any suggestions would be appreciated

Thanks, Jim


CREATE TABLE Table1 (
partA LONG NOT NULL,
partB LONG NOT NULL,
partC TEXT(50) DEFAULT "" NOT NULL,
PRIMARY KEY (partA, partB, partC)
);

Drop the Field4 as it is a computed field and can be computed on the fly anytime needed.

Just a suggestion.



I'm tryhing to do as you suggested, but have a question. Is there a
way to "name" what is now the composite key, so that in defining
relationships I can simply join the composite key "AccountNo" with a
similarly combined foreign key in other tables? In other words, I'm
not sure how to join on multiple fields........

thanks, Jim
  #9  
Old March 9th, 2009, 08:08 PM posted to microsoft.public.access.tablesdbdesign
Michael Gramelspacher
external usenet poster
 
Posts: 482
Default multiple field, primary key

On Mon, 09 Mar 2009 11:05:36 -0600, Jim wrote:

CREATE TABLE Table1 (
partA LONG NOT NULL,
partB LONG NOT NULL,
partC TEXT(50) DEFAULT "" NOT NULL,
PRIMARY KEY (partA, partB, partC)
);

Drop the Field4 as it is a computed field and can be computed on the fly anytime needed.

Just a suggestion.



I'm tryhing to do as you suggested, but have a question. Is there a
way to "name" what is now the composite key, so that in defining
relationships I can simply join the composite key "AccountNo" with a
similarly combined foreign key in other tables? In other words, I'm
not sure how to join on multiple fields........

thanks, Jim


I usually do the joining in the Relationships window. Just selet the three fields in one table and
drag them to the relatedr table. Just select the fields in the related table by using the combo
boxes in the Edit Relationships window..

If you wish to avoid multiple-column keys, you can do this.

CREATE TABLE Table1 (
table1_id AUTOINCREMENT,
partA LONG NOT NULL,
partB LONG NOT NULL,
partC TEXT(50) DEFAULT "" NOT NULL,
UNIQUE (partA, partB, partC),
PRIMARY KEY (table1_id)
);

Just join then on table1_id. I find nothing particularly difficult about using multiple-column
keys.
  #10  
Old March 10th, 2009, 02:28 PM posted to microsoft.public.access.tablesdbdesign
Jim[_52_]
external usenet poster
 
Posts: 5
Default multiple field, primary key

On Mon, 09 Mar 2009 15:08:38 -0500, Michael Gramelspacher
wrote:

On Mon, 09 Mar 2009 11:05:36 -0600, Jim wrote:

CREATE TABLE Table1 (
partA LONG NOT NULL,
partB LONG NOT NULL,
partC TEXT(50) DEFAULT "" NOT NULL,
PRIMARY KEY (partA, partB, partC)
);

Drop the Field4 as it is a computed field and can be computed on the fly anytime needed.

Just a suggestion.



I'm tryhing to do as you suggested, but have a question. Is there a
way to "name" what is now the composite key, so that in defining
relationships I can simply join the composite key "AccountNo" with a
similarly combined foreign key in other tables? In other words, I'm
not sure how to join on multiple fields........

thanks, Jim


I usually do the joining in the Relationships window. Just selet the three fields in one table and
drag them to the relatedr table. Just select the fields in the related table by using the combo
boxes in the Edit Relationships window..

If you wish to avoid multiple-column keys, you can do this.

CREATE TABLE Table1 (
table1_id AUTOINCREMENT,
partA LONG NOT NULL,
partB LONG NOT NULL,
partC TEXT(50) DEFAULT "" NOT NULL,
UNIQUE (partA, partB, partC),
PRIMARY KEY (table1_id)
);

Just join then on table1_id. I find nothing particularly difficult about using multiple-column
keys.


I was trying to make the join in the query window rather than the
relationships window. It worked once I did it in the relationships
window.

Thanks
 




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 01:36 PM.


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