tags:

views:

35

answers:

2

I have created a table called STUDENT which consists of Unique ID as the PRIMARY KEY along with other related attributes like Name, Addr, Gender etc....

Since I don't want to increase the table size of the STUDENT, I created a weak entity called ACADEMIC RECORDS which stores the previous Academic Records of the student.But in this table i have only created a PRIMARY KEY Unique ID which references the Unique ID of the student. and there is no other attribute in conjunction with Unique ID in the weak entity ACADEMIC RECORD Table.

As I came across the definition OF A WEAK ENTITY which define its primary key as a combination of weak entity's attribute and the owner's table's primary key(in this case STUDENT)

Is my method of creating a foreign key as the only primary key in the table ACADEMIC RECORD correct??

STUDENT Table  
**UID**  NAME  GENDER  ADDRESS  PHNO.

ACADEMIC RECORD Table  
**UID**  HighschoolMarks  GradSchoolMarks
+1  A: 

I'm not completely clear on what you are asking, but it sounds like you are using the correct method.

Your STUDENT table requires a primary key to provide a unique reference for each row.

Your ACADEMIC_RECORD table also requires a primary key to provide a unique reference for each row.

Each student may have zero or more academic records, and you want to identify the student to which each academic record belongs. You do this by adding a column in the ACADEMIC_RECORD table which contains the id (the primary key) of the student:

STUDENT      ACADEMIC_RECORD
             id
id <-------> student_id
name         high_school_marks
gender       grade_school_marks
address
phone_no

Assume you have three students: Alice, Bob and Dave. Alice and Dave have three academic records, and Bob has two. Your tables would look something like this (I've omitted some columns to make things clearer):

STUDENT
id    name
1     Alice
2     Bob
3     Dave

ACADEMIC_RECORD
id    student_id
1     1
2     1
3     1
4     2
5     2
6     3
7     3
8     3
Mike
@Mike....see m creating a UNIVERSITY DATABASE and the STUDENT table had many attributes so i thought rather than cluttering it more maybe i'll create a weak entity called ACADEMIC RECORDS that stored Scores of the enrolling students like High School Scores and Grad school scores (if enrolling for Masters)...and can be referenced only by the UNIQUE_ID of the STUDENT....was wondering if i could proceed like this without worrying about NORMALIZATION Issues....
S_anand
@sujitanand: If each student will always have exactly one set of academic records for high school and grad school, then you don't really need to split the tables at all - you can store all the information in one table. Of course, you *can* split the tables if you like, if you feel that this gives you a cleaner design. However, if the number of academic records for each student varies (some have none, some have one, some have more than one, and so on), then splitting the tables is worthwhile. See the answer by *bobince*, and the comments that follow, for more on this.
Mike
@Mike...Thanks a lot!!!!
S_anand
A: 

There's nothing necessarily wrong with having a primary key that's also entirely a foreign key. It's a common way of implementing something like ‘base classes’, where an entity has a row in a base table, and may have a row in one or more extension tables (one to one-or-zero relationship).

I'm not sure it's the most appropriate schema for what you're doing though. If there really is an exactly one-to-one relationship between academic_records and students, it looks like they are part of the same entity to me.

In which case from a normalisation point of view the record columns should be part of the main students table. Maybe there's an efficiency reason to denormalise, but “I don't want to increase the table size” is not normally an adequate reason. Databases can cope with big tables.

bobince
@bobince: Good point about the possible one-to-one relationship. I'd assumed (perhaps incorrectly), that the reason for splitting the tables was to allow for a one-to-many relationship between students and academic records.
Mike
Can you explain how this design is 'denormalised'? The `ACADEMIC_RECORD` table looks to be in 5NF to me. Also, it strikes me that a person can be enrolled without having completed any courses, therefore 'academic record' is not an attribute of a 'student'. A table should model either entities or relationships and it seems to me that 'academic record' is a *relationship* between a student and the courses they take.
onedaywhen
It's presumably not possible for a university student to enroll without high and grad school records. Whilst it's arguable whether an academic record should be stored in this form and whether it should be optional, the OP does seem to assuming that a single academic_record is indeed a necessary part of the student entity, and so splitting them would be a denormalisation.
bobince
@all....Thanks a lot guys!!!
S_anand
"It's presumably not possible for a university student to enroll without high and grad school records" -- "presumably"? What if they pass an entrants' exam or are given credits base on work experience? For a post graduate course, the prerequisites would be e.g requires and undergraduate degree, perhaps from a different university. How many NULLable columns does it take before you see the redundancy in your proposed design...?
onedaywhen
"and so splitting them would be a denormalisation" -- What do you mean by "a denormalisation"? You understand that normalisation is a process, right? I can process the OP's two table design right through to 5NF. Please by specific: at which normal form do you think the two table design stops? Can we at least agree that it is in 1NF (http://en.wikipedia.org/wiki/1NF)? If so, take it from there and tell where you think it stops (2NF, 3NF, etc). Thanks in advance.
onedaywhen