Relationships and Keys

F

forest8

Hi there

I've searched through the database and have read about Relationships,
Primary Keys, and Foreign Keys. But I am still having problems with my
database.

I currently have a database that has several tables. The primary table is a
list of students where their student number is the primary key. (StudentID),
In each table, there is an Access created ID which is an autonumber.


Each table has this StudentID and the ID included. If ID is the primary Key,
I can create a relationship but the link between all the tables is the
StudentID. I can't create a relationship based on the StudentID.

Thank you in advance for your help.
 
G

Gina Whipp

forest8,

Going to need to know a wee bit more information. All we know so far is
that you have a Students table, what are the rest of the tables? What are
you tracking, enrollment, attendence, grades...? You say , "I can't create
a relationship based on the StudentID.", but you don't say why you fell you
can't do that.

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
F

forest8

Sorry for the lack of information in the initial question. I've been
frustrated by my inability to create relationships.

When I try to create a relationship, I seem to be creating an
"Indeterminate" relationship. I can't create a one to one or one to many
relationship. I get "Intderminate" relationship.

I'm tracking enrolment, grades, adds/drops, etc. There is also a survey
based on how the students have rated their courses/teachers. As well, there
is a table which tracks the frequency and subject of any meetings between
student and teachers.
 
G

Gina Whipp

forest8,

Help me out... I have listed a few tables based on your description. What
am I missing and where/what are the Primary Keys and Foreigh Keys? ith that
I can lead you in setting up Relationships.

tblStudents

tblEnrollment

tblCourses

tblTeachers

tblSurvey

tblMeetings

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
J

John W. Vinson

When I try to create a relationship, I seem to be creating an
"Indeterminate" relationship. I can't create a one to one or one to many
relationship. I get "Intderminate" relationship.

You will get an Indeterminate relationship if you are joining two tables on a
field, and that field does not have a UNIQUE index in either table.

Ordinarily one would join from the Primary Key of the "one" side table in the
relationship, to a foreign key in the "many" side table. The Primary Key is by
definition unique, and Access will create a unique index on it for you.
Creating a relationship and enforcing referential integrity will automatically
create a non-unique index on the foreign key field for you.

It sounds like you either haven't established primary keys, or that you're
trying to join on some other field or fields.
 
F

forest8

Hi there

Yes. Those are some of my tables.



Gina Whipp said:
forest8,

Help me out... I have listed a few tables based on your description. What
am I missing and where/what are the Primary Keys and Foreigh Keys? ith that
I can lead you in setting up Relationships.

tblStudents

tblEnrollment

tblCourses

tblTeachers

tblSurvey

tblMeetings

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm




.
 
F

forest8

In my database, I have several tables. I tried to establish a relationship
between 2 tables first -- each has a primary key. When that failed, I tried
another two -- again each had a primary key.

Still the same result -- no matter which tables I use.
 
G

Gina Whipp

forest8,

Ummm, did you not see the rest of the post? You need to help me out here
and identify Primary Keys and Foreign Keys so we can help you. If there are
more tables then we need those also.

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
J

John W. Vinson

In my database, I have several tables. I tried to establish a relationship
between 2 tables first -- each has a primary key. When that failed, I tried
another two -- again each had a primary key.

Still the same result -- no matter which tables I use.

Details, details please!

Please post:

