Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > AutoNumber Good Bad < Sync Remote | Odd or Even >
Back to AutoNumbers Good or Bad?    Comments List
Upload Images   @Reply   Bookmark    Link   Email  
Replace Keys with AutoNumbers
Thomas Gonder 
        
3 years ago
Let's say there are four tables that are Entity, Cntry, Regsub, Regn. Each is the "parent" to the other, i.e. there is a foreign key in Entity that points to table Cntry. Cntry has a foreign key that points to Regsub, Regsun to Regn.  At present there are relationships between all four tables. Only the Entity table uses autonumber at present.

If I want to add autonumbers ids to Cntry, Regsub, Regn, what steps do I have to do? I don't yet get SQL or the queries. Got a TechTip on something like this? When we're done, the foreign keys should be the new autonumber, and not the old ISO code which is at present the primary key.
Richard Rost  @Reply  
          
3 years ago
I would need to know more about the relationships between these tables. What are they? The names aren't very meaningful. Are they one-to-many relationships? For example: Customers to Orders to Order Details to Products. Four tables. Each has a primary key and the last three have a foreign key pointing to the parent. Watch Relationships.
Richard Rost  @Reply  
          
3 years ago
If you're trying to say that the other tables have a NATURAL KEY (like a vendor part number, or phone number, or SSN - something that exists in the real world) that is being used for the relationship, then you could just add an AutoNumber field to the parent table, add a Long Int as a foreign key to the child table, and then use an Update Query to copy that info. If that's where you're going, then yes, that would make a cool video. I've had other students ask me about this before. I'll add it to the list.
Thomas Gonder OP  @Reply  
        
3 years ago

Thomas Gonder OP  @Reply  
        
3 years ago
Sorry, I just saw that I could attach an image. So what we want to do is add an autonumber to an existing table that doesn't have an autonumber. then repeat for two other tables. I'm not sure of the order to do things or how:
1) add an autonumber to the Cntry table (Country)
2) change the foreign id (BirthCntryId) in the Entity table from the old Id to the new autonumber id now found in the Cntry table.

Then we repeat adding an autonumber to RegSub and change RegnSubId in the Cntry table to the new autonumber id.
Then we repeat adding an autonumber to Regn and change  RegnId in the RegnSub table with the new autonumber id.

I'm wondering if we can build a query to do this, one for each parent file.
Kevin Robertson  @Reply  
           
3 years ago
Thomas Gonder OP  @Reply  
        
3 years ago
To understand an example of the hierarchy,
Entity John (AID = 15) was born in Canada (ISO cd and the ID in Cntry = 124).
Canada is part of North America (ISO cd and Id in Regnsub = 21)
North America is part of the Americas (ISO cd and Id in Regn = 19)

All of the primary key ids (124, 21, 19) are going to remain as data columns in their respective tables, but we will change the foreign ids to the new autonumber primary keys.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in AutoNumbers Good or Bad?.
 

 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2025 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/22/2025 5:56:57 PM. PLT: 1s