Foreign Key To A Table With Multiple Primary Keyfields???

May 30, 2005

I`m designing a database in MS Access '97.

A lot of the tables I`m using have multiple primary key fields.

How is it posible to create one relationship between 2 fields in table A and 2 primary key fields in table B and force integrity?

thx in advance

View Replies


ADVERTISEMENT

Tables :: One Primary Key To Multiple Foreign Keys In The Same Table?

Aug 29, 2013

Right now, I have 4 related tables. There's a table with companies, one with people involved with companies, a table linking the two by having foreign keys of the company number and people names, and a table that indicates directors and their alternates.

Since there's a one-to-many relationship for companies/people to company-peopleID (A person can run multiple companies, a company has multiple directors, it's easier this way), a person's name can appear multiple times, as can a company, within that table.

In a company, a director may or may not have 1 and only 1 alternate director to him/herself. So, I thought the easiest way was to put an autonumber in the Company-personID table and have a table (alternates) that had two fields, "alternate" and "director", both using that autonumber to link them. However, it appears as though I can't link the same primary key twice to two foreign keys of the same table.

[URL]

View 3 Replies View Related

Forms :: Primary Key As Multiple Foreign Keys In Single Table

Mar 26, 2013

I'm developing a simple sporting records db. I have a 'Competitor' table listing competitors as follows: CompetitorPK, Name, Division, Club. I have a 'Contest' table listing contests as follows: ContestPK, Competitor1_FK, Competitor2_FK, Winner_FK, Score etc. My question is have I modelled tables correctly i.e. CompetitorPK will appear in three columns of Contest table. How do I define this relationship? What alternative is there to what I have done.I intend to use forms to populate both tables (independantly obviously).

View 4 Replies View Related

One Primary Key + Multiple Foreign Keys...help Creating Form With Option

May 4, 2006

I need some help creating a simple datebase to store my documents and other knowledge objects. There are two types of

knowledge objects I need to store: Documents and Questions/Answers. For this reason I have created three tables: Index,

Question, and Document.

The problems I am encountering is that the ID field in the Index Table is the Primary and relates to the ID field in the

other two tables. So basically when I am entering information it can either be a question or document. I want to create a

for so that when its a question that I am entering it records the information in the question table and when its a document

I am entering it records the information in the document table.

I'm a beginner at using access and don't know VB or SQL. Any help would be appreciated.


Table Structure

Index Table
ID (Primary Key)
Link
Type
Source
Reference

Question Table
ID (Foreign Key)
Question
Answer

Document Table
ID (Foreign Key)
Title
Summary
Notes

View 1 Replies View Related

One Primary Key In One Table Linked To Two Foreign Keys In Two Different Tables!!!

Sep 22, 2007

Hi there,

I am trying to model my database to create relationships between different tables in my database. During the process of doing so I ended up having one primary key in table A linked with to foreign keys in two different tables ( table B & table C) and both of those two table are junction tables to break out many to many between many other tables

