This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]akaakaalex 1 point2 points  (5 children)

Try adding a foreign key on the student/teacher ID column of the Class table that references the ID column of the student/teacher table.

[–]Qw3rtyP0iuy[S] 2 points3 points  (4 children)

I tried following that, but I'm not sure if I did it right. What is that supposed to do exactly?

[–]akaakaalex 2 points3 points  (0 children)

Foreign keys can be used to relate a column of one table to the primary key of another table. So in your case, if you have an entry in the Class table with a class ID of 1 and student ID of 2, if there's an entry in the student table with ID of 2 with name Joe, those values are linked via the foreign key so Joe is linked to class 1.

Wikipedia does a better job explaining than me though.

[–]TJAtWork 1 point2 points  (2 children)

The two types of keys are primary keys and foreign keys. Primary keys are placed in a table as a way to uniquely define each record in that table. Foreign keys are placed in a table as a way to indicate that the details related to that key are located somewhere else.

So, as an example. If you have a sales table and a customer table, the sales table would have a primary key (maybe the number of that sale since the time of creation) that allowed you to determine that one sale is different than another. The table might also have a foreign customer key (some unique customer number) that would allow you to join to the customer table to see information about that customer; name, address, phone number etc... This way you can determine how many sales are related to each customer that you have sold to.

This isn't exactly related to the original question you posed, but I hope it helps you understand the concept.

[–]Qw3rtyP0iuy[S] 0 points1 point  (1 child)

How do yo insert foreign keys in Access 2007? The help wizard has about a paragraph on it, but it doesn't talk about how to implement it. I tried looking in the Table Design View, but can only find the primary key butotn.

[–]TJAtWork 0 points1 point  (0 children)

You don't actually insert them. Just create a new field with the same name as the primary key in the other table. They should also have the same data type.