PC Review


Reply
Thread Tools Rate Thread

custom primary key using multiple fields

 
 
=?Utf-8?B?REdyZWdn?=
Guest
Posts: n/a
 
      31st Oct 2007
I would like to create my own primary key using a concatenation of existing
fields:
eventnumber & date & time.
How do I go about doing this?
Any help is greatly appreciated. Thank you in advance.


 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      31st Oct 2007
Why? Access is capable of using a primary key that's comprised of up to ten
separate fields.

Concatenating values into a single field is rarely a good idea.

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


"DGregg" <(E-Mail Removed)> wrote in message
news:BD804869-FD9D-473C-826B-(E-Mail Removed)...
>I would like to create my own primary key using a concatenation of existing
> fields:
> eventnumber & date & time.
> How do I go about doing this?
> Any help is greatly appreciated. Thank you in advance.
>
>



 
Reply With Quote
 
=?Utf-8?B?REdyZWdn?=
Guest
Posts: n/a
 
      31st Oct 2007
Thank you for your response. Perhaps I'm wording this incorrectly. I would
like to create a primary key (separate field, of course) that is comprised of
data in 3 existing fields: EventNumber, Date, Time. I'm not sure how to go
about doing this.

"Douglas J. Steele" wrote:

> Why? Access is capable of using a primary key that's comprised of up to ten
> separate fields.
>
> Concatenating values into a single field is rarely a good idea.
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "DGregg" <(E-Mail Removed)> wrote in message
> news:BD804869-FD9D-473C-826B-(E-Mail Removed)...
> >I would like to create my own primary key using a concatenation of existing
> > fields:
> > eventnumber & date & time.
> > How do I go about doing this?
> > Any help is greatly appreciated. Thank you in advance.
> >
> >

>
>
>

 
Reply With Quote
 
=?Utf-8?B?SmVycnkgV2hpdHRsZQ==?=
Guest
Posts: n/a
 
      31st Oct 2007
What Doug said.

I'll add that multi-field primary keys can be a PITA to maintain. If you
have a two-field PK, then you need a two-field foriegn key in related tables.

IMHO you are better off using an autonumber as the primary key and making
the two fields a unique index / constraint to prevent duplicates.

One other thing: Date and time should be in just one field. Again IMHO.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"DGregg" wrote:

> I would like to create my own primary key using a concatenation of existing
> fields:
> eventnumber & date & time.
> How do I go about doing this?
> Any help is greatly appreciated. Thank you in advance.
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      31st Oct 2007
If you're doing it through the GUI, open the table in Design view and select
all of the fields of interest (using the Ctrl key if they're not
contiguous). Then, click on the Key button on the Button Bar (or select
Primary Key from the Edit menu)

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


"DGregg" <(E-Mail Removed)> wrote in message
news:31FCCD92-ADBF-430B-85EE-(E-Mail Removed)...
> Thank you for your response. Perhaps I'm wording this incorrectly. I
> would
> like to create a primary key (separate field, of course) that is comprised
> of
> data in 3 existing fields: EventNumber, Date, Time. I'm not sure how to
> go
> about doing this.
>
> "Douglas J. Steele" wrote:
>
>> Why? Access is capable of using a primary key that's comprised of up to
>> ten
>> separate fields.
>>
>> Concatenating values into a single field is rarely a good idea.
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "DGregg" <(E-Mail Removed)> wrote in message
>> news:BD804869-FD9D-473C-826B-(E-Mail Removed)...
>> >I would like to create my own primary key using a concatenation of
>> >existing
>> > fields:
>> > eventnumber & date & time.
>> > How do I go about doing this?
>> > Any help is greatly appreciated. Thank you in advance.
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?REdyZWdn?=
Guest
Posts: n/a
 
      1st Nov 2007
Douglas, thank you for your response. This did the trick.

"Douglas J. Steele" wrote:

> If you're doing it through the GUI, open the table in Design view and select
> all of the fields of interest (using the Ctrl key if they're not
> contiguous). Then, click on the Key button on the Button Bar (or select
> Primary Key from the Edit menu)
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "DGregg" <(E-Mail Removed)> wrote in message
> news:31FCCD92-ADBF-430B-85EE-(E-Mail Removed)...
> > Thank you for your response. Perhaps I'm wording this incorrectly. I
> > would
> > like to create a primary key (separate field, of course) that is comprised
> > of
> > data in 3 existing fields: EventNumber, Date, Time. I'm not sure how to
> > go
> > about doing this.
> >
> > "Douglas J. Steele" wrote:
> >
> >> Why? Access is capable of using a primary key that's comprised of up to
> >> ten
> >> separate fields.
> >>
> >> Concatenating values into a single field is rarely a good idea.
> >>
> >> --
> >> Doug Steele, Microsoft Access MVP
> >> http://I.Am/DougSteele
> >> (no e-mails, please!)
> >>
> >>
> >> "DGregg" <(E-Mail Removed)> wrote in message
> >> news:BD804869-FD9D-473C-826B-(E-Mail Removed)...
> >> >I would like to create my own primary key using a concatenation of
> >> >existing
> >> > fields:
> >> > eventnumber & date & time.
> >> > How do I go about doing this?
> >> > Any help is greatly appreciated. Thank you in advance.
> >> >
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?REdyZWdn?=
Guest
Posts: n/a
 
      1st Nov 2007
Thank you for your response, Jerry.

"Jerry Whittle" wrote:

> What Doug said.
>
> I'll add that multi-field primary keys can be a PITA to maintain. If you
> have a two-field PK, then you need a two-field foriegn key in related tables.
>
> IMHO you are better off using an autonumber as the primary key and making
> the two fields a unique index / constraint to prevent duplicates.
>
> One other thing: Date and time should be in just one field. Again IMHO.
> --
> Jerry Whittle, Microsoft Access MVP
> Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.
>
>
> "DGregg" wrote:
>
> > I would like to create my own primary key using a concatenation of existing
> > fields:
> > eventnumber & date & time.
> > How do I go about doing this?
> > Any help is greatly appreciated. Thank you in advance.
> >
> >

 
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
Primary key has multiple fields - Access 2007 Abay Microsoft Access 4 15th Jun 2009 02:52 AM
writing primary key when multiple fields =?Utf-8?B?U2xhcHB5?= Microsoft Access VBA Modules 6 5th Mar 2007 01:44 PM
Prevent Duplicate Records in table with multiple Fields as Primary =?Utf-8?B?U3JlZWRoYXI=?= Microsoft Access VBA Modules 7 7th Aug 2006 06:22 PM
Composite Primary Key or Unqiue Index Compose of Multiple Fields Eric Microsoft Access Database Table Design 1 16th Dec 2003 05:15 AM
Primary key fields comprised of multiple columns in a datagrid Stephen Vanterpool Microsoft ADO .NET 0 22nd Sep 2003 03:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:35 AM.