Now for some reason!!! I feel that there is something wrong with my logic mapping and modeling of the relationships between tables due the fact of having one primary key linked to two foreign keys in two different tables :(

Is my intuition is right? should such case be considered as indicative of wrong modeling of relationships between tables in a single database
And if so what is the disadvantages of that link (talking down the road) when the database if fully populated? :confused:

By the way I am new member and new to database, so please take it easy on me :o

Many thanks

View 2 Replies View Related

Possible For Primary Key Of One Table To Act As Foreign Key In Another Table For More Than One Columns?

Nov 7, 2012

Is it possible for the primary key of one table to act as the foreign key in another table for more than one columns? What I'm trying to do is create a table for a Committee which will have 1 student and 5 professors! So Can I import the faculty ID for each of the 5 faculty members?When I try creating the second relationship, access automatically creates a new Faculty table for the relationship!

View 6 Replies View Related

Foreign Key And Primary Key

Apr 12, 2008

it wuld be helpful if any of u can tell me how to link tables to query using primary key and foreign key or web page where i can solve my problem.

View 1 Replies View Related

Foreign Key/Primary Key

Jun 6, 2005

Hi All, Me Again :eek:

I have another issue that has stumped me:

On the mainform [frm1930Census] I have a couple of subforms [sbf1930CenHeader & sbf1930CenDep]

The primary key [FTMID] has passed from the mainform to the 1st subform [sbf1930CenHeader] correctly. Using the one to many relationship attached by the [FTMID] field.

The problem is the primary key [1930CenHdrID] from the subform[sbf1930CenHeader] should then travel to [sbf1930CenDep] which it does not. The relationship between the two subforms are one to many focusing on the [1930CenHdrID] field/

I am using the following code:

Private Sub Ctl1930CenHdrID_BeforeUpdate(Cancel As Integer)
Me.1930CenHdrID = Forms![frm1930Census]![sbf1930CenHeader].[Form]![1930CenHdrID]
End Sub

Any help will be most appreciated.

~VanEpps

View 1 Replies View Related

Tables :: Create Primary Key From Foreign Key?

Sep 24, 2012

I have two tables tblPatients (pkUMRN) and tblAdmissions (pkAdmissionID, fkUMRNAdmission). pkUMRN is not auto-number, but is an 8-digit alphanumeric code unique to each tblPatients record. I have set up a one-to-many relationship between tblPatients_pkUMRN and tblAdmissions_fkUMRNAdmissions (each patient can have multiple admissions).

Is it possible to allow the entry of a new tblAdmissions_fkUMRNAdmissions to create a new tblPatients_pkUMRN? IE can you create a new primary key from a new foreign key?

Along a similar line, if the primary key already exists, how would you autofill a form with data from tblPatients when the tblAdmissions_fkUMRNAdmissions is entered in to the table?

View 6 Replies View Related

Forms :: Populating Form2 Foreign Key Control With Primary Key From Form1

Sep 11, 2014

I am trying to get the Primary Key value from one form to auto-populate the foreign key value of a second form

I have tried the following code in both the second form's Load Event and the Foreign Key Control Got Focus Event but nothing doing...

Me.[NHS Number] = Forms![frm_Patient_Data_Entry]![NHS Number]

I am new to VBA so not sure of the referencing technique but have looked at the MVPS Form 'referencing' sheet to no avail.

I keep getting an error message (2450) MS Access cannot find the referenced form "frm_Patient_Data_Entry"

I have checked spelling throughout countless times so there must be something wrong with my referencing I guess.

View 2 Replies View Related

Tables :: Multiple Parents Table Linked To Child Table - Primary Keys

May 28, 2015

I have a table for a multiple parents linked to a child table. I need to figure out a way to only allow 1 parent to be coded as primary, 1 as secondary, and then the rest as other... I thought about making Primary/Secondary/Other a primary key. But then I can only have 1 other. I would have to make a finite number of parents that could be entered and I want an infinite number.... My end goal is to have a report that only has a primary and second parent on it, but the rest of the parents still exist in the table...

*Child_ID
Parent_First_Name
*Primary/Secondary/Other

View 8 Replies View Related

Add Multiple Fields In Same Table With Same Primary Key?

Oct 24, 2012

How do I add multiple fields in the same table with the same primary key?

For example I have an employee with the employee ID 1 named john. He has two degrees. One in Math the other in science. I need to have both of these incorporated into my table.

View 3 Replies View Related

Create Relationship Between Multiple Field Primary Key And Another Table?

Aug 4, 2015

In table 1 fields Factor, Aggregations, Stat, and Days Back are fields that make up a multi-field primary key [URL].

I want to create a relationship between that multi-field primary key and another table, call it table 2, and make it a one-to-one relationship.

How do I do this in MS Access 2013?

View 3 Replies View Related

Avoid Multiple Entry For Foreign Key?

Sep 8, 2014

I have a master to child table relation which is one to many. Each one is represented by a different form.

The problem is, the user enters the primary key "JobID" on the master form, then he needs to enter a few records on the child list with the same "JobID" which is the foreign key in that case. I don't want the user to enter the "JobID" every time he enters a new record in the child form.

Is there a way I can copy the primary key to the foreign key each time the user enters a new record in the child form?

View 2 Replies View Related

General :: Avoid Multiple Entry For Foreign Key?

Sep 8, 2014

I have a master to child table relation which is one to many. Each one is represented by a different form.

The problem is, the user enters the primary key "JobID" on the master form, then he needs to enter a few records on the child list with the same "JobID" which is the foreign key in that case. I don't want the user to enter the "JobID" every time he enters a new record in the child form.

Is there a way I can copy the primary key to the foreign key each time the user enters a new record in the child form?

View 8 Replies View Related

Two Foreign Keys In One Table.

Apr 20, 2006

I'm not new to access, and I understand normalization at pretty much all its levels, but right now I'm curious about a situation that I have just come across. The first time I've been in something like this, so I thought I would ask.

This is the setup.

I have employees. They are apart of a shift and a budget. Shifts and budgets are completely independent of each other.

The database needs to keep track of shifts and budgets over time. Therefore, 1 to many relationship to shift table and budget table.

But, the database also needs to keep track of attendance. And the user wants attendance tracked by Shift and Budget.

Shift and budget are completely independent of each other.

Currently, I have the relationships set up like this.

Employee (1) ---(Many) Budget (1)------(Many) Attendance
Employee (1) ---(Many) Shift (1)--------(Many) Attendance

When a new attendance record needs to be added, both the key to the budget and shift are added to the attendance table. The key chosen is dependant onthe Employee chosen, and whether the budget and shift are the CURRENT budget and shift that the employee is apart of.

I thought of running a query showing budget and shift by date descending, so that the latest budget / shift would be displayed, and thus the most current (SUPPOSEDLY) But, if a user put in a different date, or screwed up on the date, then the incorrect shift and/or budget would be displayed.

Date stamping an entry was an option, but there needed to also be a user entered date as well, to specify WHEN a user began working in that specific budget / shift. Therefore two date entries would be required. Duplicate entries in most cases.

I therefore decided to go with a true/false yes/no checkbox. Where the current budget or shift would be checked, and all non current ones would be unchecked (false).

Currently, this is how the systems works. And it works well. But it is dependent on some form code I created to set the yes/no checkbox to true/false depending on the situation.

I DON"T like doing this. Am I missing a way to do this "correctly" where by Access would do this "automagically" instead of via my trick.

The ONLY issue really, is that when a new attendance incident occurs, the user needs to put in the incident to the approbriate shift / budget. And if the current shift / budget could automatically be displayed without user intervention (IE user has to pick the shift / budget from drop down box after looking up info etc etc) since the current information SHOULD be known.

I've never done a table setup where two foreign keys are the many side of the relationship in a single table.

It is currently working fine, and seems to do well, but I wanted to make sure with others who might have had this experience. And also, any "advice" / "cautions" for this kind of situation so I don't step into it deep and have to fix it later.

View 14 Replies View Related

Table With Two Foreign Keys?

Oct 5, 2015

Can a table have two foreign keys?

View 1 Replies View Related

Using Foreign Key To Get Related Values From One Table Onto Another Table?

Sep 25, 2013

I created 2 table that are linked to a link table so to get a many to many relationship.I have a table for locations and a table for parts.One location can have many parts and One part can belong to many locations, that is way the many to many relationship.

how to get values from the parts table to the Location table using the linked Primary Key in the foreign key linked field.The values also have to be interactive, if I change the value in the part table it needs to update in the location table.

What can I put in the field of the location table to get a specific value from the parts table?

I tried setting the field to calculated field and put the Dlookup function but that didn't work. The lookup wizard seems to be the solution, but I can only create combobox or list box and I need to select the value manually. I just need a value to be put automatically by looking at the foreign key.

If I put the Dlookup function on the default value, those it update if a value is changed in the part table?

View 3 Replies View Related

Link Replication ID As Foreign Key Within Different Table

Oct 2, 2014

How would one link a replication ID as a foreign key within a different table as they aren't numbers and not quite text?!

View 8 Replies View Related

Forms :: Select Recordset ID For Inclusion As Foreign Key In Table

Jun 17, 2014

Trying to use a form based on a table to choose a recordset of values, and pick the ID of that recordset to include in another table as a foreign key.

I am not sure how to even search for what I'm trying to do, though I've tried all the variants I can think of anyway.

The idea being that there are a set of values that are associated with each other, and generally found in conjunction with another set of data. So Table 1 contains data such as this, though this is greatly simplified from the numerics that are actually stored in these fields:

FooID Field 1 Field 2 Field 3 etc, etc...
1 x y z
2 d y z
3 x y q
4 x r P
.
.
.

This data is then associated with the information in table 2, and rather than repeat fields 1-whatever in table 2 I want to use the FooID in table 2 to store the link to all of the subsequent field data. Normalization as I understand it in other words.

I cannot figure out how to pull the table 1 data into a datasheet form and allow someone to choose one of the lines of data, store the FooID into an unbound text box, or some other method, and then run an update query on table 2 to update a field with the FooID for the 12-72 records that are in that table.

Would this make more sense as a combo box in a single form? I've been trying to do this with a datasheet, but I think I'm too limited in appending a check box to an individual recordset this way, or at least I've not managed to get it to work so far anyway.

View 2 Replies View Related

Multiple Primary Keys

Feb 28, 2005

I made a database that was working fine. It was only after I had finished the database, and data was being entered, that I was informed that the field I designated as the primary key would not work. Origanally, I used 'OffCit' as the single primary key. Now they tell me that one 'OffCit' can be entered several times for different reasons. To solve this, I thought about using autonumbers but have been told, and seen, that this may not be a good idea. So, I am trying to use multiple primary keys. So far I have had no luck. I have attached a screen shot of the tables and relationships. I have 'OffCit', 'AreaofLaw', and 'EffectiveDate' as the primary keys. The same 'OffCit' and 'AreaofLaw' will be used several times in different records. That is the reason for the third primary key. I am wondering if I have set this up right or if there is something I overlooked. Perhaps someone has an idea that may work better. Thanks for any input.

View 5 Replies View Related

Should I Use Multiple Primary Keys?

Sep 13, 2005

I have the following table:
YieldID |ProductID | Year | Month| Yield

I want to make sure that it is not possible to insert the same date (so, year and month together) twice for each productID. But at the other hand, it should be possible to insert the same date but then for different productIDs. How can I make sure that Access does this? Can I use (multiple) primary keys to enforce this?
Thank you,
Stacey

View 7 Replies View Related

Multiple Primary Keys?

May 21, 2006

Hi

I have tried searching the forums, but couldn't locate any relevant information. I have an assignment at the moment and am meant to have 8 tables in my data base, two of which are 'User' and 'Hardware' which have the following fields:

USER:
UserCode (Primary Key)
UserFirstName
UserLastName
DepartmentCode

HARDWARE:
HardwareCode (Primary Key)
HardwareName
VendorCode
PurchaseDate

Now I am meant to have another table called 'Hardware Config' consisting of the Primary Key fields from the two tables above, and they are both meant to be Primary Keys in this table.

I have been able to make the 'Hardware Config' table, but I don't know how to make more than one Primary Key... any ideas?

Thanks in advance - dragonfly :o

View 13 Replies View Related

Help With Multiple Primary Keys

Oct 6, 2007

I have a table that has the following fields: Symbol, DeliveryMonth, DDate, Close. This table has information for a large number of different commodities. I am hoping to run a query against the table and find breakouts. I am working on the actual query but my question is this: If I have only one table do I need to have a primary key? There will be no relationships established so what is the need for a primary key unless you plan to link tables together? If it is always a good idea to have a primary key then I will have to have the Symbol, Delievery Month and the DDate together be the key since without all three there would be duplicates. Each symbol has many different deliveryMonths, each DeliveryMonth has many symbols, and each date has many Symbols. SO it takes all three together to get a unique value. Will having a primary key in this scenario help me with writing queries? I appreciate all of your wisdom in explaining how this table should be organized. Thanks:)

View 1 Replies View Related

Multiple Primary Keys

Jul 9, 2006

Looking at a database that someone wlse has created I see that numerous tables have mulitple primary keys. How is this possible? If i try and allocate a primary key it will only let me do it for one field.

I think what I actually want to do is create composite keys but if I set the key then put it to duplicates allowed it says that the primary key is not allowed. Am I mixing up indexes and keys???
How do you assign a composite key

View 1 Replies View Related

Multiple Primary Keys

Mar 21, 2013

I have a table where each record is unique if at least one of three variables is different. The three variables in my case are each integers and are: YearRouteSegment.

Now each of these individual variables allows (and has) duplicates, but if the thing is working right, no pair of records in this table should have all three of these variables with identical values. Is this table a candidate for using multiple primary keys?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved