How should I make the relation work in this Database model - database

(I apologies in advance for my English)
I need to make a model of relation.
Normally it a thing we should do in team, but I am stuck to be alone, so I am kind of overwhelm by this
It about a school and it information concerning The Student, The Parents and the Class he want to enroll. Also they keep academic results.
I just can't get an ideal of how I could link them all and avoiding relations problems
http://i.imgur.com/fdwxH8g.jpg

First, I suggest you add a Person table to supertype Parent and Student, and move all the personal and contact information attributes to Person. You're sure to want to add additional information later, and having to duplicate everything for parents, students (and later, teachers and other school staff) gets to be a nuisance.
person (person_id PK, last_name, first_name, sex, birthday, email, address, city, phone_number, cellphone_number)
Next, do you want to record biological parents or caregivers? In schools we normally care about caregivers and their relationship to the student. To record that, you could create a relationship type table:
relationship (relationship_id PK, description)
with entries for father, mother, aunt, grandfather, fostermother, etc. You can then record the relationship between 2 persons like so:
parent (parent_id PK/FK, child_id PK/FK, relationship FK)
If you wanted to record biological parents, you could use:
bioparents (child_id PK/FK, father_id FK, mother_id FK)
with father and mother ids nullable (or decompose into separate tables for father and mother) since we're unlikely to know both parents for all students.
Finally, we get to the business at hand, students. Historical information and alumni are important in schools, so take care to model students over time, not just current students. You need to consider the time resolution for student registrations - are registrations annual, quarterly, or something else? For annual registrations, you could start with:
student (person_id PK/FK, year)
Now, what is a class? Is it something that recurs over time, or are classes with the same name in different years/quarters separate things? Can classes contain learners of different forms/grades/levels, or are they partitions of those? Is a class a grouping of students that attend multiple subjects, or a subject-specific grouping? I'm familiar with two types of classes, which could be called form classes and academic classes, but things may be different in your region of the world.
Using your class table:
class (class_number PK, name, prerequisite, formation_time)
We need to link students to it. If class membership is an annual thing, we can add to the student relation above, e.g.
student (person_id PK/FK, year, class_number FK)
Now, I just made up tables as I went along, but if you want to do this properly, you really should list/model your functional dependencies before you start making up tables. You could look into a formal modeling discipline like Object-Role Modeling, or at least write out simple logical relations in both directions:
a Student has one or more Parents
a Parent has one or more Students
a Class has a Year
a Year has zero or more Classes
a Student has a Class per Year
For non-binary relations, you don't need to write it out in every direction, but you do need to decide which combinations of attributes uniquely determine the others. For example, the combination of Student and Year uniquely determines the Class.
Anyway, that should give you a start.

Related

Represent a relationship

I've currently come to a complete halt in thinking.
I have a table called Account, which has attributes accountID(PK), firstName,lastName etc... and I have made a table called Class which has attributes classID(PK), className, classTime etc... Many to many relationship exists between the 2 tables.
I need to break the many to many relationship. The conditions are: after an account is made, it may be enrolled to a class as either student or instructor but not both. However, an account could have an instructor role in one class, and a student role in another class
So I thought of making a table called Enrollment, and having accountID, classID and enrollment type, but what I'm uncertain on is the relationships needed btwn Account and Enrollment and Enrollment and Class. Would it be one account to many enrollment?
If anyone would be kind enough to help me understand this I would be very grateful.
Your design seems correct.
In this model, an account has many enrollments; and enrollment has exactly one account.
A class has many enrollments; an enrollment has exactly one class.
If you add a unique key to the enrollment with account_id, class_id, you fulfill the rule that an account may have only one enrollment for a given class.

Diagram ER doubte one relation

First I'll explain the statement of diagram and after that I will explain my problem and I'll attach my actual diagram.
I should make an ER diagram about the following statement:
Perform the design and implementation of a database to store information about patients admitted to a hospital, patients can be adults or children. In the case of children we save information from who their parents who in turn can also be patient. In this hospital, patients arriving at the emergency department of the hospital are examined by a doctor and, depending on their health status, are entered in the corresponding plant (traumatology, intensive care...) under the supervision of a nurse.
Each patient receives a treatment that must be stored
Well, I design the following diagram; but my main problem is how to make the relation between fathers that can be patients. I decided put all fathers as patients and don't represent adults as entity, I have considered them implicit into patient's entity. But I'm not very sure about the validity of my solution.
I'd be grateful if someone can help me with my doubt.
How about subtyping patient from person and then creating a relationship from patients who are children to their parent persons? In this way, not every person need to be a patient but parents can be patients too. The relationship between parent and child indicates the role of each so there's no need to specifically subtype patients into parents or children.
Note also that your Doctors can currently only examine one patient.

