PC Review


Reply
Thread Tools Rate Thread

Creating a key consisting of two columns

 
 
Rachel Garrett
Guest
Posts: n/a
 
      23rd Aug 2011
Greetings,

I have records which are identified by a unique naming system (up to
six characters), and the numbering system changes each year. A key
consisting of [number,year] would work as a primary key, and in Design
View, I was able to shift-select two columns and make it the primary
key in my table.

Now that I've done that, how can I use this primary key in
relationships to other tables? Do I have to go back to autonumbering
instead?

Thanks,
Rachel
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      23rd Aug 2011
On Tue, 23 Aug 2011 07:16:24 -0700 (PDT), Rachel Garrett <(E-Mail Removed)>
wrote:

>Greetings,
>
>I have records which are identified by a unique naming system (up to
>six characters), and the numbering system changes each year. A key
>consisting of [number,year] would work as a primary key, and in Design
>View, I was able to shift-select two columns and make it the primary
>key in my table.
>
>Now that I've done that, how can I use this primary key in
>relationships to other tables? Do I have to go back to autonumbering
>instead?
>
>Thanks,
>Rachel


That's your choice. You can create two fields of matching datatypes and sizes
in your child tables, and join both fields in the Relationships window (drag
the number to the number, drag the year to the year, be sure both lines are
selected/dark, and check the Enforce Referential Integrity checkbox; if you
desire to do so, also check the Cascade Updates and/or Deletes).

You can also use two fields (or ten for that matter) in the Master/Child link
fields of a Subform.

Alternatively, you can just put a unique Index (not a primary key) on the two
fields, add an Autonumber as a primary key, and link it to Long Integer fields
in your child tables.

This can be a contentious issue among Access developers - some folks always
use an Autonumber, others will use a "natural key" such as you describe, and
some have strong opinions about the advantages of the two approaches. I use
both. I'll admit that maintaining multifield joins can be a hassle, but it
does have the advantage that you can display the year/number in Reports based
on child tables without the overhead of a join.
--

John W. Vinson [MVP]
Microsoft's replacements for these newsgroups:
http://social.msdn.microsoft.com/For...-US/accessdev/
http://social.answers.microsoft.com/.../en-US/addbuz/
and see also http://www.utteraccess.com
 
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
creating columns out of two columns in excel dan3959 General 1 2nd Jul 2009 02:42 AM
ListView and columns consisting of icons Alexander Vasilevsky Microsoft Dot NET Framework Forms 0 3rd Jan 2008 09:25 AM
ArrayList consisting of objects =?Utf-8?B?WlM=?= Microsoft C# .NET 5 15th Sep 2006 04:33 AM
creating a webcontrol consisting of server controls tolisss Microsoft ASP .NET 1 12th Nov 2005 06:14 AM
Pivot Table Creating New Columns that Subtract Two Existing Columns den4673 Microsoft Excel Misc 3 17th Dec 2004 01:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:56 PM.