creating foreign key

V

VTM3

I have several simple tables made with autonumber fields (Primary key fields)
created automatically for each table. I have defined the relationships
between the tables as one-to-many.

Now the next step is to create foreign key fields in my 'many' table from my
'one' tables. Do I just copy the primary key columns from the 'one' tables
and paste them into the 'many' table?

Thank you

Vtm3
 
K

KARL DEWEY

You should not be working in tables but in queries or forms.
If you have set the relationship and selected Cascade Update Related Fields
and use a form/subform for primary/foreign as you add a record in the subform
that is related to the primary it will automatically insert the foreign key.
 
J

John W. Vinson/MVP

I have several simple tables made with autonumber fields (Primary key fields)
created automatically for each table. I have defined the relationships
between the tables as one-to-many.

Now the next step is to create foreign key fields in my 'many' table from my
'one' tables. Do I just copy the primary key columns from the 'one' tables
and paste them into the 'many' table?

No. That's not how it works and that's not what foreign keys are for!

If the Primary Key of the "one" side table is an Autonumber, you
should have a field in the "many" side table of datatype Long Integer.
You make this the foreign key by going to the Relationships window
(use the icon in table design view, it looks like three little
datasheets with lines between them).

Normally you would use a Form based on the "one" side table, with a
Subform (or subforms) for the "many" side. Use the autonumber
fieldname as the Master Link Field and the corresponding foreign key
fieldname as the Child Link Field properties of the subform. When you
have it set up like this, entering data into the subform will
automatically fill in the matching foreign key value. There's no need
even to see it, much less to type it in.

If you've defined relationships from autonumber to autonumber...
don't. That won't work, since you cannot control the value of the
autonumber, it will just be assigned the next available value, without
regard to how the data in the tables is logically related.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top