Free Lessons
Fast Tips
Topic Index
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
Access Foreign Keys & Space
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   17 years ago

Here's another GREAT question from a customer:

First of all, I now have a small business going as a database developer, and a large part of the credit goes to Richard. Excellent classes! But one question. I think you sometimes use IDs as primary keys in tables unneccesarily. For example, you showed a table of payment types, where you had an ID field and a payment type field. Wouldn't it be better just to have the payment type field only, and make it the primary key? Payment types will be unique, and then when you need the payment type in a query, you don't have to tie in the payment type table just to get the description, since the payment type will be stored as the foreign key in the other table, for example, the orders table. Please keep the Access classes coming!

It's certainly possible to create tables without keys. Personally, I prefer to use an ID field in almost every table because it keeps things clean and easy - and can save space in your database.

Let's take Payment Type for example. Let's look at two tables. The first one has IDs, and the second one doesn't.

1 - Visa
2 - MasterCard
3 - Discover
4 - American Express

Now in the second table, there's no ID to refer to the payment type, so for each customer's order where I have to track the payment type, their ORDER TABLE now has to have the full text of the payment method in it.

What takes up less space in your database:

1001, Joe Smith, American Express
1002, Sue Jones, MasterCard
1003, Bill Watson, American Express
1004, Adam West, American Express

Or this (assuming you use a CustomerID and PaymentID):

1001, 1, 4
1002, 2, 2
1003, 3, 4
1004, 4, 4

See? The space savings alone in a large database make it worthwhile. If you have 10,000 orders, you'll save multiple megabytes worth of space. And remember, a small database is a fast database.

ALSO, using IDs keeps your VBA code cleaner. What's easier:

X = DLOOKUP("Info","PaymentT","PaymentID=" & ID)


X = DLOOKUP("Info","PaymentT","PaymentType='" & PaymentName & "'")

Gotta put those single quotes (or two double quotes) around those string values - I hate working with string value.

So there ya go. Really it's just to keep the database tight and efficient, but there are lots of reasons why it's best to use an ID for every table - even if you don't think you'll need it.

Hope this helps.

Start a NEW Conversation
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
Subscribe to Access Foreign Keys & Space
Get notifications when this page is updated

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

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

Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 7/19/2024 7:38:24 AM. PLT: 0s
Keywords: access index id tips  PermaLink  Access Foreign Keys & Space