dbTalk Databases Forums  

Changing Primary Key Value

comp.databases.ms-access comp.databases.ms-access


Discuss Changing Primary Key Value in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rafeek
 
Posts: n/a

Default Changing Primary Key Value - 09-02-2011 , 07:14 AM






I got an acquired table in which Primary Key data type is text and the key
is prefixed with letters DC followed by number strings, like DC520309391,
DC650725, DC10002 etc. I have 300+ records in the table and would like to
remove the prefixed DC from the Primary Key. How can I do this.

Thank you in advance.

Rafeek.

Reply With Quote
  #2  
Old   
Phil
 
Posts: n/a

Default Re: Changing Primary Key Value - 09-02-2011 , 08:06 AM






On 02/09/2011 13:14:52, "rafeek" wrote:
Quote:
I got an acquired table in which Primary Key data type is text and the key
is prefixed with letters DC followed by number strings, like DC520309391,
DC650725, DC10002 etc. I have 300+ records in the table and would like to
remove the prefixed DC from the Primary Key. How can I do this.

Thank you in advance.

Rafeek.


Assuming the field Name is MyField, do an update query and set MyField to
Mid(MyField, 3, Len(MyField) - 2).
This is starting at the 3rd letter/number, i.e. after the DC, then using all
the numbers to the end. If MyField is a primary key, duplicates will not be
allowed, but I assume if there are no duplicates in the original table, there
won't be any in the modified table.

Dont forget the result will be a text field, not a numeric field.

make sure you have a backup of the original table before you start.

HTH

Phil

Reply With Quote
  #3  
Old   
rafeek
 
Posts: n/a

Default Re: Changing Primary Key Value - 09-02-2011 , 04:36 PM



Great. Thank you very much, Phil.


"Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote

Quote:
On 02/09/2011 13:14:52, "rafeek" wrote:
I got an acquired table in which Primary Key data type is text and the
key
is prefixed with letters DC followed by number strings, like DC520309391,
DC650725, DC10002 etc. I have 300+ records in the table and would like to
remove the prefixed DC from the Primary Key. How can I do this.

Thank you in advance.

Rafeek.



Assuming the field Name is MyField, do an update query and set MyField to
Mid(MyField, 3, Len(MyField) - 2).
This is starting at the 3rd letter/number, i.e. after the DC, then using
all
the numbers to the end. If MyField is a primary key, duplicates will not
be
allowed, but I assume if there are no duplicates in the original table,
there
won't be any in the modified table.

Dont forget the result will be a text field, not a numeric field.

make sure you have a backup of the original table before you start.

HTH

Phil

Reply With Quote
  #4  
Old   
Tony Toews
 
Posts: n/a

Default Re: Changing Primary Key Value - 09-02-2011 , 04:40 PM



On Fri, 2 Sep 2011 15:14:52 +0300, "rafeek" <rafeek (AT) mymail (DOT) com> wrote:

Quote:
I got an acquired table in which Primary Key data type is text and the key
is prefixed with letters DC followed by number strings, like DC520309391,
DC650725, DC10002 etc. I have 300+ records in the table and would like to
remove the prefixed DC from the Primary Key. How can I do this.
Are there any child tables with that field as a foreign key? If so
you will need to set the Cascade Updates on for that relationship.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/

Reply With Quote
  #5  
Old   
Rafeek
 
Posts: n/a

Default Re: Changing Primary Key Value - 09-04-2011 , 12:18 AM



Thank you, Tony.
"Tony Toews" <ttoews (AT) telusplanet (DOT) net> wrote

Quote:
On Fri, 2 Sep 2011 15:14:52 +0300, "rafeek" <rafeek (AT) mymail (DOT) com> wrote:

I got an acquired table in which Primary Key data type is text and the key
is prefixed with letters DC followed by number strings, like DC520309391,
DC650725, DC10002 etc. I have 300+ records in the table and would like to
remove the prefixed DC from the Primary Key. How can I do this.

Are there any child tables with that field as a foreign key? If so
you will need to set the Cascade Updates on for that relationship.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/

Reply With Quote
Reply




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 On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.