Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update foreign key in main table

Status
Not open for further replies.

VBVines

MIS
Jun 11, 1999
98
US
I have a main table(PC) with foreign keys from several tables such as Staff, OS, Devices. If I run an insert statement that adds a record to each of the tables, I know that the primary key/identity key for each table will be incremented. How do I get this new value to be reflected in the foreign key column of the main table. Is this what will happen if I check the "enable relationships for inserts and updates box on the properties sheets of the relationship diagram. thanks

aspvbwannab
 
Not sure what you are asking. Can you give an exaple of some tables and there structures and what you want to do? And what do you mean by update the FK in the main table? Do you mean you want to Insert a row into the main table afer you insert into the related tables.
 
First thanks jbenson001 for getting right back to me.
I have a table called staff with the following fields

Staff_ID (primary Key)
Fname
Lname
email_add
active

I have another table that has a column called
staff_id which is a foreign Key to the staff table

If I insert a new record in the staff table the primary key increments. My question is, how is the increment reflected in the table with the foreign key in it.

If I add Jerry Cantrell to the staff table the Primary Key increments by one. Later I query the other table for Jerry Cantrell. Will I get anything back?

Is this what you use the "enable relationships for inserts and updates box on the properties sheets of the relationship diagram. Does this checkbox ensure that foreign keys are updated? thanks



aspvbwannab
 
What do you mean by how will it be incremented? If you insert into Staff, a new row will be created.
Ex
123, John, Smith, something@aol.com, 'Y'

123 is the autogenerated primary key for this new row.

What do you expect to happen? Noting is Inserted into your FK table unless you specifically do an Insert or you create an Insert Trigger to do it.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top