PC Review


Reply
Thread Tools Rate Thread

Concatinating one PK from one tbl & autonumber for a PK in a 2nd t

 
 
=?Utf-8?B?UmljaGFyZA==?=
Guest
Posts: n/a
 
      27th Oct 2007
I have many tables based on two fields in two different tables. Rather than
have both PKs in every table, I would like to have a PK from one table
(tblStyle SK (StyleKey) 1...50) be in combination with an autonumber giving
me a unique ID based on the two so that it looks like this:

tblDesign Primary Key = (SK)37+autonumber = 37405

If this is possible in Access, would you please explain how I would go about
doing this? Thank you
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      27th Oct 2007
What's the matter with having two separate fields? That's the way it should
be done. What you're proposing would actually be a violation of database
normalization principles, one of which states that each field should be
atomic (you're trying to put two pieces of information into one field).

If you want 37405 displayed on forms or reports, you can concatenate the two
fields. Store them separately though.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Richard" <(E-Mail Removed)> wrote in message
news:1835D40E-DDE2-45A7-AE3D-(E-Mail Removed)...
>I have many tables based on two fields in two different tables. Rather than
> have both PKs in every table, I would like to have a PK from one table
> (tblStyle SK (StyleKey) 1...50) be in combination with an autonumber
> giving
> me a unique ID based on the two so that it looks like this:
>
> tblDesign Primary Key = (SK)37+autonumber = 37405
>
> If this is possible in Access, would you please explain how I would go
> about
> doing this? Thank you



 
Reply With Quote
 
Tony Toews [MVP]
Guest
Posts: n/a
 
      27th Oct 2007
Richard <(E-Mail Removed)> wrote:

>I have many tables based on two fields in two different tables. Rather than
>have both PKs in every table, I would like to have a PK from one table
>(tblStyle SK (StyleKey) 1...50) be in combination with an autonumber giving
>me a unique ID based on the two so that it looks like this:
>
>tblDesign Primary Key = (SK)37+autonumber = 37405


What happens if you have (SK)3 and autonumber 7405?

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/
 
Reply With Quote
 
=?Utf-8?B?UmljaGFyZA==?=
Guest
Posts: n/a
 
      27th Oct 2007
Thanks for your reply Tony.

Yes I had thought of that too, and decided that my next question, IF the
concatenation above was possible was to ask if it was possible to have a
rigid 10 digit number, or concatenate with a letter or three 9s between the
two. First things first. R-

"Tony Toews [MVP]" wrote:

> What happens if you have (SK)3 and autonumber 7405?
>
> Tony
> --
> Tony Toews, Microsoft Access MVP


 
Reply With Quote
 
=?Utf-8?B?UmljaGFyZA==?=
Guest
Posts: n/a
 
      27th Oct 2007
Thanks for your reply Douglas.

It appears that we have a misunderstanding. First, this is not for use in
forms and reports. Second, repeating the same TWO fields in all my tables
would seem to me to be against normalization. I could set up a third table
that has three fields - DK, SK, and UniqueID. I just wanted to get there in
the second table. After all, we don't use a separate table for the area code
of a phone number. (Access actually did that once for me when I got a list
of phone numbers from an Excel file.)

Say, I have 20 aux. tables all of which are dependent/related to the DK/SK
combination (the DKs come in many SKs). If I have to list both fields in
each aux. table in order to insure uniqueness, I will have many SKs in each,
which I see as against normalization. Having the DK with an SK "prefix"
would also be a good visual check that would help the user to know the style
at a glance, much as seeing the area code 202 tells you it is Washington, D.C.

Perhaps it is not a good idea, and my third table above is better, but the
issue becomes more complex once I send replicas out because all those tables.
R-

"Douglas J. Steele" wrote:

> What's the matter with having two separate fields? That's the way it should
> be done. What you're proposing would actually be a violation of database
> normalization principles, one of which states that each field should be
> atomic (you're trying to put two pieces of information into one field).
>
> If you want 37405 displayed on forms or reports, you can concatenate the two
> fields. Store them separately though.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "Richard" <(E-Mail Removed)> wrote in message
> news:1835D40E-DDE2-45A7-AE3D-(E-Mail Removed)...
> >I have many tables based on two fields in two different tables. Rather than
> > have both PKs in every table, I would like to have a PK from one table
> > (tblStyle SK (StyleKey) 1...50) be in combination with an autonumber
> > giving
> > me a unique ID based on the two so that it looks like this:
> >
> > tblDesign Primary Key = (SK)37+autonumber = 37405
> >
> > If this is possible in Access, would you please explain how I would go
> > about
> > doing this? Thank you

>
>
>

 
Reply With Quote
 
Sylvain Lafontaine
Guest
Posts: n/a
 
      27th Oct 2007
From what I understand from your description, this seems to me as a very bad
idea. By generating your own *autonumber*, it's very easy to implement
something like that (using 0 to padd the low order key to a constant number
of digit). However, when you will try to join your two tables into a query,
you will be hurt be a *very* severe performance problem because you will
have to decompose your composite key into its elements and no index can
manage that in an effective way.

The use of a third table (DK, SK and UniqueID) could possibly alleviate this
problem but still, you sentence « Second, repeating the same TWO fields in
all my tables would seem to me to be against normalization » suggest that
you might have a design problem here: if only one combination of DK and SK
is permissible for each value of DK and SK then one of these values is
superfluous and the second table should use DK instead of SK as its primary
key. If other combinations are possible, then goodbye performance and
welcome slowness.

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


"Richard" <(E-Mail Removed)> wrote in message
news:1835D40E-DDE2-45A7-AE3D-(E-Mail Removed)...
>I have many tables based on two fields in two different tables. Rather than
> have both PKs in every table, I would like to have a PK from one table
> (tblStyle SK (StyleKey) 1...50) be in combination with an autonumber
> giving
> me a unique ID based on the two so that it looks like this:
>
> tblDesign Primary Key = (SK)37+autonumber = 37405
>
> If this is possible in Access, would you please explain how I would go
> about
> doing this? Thank you



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      27th Oct 2007
There's nothing wrong with the primary key being more than one field if
that's what it takes to guarantee uniqueness. You can have up to ten
separate fields in an index.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"Richard" <(E-Mail Removed)> wrote in message
news:72952494-BD77-4B17-A4DD-(E-Mail Removed)...
> Thanks for your reply Douglas.
>
> It appears that we have a misunderstanding. First, this is not for use in
> forms and reports. Second, repeating the same TWO fields in all my tables
> would seem to me to be against normalization. I could set up a third
> table
> that has three fields - DK, SK, and UniqueID. I just wanted to get there
> in
> the second table. After all, we don't use a separate table for the area
> code
> of a phone number. (Access actually did that once for me when I got a
> list
> of phone numbers from an Excel file.)
>
> Say, I have 20 aux. tables all of which are dependent/related to the DK/SK
> combination (the DKs come in many SKs). If I have to list both fields in
> each aux. table in order to insure uniqueness, I will have many SKs in
> each,
> which I see as against normalization. Having the DK with an SK "prefix"
> would also be a good visual check that would help the user to know the
> style
> at a glance, much as seeing the area code 202 tells you it is Washington,
> D.C.
>
> Perhaps it is not a good idea, and my third table above is better, but the
> issue becomes more complex once I send replicas out because all those
> tables.
> R-
>
> "Douglas J. Steele" wrote:
>
>> What's the matter with having two separate fields? That's the way it
>> should
>> be done. What you're proposing would actually be a violation of database
>> normalization principles, one of which states that each field should be
>> atomic (you're trying to put two pieces of information into one field).
>>
>> If you want 37405 displayed on forms or reports, you can concatenate the
>> two
>> fields. Store them separately though.
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no private e-mails, please)
>>
>>
>> "Richard" <(E-Mail Removed)> wrote in message
>> news:1835D40E-DDE2-45A7-AE3D-(E-Mail Removed)...
>> >I have many tables based on two fields in two different tables. Rather
>> >than
>> > have both PKs in every table, I would like to have a PK from one table
>> > (tblStyle SK (StyleKey) 1...50) be in combination with an autonumber
>> > giving
>> > me a unique ID based on the two so that it looks like this:
>> >
>> > tblDesign Primary Key = (SK)37+autonumber = 37405
>> >
>> > If this is possible in Access, would you please explain how I would go
>> > about
>> > doing this? Thank you

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?UmljaGFyZA==?=
Guest
Posts: n/a
 
      5th Nov 2007
Thanks Sylvain for your reply.

I have indeed started over in the design process, and your comment about
"one of these values is superfluous" is close on. Part of my problem is a
lack of understanding (plain ignorance) about the process of replication, and
what I was trying to do here, is probably superfluous because replication I
think, takes care of the "security" I was trying to build in. Hope that
makes sense.
In any case, I need to learn about that process before proceeding with the
design.

Once again, thank you and all the others for your input. Working alone with
no one, who understands what you are doing, to run things by to get a second
opinion is mind-boggling, So, having you "experts" willing to share some of
your knowledge is something to be thankful for this coming Thanksgiving. I
will raise a toast to you all that day. R-
"Sylvain Lafontaine" wrote:


 
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
Concatinating one PK from one tbl & autonumber for a PK in another =?Utf-8?B?UmljaGFyZA==?= Microsoft Word Document Management 3 31st Oct 2007 12:08 PM
concatinating fields Microsoft Access 3 18th Nov 2005 12:44 AM
Concatinating cells Praveen Microsoft Excel Programming 4 11th Aug 2005 09:14 AM
Concatinating two dates.....? Kelvin Beaton Microsoft Excel Discussion 4 22nd Apr 2004 05:19 PM
concatinating records Eric Blitzer Microsoft Access 2 8th Jan 2004 02:47 PM


Features
 

Advertising
 

Newsgroups
 


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