Access 2007-2019
Access 2000-2003
Access Seminars
TechHelp Support
Tips & Tricks
Access Forum
Course Index
Topic Glossary
Insider Circle
Home   Courses   Seminars   Templates   Help   TechHelp   Forums   Contact   Join   Order   Logon  
Access Foreign Keys & Space
By Richard Rost   Richard Rost on Twitter Richard Rost on LinkedIn Email Richard Rost   14 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 right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.

You may want to read these articles from the 599CD News:

12/3/2021Access Beginner 2
12/3/2021Access Beginner 2 Lessons
12/3/2021Access Beginner 2
11/30/2021Import Multiline Cells
11/30/2021Adam's Access Games
11/29/2021Prevent Close
11/22/2021Currency Symbols
11/13/2021Access Developer 36

Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Account Login
Online Theater
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
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn
Keywords: access index id tips  PermaLink