ERD - Entity relationship diagram - complex and tricky relations

Here is the scenario.
Two completely different Entities are independently related to the third entity in the same way. How do we represent it in the ERD? or (Enhanced ER)
Ex:
Student "BORROWS" BOOK (from the library)
DEPARTMENT "BORROWS" BOOK (from the same library).
If I define 'BORROWS' relationship twice, it would be awkward and clumsy in terms of appearance in the diagram, and increase the complexity of implementation as well.
At the same time, I can not declare a ternary relationship since STUDENT and DEPARTMENT are not inter-related in a relationship-instance.
However, I couldn't find a better way.
How do I solve it?
If Wikipedia is to be believed, Enhanced ER permits inheritance. Why don't you have a BORROWER entity (with the appropriate relationship), and have STUDENT and DEPARTMENT subclass that?
I've been having a similar issue - where a company or a person can order a product.
You've got an order, that can belong to either a person, or a company - so what do you link the relationship to? I'm thinking orders will have a companyId, and a personId foreign key, but how do you make them exclusive? The data returned won't necessarily be the same - a company doesn't have a first name / last name field for example.
I guess it could be done by having a name returned, and in the case of a person build the string out of firstname / lastname, and in the case of a company use the companyname field .

shared table for entities teachers and students?

I have to create a database and I want to know what would be the best solution.
Let's say I have to store information about students and teachers.
Should I make one single table containing all the personal information (name,email,phone password) to both students and teachers?
For additional information should I keep them in separate tables as ADD_TEACHERS and ADD_STUDENTS?
You may want to create a people table for the common data like name,email etc. You can then use a primary key column in this table, and if there has to be information specific to teacher (like course_instructor, head_teacher of class), then use that unique key from people as reference in your course_information table. Do the same for students too.
It sounds like your best route is to have a separate table for teachers and students. You'll have what is called a one-to-many relationship between teachers and students: one teacher, many students.
But that only covers one semester. When you consider other semesters, you have a many-to-many relationship between students and teachers.
In the end, you're best off with at least three tables: Teachers, Students, and teacher-to-student relationship.
First thing you have to do is Map the entity relationships (ER) and its attributes.then design the database and apply the normalization strategies.
In the proposed scenario students and teachers are different entities . and find out thier relationship
ONE student ONE TEACHER
MANY Students HAVE ONE TEACHER
MANY Students HAVE MANY TEACHERs
Then check out their attributes Example - Student(Name,Class,DOB)
It depends on how you are going to use the data. If you have a lot of use cases where you are interested in "persons", regardless of role, or if you have a lot of persons who are both teachers and students, you may want to learn the gen-spec design pattern, as it applies to relational tables.
See previous discussion.

Help with many-to-many relation

I have a problem with a many-to-many relation in my tables, which is between an employee and instructor who work in a training centre. I cannot find the link between them, and I don't know how to get it. The employee fields are:
employee no.
employee name
company name
department job title
business area
mobile number
ext
ranking
The Instructors fields are
instructor name
institute
mobile number
email address
fees
in a many-to-many relationship the relationships will be in a 3rd table, something like
table EmployeeInstructor
EmployeeID
InstructorID
to find all the employees for a specific instructor, you'd use a join against all three tables.
Or more likely there will be classes involved --
Employee takes Class
Instructor teaches Class
so you'll have and EmployeeClass table,
an InstructorClass table,
and join through them. And Class needs to be unique, or else you'll need
Class is taught in Quarter on ClassSchedule
and end up joining EmplyeeClassSchedule to InstructorClassSchedule.
This ends up being one of your more interesting relational designs pretty quickly. If you google for "Terry Halpin" and "Object Role Modeling", this is used as an illustrative situation in the tutorial.
First of all, you will need a unique key in both tables. The employee number may work for the employee table, but you will need another for the instructor table. Personally, I tend to use auto incrementing identity fields called ID in my tables. This is the primary key.
Second, create a new table, InstructorEmployee. This table has two columns, InstructorID and EmployeeID. Both fields should be indexed. Now you can create an association between any Employee and any Instructor by creating a record which contains the two IDs.

Resources