Table names
Name of the Primary Key field of each table (and it does show the key icon
next to the fieldname in table design view... right?)
Datatype of the Primary Key (maybe autonumber, maybe some other field type
you've chosen)
Name and datatype of the foreign key field


Note that datatypes and field sizes must match: an Autonumber primary key must
be joined to a Long Integer (non-autonumber!!!) foreign key.

If you would like, you could zip the database and email it to me; I'll be glad
to investigate and see if I can figure out why you can't create relationships.
Send to jvinson <at> wysard of info <dot> com - edit out the blanks and edit
in the punctuation.
 
J

John W. Vinson

John,

I have been trying to get them... Even helped out with one of my posts but
to no avail.

Sigh. Sounds like forest8 just wants to complain, not to solve his or her
problem. Not my loss!
 
F

forest8

Hi

I do appreciate all the help and advice I am getting from both you and Gina.
I am not complaining just seeking answers and hopefully understanding. This
is the first Access database I am creating with little experience in Access.

In my tblStudent (this is the table which includes all the student info),
there is ID (autonumber and Primary key), StudentID, Firstname, LastName,
Birthdate, EntryYear, Major.

In the tblGrades, the ID, StudentID, Course, Grade, Teacher, Mark1, Mark2,
Mark3, ActiveStudent. This time, StudentID is the PK, and I'm trying to link
this to the tblStudnt.

In the tblTeacher, the ID, StudentID, Teacher, Course, AverageClassMark.
(This time, TeacherID is the PK) and I'm tying to link this to the tblGrades
table.

In the tblCourse, the ID, StudentID, ClassEvaluation, NoStudentPass. (Here
I'm trying to link the student back to the tblStudent). Am I just doing this
wrong?

In the tblSurvey, the ID, StudentID, Teacger ID, ExpectationsofCourse,
Major, (there are variables which deal with different subjects such as rate
the instructor, materials used, teaching, tutuorials, lectures, etc.). Here
I'm not sure what the PK should be.

The thing is, if I can create relationships between these tables, I can use
this logic to fix all the relationships.

I am also trying to apply what advice you both have given me as I tried to
figure out what to do. Not ignoring any of the advice.

Thank you again!
 
F

forest8

An addendum to my last post. The ID in each table is an autonumber. All other
variables (if they're not dates which are in the data format or comments
which are I have designated as memo formats) are text.

The StudientID (text format) in the tblStudent is the primary key. The
StudentID is actually the primary key in all the tables except tblStudent
where the ID (which is an autonumber) is the PK.

What I want is to connect all the tables to the tblStudent. All students
only have a single Student number, but they may enrol in several courses (not
all the same). The teachers may teach the same course and not all all the
students so I wanted to link the teacher to the students in their classes.
Not all the students will be evaluating all the teachers (jut those who are
teaching them).

Students can repeat courses to improve their marks and as such can have more
than 1 teacher for a course which would be taken at different times and be
evaluated each time.

Students when they join the school are asked to complete a survey (their
results are linked to their StudentID and the first table). WHen they leave
the school, they're asked a post survey. Throughout their time at the
school, they may be asked a survey during the stay.

As I mentioned in my last post, if I can establish relationships between
these tables I believe I can fix all the relationships in my table.

Thank you in advance.
 
J

John W. Vinson

An addendum to my last post. The ID in each table is an autonumber. All other
variables (if they're not dates which are in the data format or comments
which are I have designated as memo formats) are text.

The StudientID (text format) in the tblStudent is the primary key. The
StudentID is actually the primary key in all the tables except tblStudent
where the ID (which is an autonumber) is the PK.

But you're joining - *NOT* on ID, which is the primary key and has a unique
index - but on StudentID, which is *NOT* the primary key and does *NOT* have a
unique index!

You need to either join on the PRIMARY KEY, or create a unique Index on
StudentID (which would make either ID or StudentID redundant and unnecessary).

Calling a field "StudentID" does not make it unique, and does not make it a
primary key.
What I want is to connect all the tables to the tblStudent. All students
only have a single Student number, but they may enrol in several courses (not
all the same).

That means that StudentID must *not* be the primary key of the Courses table.
That would mean that each student may take one, and only one, course; since
the primary key is by definition uinque.
The teachers may teach the same course and not all all the
students so I wanted to link the teacher to the students in their classes.
Not all the students will be evaluating all the teachers (jut those who are
teaching them).

That is not necessary. Each table must have *ITS OWN* primary key, independent
of any other table's primary key! The table of Courses must have a CourseID
that uniquely identifies that course; the table of Faculty must have a
FacultyID or TeacherID which uniquely identifies that teacher; you'll have a
many to many relationship between courses and students, so you'll need an
Enrollment table with a StudentID (which student is enrolled) and a CourseID
(which course is she enrolled in), *NEITHER* of which is the primary key of
the table!

Students can repeat courses to improve their marks and as such can have more
than 1 teacher for a course which would be taken at different times and be
evaluated each time.

Exactly. That's what a normalized table design - *with appropriate primary
keys, which you do not currently have* - will let you do. You'll have (almost
exclusively) one to many relationships between your tables.
Students when they join the school are asked to complete a survey (their
results are linked to their StudentID and the first table). WHen they leave
the school, they're asked a post survey. Throughout their time at the
school, they may be asked a survey during the stay.

So you need a table of Surveys, related one to many to a table of
SurveyResults, which is related many to one to a table of Students.
As I mentioned in my last post, if I can establish relationships between
these tables I believe I can fix all the relationships in my table.

You bet. Start by understanding what a primary key *is* - a unique identifier
for the records *IN THAT TABLE* - and making your relationships from that
field to (matching) foreign keys in the related tables.

If you have not already done so, study Crystal's tutorial in:


A free tutorial written by Crystal:
http://allenbrowne.com/casu-22.html

or

A video how-to series by Crystal:
http://www.YouTube.com/user/LearnAccessByCrystal

paying special attention to the chapter on Normalization.
 
G

Gina Whipp

forest8,

It's 1:30 AM where I am and I'm about shot so *later* today you will get a
more comprehensive answer tomorrow (provided no one else picks up my slack)
with a correction in your table layout PK's and FK's.

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
G

Gina Whipp

forest8,

I'mmmm back! I see John has given you some real good advice which includes
reviewing Crystal's video. I hope you have done so. I am REdoing your
tables and outlining PK's and FK's and proper relationships. and some notes.

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
G

Gina Whipp

forest8,

Below I have redone your tables and corrected your relationships. You seem
to under the impression that since your database is about Students every
table should have StudentID as a PK when that is not how relational
databases work, nor is that the case. Now if the below makes little or no
sense to you then I have posted some links after the tables which AFTER
viewing Cyrstal's video you need to read, save and read again. Tables much
like foundations to houses, if it's not right and you build the house...
it's coming down and so will your database!

Keep in my the below may need some tweaking based your your exact needs but
hopefully this will get you pointed in the correct direction.

tblStudents
sStudentID (PK-Autonumber)
sInternalStudentID (Text - This is the one used by the School)
sFirstName
sLastName
sBirthDate
sEntryYear
sMajor
sActive
etc...

tblStudentCourses
scStudentCourseID (PK-Autonumber)
scStudentID (FK-related to tblStudents:sStudentID)
scCourseID (FK-related to tblCourses:cCourseID)
scStudentGradeID (FK-related to tblStudentGrades:sgStudentGradeID)
etc...

tblStudentGrades
sgStudentGradeID (PK-Autonumber)
sgGrade
sgMark
etc...

tblTeacher
tTeacherID (PK-Autonumber)
tFirstName
tLastName
tCredentials
etc...

tblCourses
cCourseID (PK-Autonumber)
cTeacherID (FK-related to tblTeachers:tTeacherID)
cCourseName
cAverageClassMark
etc...

tblSurvey
sSurveyID (PK-Autonumber)
sSurveyName
sTeacherID (FK-related to tblTeachers:tTeacherID)
sCourseExpectations
etc..

tblSurveyDetails
sdSurveryDetailsID (PK-Autonumber)
sdSurveyID (FK-related to tblSurvey:sSurveyID)
sdMajor
etc...

Jeff Conrad's resources page...
http://www.accessmvp.com/JConrad/accessjunkie/resources.html

The Access Web resources page...
http://www.mvps.org/access/resources/index.html

A free tutorial written by Crystal (MS Access MVP)...
http://allenbrowne.com/casu-22.html

MVP Allen Browne's tutorials...
http://allenbrowne.com/links.html#Tutorials

Sample data models...
http://www.databasedev.co.uk/table-of-contents.html

You also need to be a wee bit more careful when selected field names and
here's why...
http://allenbrowne.com/AppIssueBadWord.html

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
F

forest8

Hi John

Thank you for the advice and the link to Crystal's tutorials. I am in the
process of reviewing both.
 
F

forest8

Hi John

Thank you for your help. Wanted to tell you that your assistance, I was able
to create relationships.

Thanks again.
 

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