Re: Content of Foreign Key

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm going to jump in here and hope that I don't rile the waters. The
correct order is to create the structure (including relationships), then add
the data. Relational databases start with tables and relationships. Forms
are the user interface.

To stress a point that has already been mentioned, if you are using an
autonumber PK (primary key) in Orders, put the field into the Orders table,
put a corresponding Number field into the Order Details table, create the
relationship between the two fields, then forget about it. Every time you
use a form to create a record for an Order it will have a unique autonumber
PK. Every record you create in the corresponding subform will have that
same number in the related field.

Do what you wish for naming fields, tables, etc., but it helps to be
consistent. I would call an Orders table tblOrders. A query based on that
table would be qryOrders, the form would be frmOrders, and so forth. With a
nod to Albert, who has provided endless valuable advice to myself and others
in this forum, I prefer to stay away from generic field names. I would tend
to use OrderID as the name of the PK field in tblOrders, and would also use
OrderID as the name of the related field in tblOrderDetails.
tblOrderDetails may have its own ID field, which needs to be a different
name than any other field in that table. I find it easier to create
relationships between fields with the same name. That's just how my brain
seems to be wired.

Using the naming scheme I have outlined, if the PK for an Order record is
123, every correspondig record in the Order Details will have 123 in the
OrderID field. Every record in OrderDetails with 123 in the OrderID (child)
field will be related to one and only one record in tblOrders. One common
example of how this works is with payroll. If you have an EmployeeID number
where you work, every payroll record for you will contain that number.
Those records will be associated with you and only you, because nobody else
has that same EmployeeID number. If your name changes, the old records will
be carried forward since they are associated with an unchanging number.

A word on junction tables, which are used in specialized situations. If you
are keeping track of students and courses, each student will take many
courses, and each course will be attended by many students. Therefore the
relationship between Students and Courses is many-to-many. You cannot
create a many-to-many relationship directly between two tables, so a third
table is needed to resolve the relationship. This third table (I will call
it tblEnrollment) is related to both the Students and Courses tables. I
don't think you need to concern yourself with that in your situation. Each
OrderDetail is associated with only one Order. With Parts you may want to
store the Part information in the OrderDetails table (the price, at least)
rather than linking to the Parts record, so there is probably no
many-to-many relationship. I mention this because junction table is a term
in common usage, and not to argue with Albert's point that the term can
become confusing. It is, after all, just another table.

"ffisher" <ffisher.1xi65p@xxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:ffisher.1xi65p@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> Thanks to Albert and John,
> Reading through both of your replies it seems the approach is to create
> a form to fill in the information from the PK into the FK.
>
> First I will add data to the tables then create my relationships and
> then create the form.
> I assume this is the correct order of working.
> Thanks.
> ffisher
>
>
> --
> ffisher


.



Relevant Pages

  • Re: Prolems in Mathematics Education
    ... mathematics courses, and claim to have taken a calculus course in high ... Most local students taking AP Calculus do not bother to actually ... they are put into one of our basic math ... Our university college dean (Ed.D. ...
    (sci.math)
  • Re: Sarah Palin- creationist VP candidate?
    ... there will be many high school students ... mathematics is, for whatever reason, necessary for higher learning. ... algebra-free statistics courses have given very poor results, ... is quite bright) was unable to pass high school algebra, ...
    (talk.origins)
  • RE: VBA or SQL
    ... subquery that lists classes attended and entering the IIF's into the ... Req5 Leading High Performing Teams Simulation ... students and the classes needed. ... attended courses whether they are required or not). ...
    (microsoft.public.access.modulesdaovba)
  • Prolems in Mathematics Education
    ... mathematics courses, and claim to have taken a calculus course in high ... yet place into our Intermediate Algebra (basically an Algebra I ... Most local students taking AP Calculus do not bother to actually ... Our university college dean (Ed.D. ...
    (sci.math)
  • Re: School Grades/Levels in the UK
    ... >> you have 'finished' or 'graduated from' high school. ... Typically students 17/18 can take AP classes ... AP level courses are meant to be substitutes for university level ... because colleges and universities use these exams to help them determine ...
    (alt.fan.harry-potter)