Results 1 to 5 of 5

Thread: Database relationships problem

  1. #1
    Join Date
    Dec 2008
    Posts
    5

    Database relationships problem

    Hi Friends,

    I am newbie to Database technologies. Can anyone please help me with this. Which of the following is the best way in defining relationship between two entities?

    SCHEME 1
    Table - Course
    Course_id
    Course_Name
    Course_details

    Table- Student
    Student_id
    Student_Name
    Student_Roll No.
    Course_id

    SCHEMA 2

    Table - Course
    Course_id
    Course_Name
    Course_details

    Table- Student
    Student_id
    Student_Name
    Student_Roll No.

    Table Student_Course
    Student_id
    Course_id

    As per my understanding in SCHEMA 1, by having course_id column in student table we imply that every student must have a course, i guess i am right? Whereas in SCHEMA 2, we mean that course and student exist independent of each other and there may be a relationship between them.

    How do we look at these schemas when we develop an application over it, from same point of view as i did? I mean we can force to select or enter a course for a student record in SCHEMA 2 using application logic or we can skip (by passing null value) course details of a student in SCHEMA 1.

    For example somebody is entering bulk records of students in the system and he may or may not aware of student's course and may want to skip for the moment? Which schema should be chosen in this case?

    Above scenario was built for two tables, how about having multiple relationships e.g student_exam, student_sport, student_activity etc ?

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Database relationships problem

    Hi Barny,
    There are two different kind of relationships between course table and relationships table.There is a relationship of 1:n in your first schema. This means, there could be an unknown number of students for every course, but for every student there could only be one course.

    Whereas contrasting the first schema, your second scheme defines another relationship referred by n:m relationship. This means, that there can be an unknown number of students for every course, and for every student there could be an unknown number of courses (between 0 an n).

    Since these are two different relationships it is upto you which relationship you want to use. Be sure and logical of it, which of your schemes you should use.

  3. #3
    Join Date
    Dec 2008
    Posts
    5

    Re: Database relationships problem

    Thanks for your reply,
    I would like to have one student multiple course but one course can be assigned to only one student.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Database relationships problem

    As per your requirements your schema 1 describes a 1:n relationship between student and course, so you need to change that. Since you want to implement a 1:n relationship between course and student.

    It means n courses if you look from the student side, and one student if you look from the course side. The identifying feature would be the student id in a course table.

    But the case will be different for private courses, you will probably have a course with multiple time slots for multiple students.

    For example, at 07:00 there is an Mathematics course for student Amy while there is another one at 9:30 for student Dean.

    In above case the schema can be:

    Table - Course
    Course_id
    Course_Name
    Course_details

    Table- Student
    Student_id
    Student_Name
    Student_Roll No.

    Table Student_Course
    Student_id
    Course_id
    start_time
    duration

    As long as you have a unique constraint over all four columns, this could meet your requirements.
    It's just my experience, maybe this idea is absolutely unnecessary.

  5. #5
    Join Date
    Dec 2008
    Posts
    5

    Re: Database relationships problem

    Thanks Mindspace,
    You made things clear for me, using unque constaints i can limit my database relationships.

    Thanks for it.

Similar Threads

  1. Relationships in The Elder scrolls
    By Hardiyy in forum Video Games
    Replies: 5
    Last Post: 06-06-2011, 11:02 PM
  2. How to make relationships with various entities in MS Access
    By Ferdinand Alosa in forum Windows Software
    Replies: 3
    Last Post: 06-02-2011, 04:14 PM
  3. Relationships in java
    By Jagadamba in forum Software Development
    Replies: 3
    Last Post: 18-11-2009, 11:02 AM
  4. How do i assign relationships primary key access
    By Kamran in forum Windows Software
    Replies: 3
    Last Post: 19-05-2009, 12:42 PM
  5. How many relationships can create in EJB?
    By Pandya in forum Software Development
    Replies: 2
    Last Post: 30-03-2009, 11:39 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,001,549.06794 seconds with 17 queries