Can you have the same relationship twice in an eer diagram? - database

For example let's say there is a student entity, book entity, and laptop entity. The student can loan either a book or laptop, so should I make the student entity have 2 LOANS relations with book and laptop or should I make student have one LOANS relation and have it connect to a new entity called item and generalize it so it can have both book and laptop?

Related

Is my Entity Relationship Diagram meet the student teacher class relationship?

I basically want to show in the model a relationship in a school
Teacher can teach one or many subjects
Teacher can teach one or many class
Student can attend one or many subjects
Student can have one or many teachers
Student can be registered for one or many class
Class can have one or more subjects
Is my model so far meet the relationship above?
my Diagram

Should every entity have a primary key? And can we have a sub entity?

Problem:
Design an ER diagram where:
An item has the attribute: description.
An item can be sold by a company or a person.
A person has the attributes: name, phone and email.
A company has the attributes: company name, address and a contact person who is one from the person entity set.
A contact person cannot sell the same item with the company he works for.
This is my design:
I'm learning. Please correct and point out what is wrong in my design.
I'm not sure that I should remove the primary key SellerID in the Seller entity and add companyID to the Company entity and personID to the entity.
Is the Contact Person entity connected to the Person entity correctly?
How can I demonstrate this constraint: A contact person cannot sell the items (distinguished by item ID) his company is selling.
Based on the use-case you have outlined here is my suggestion.
Seller should be the anchor entity to Company and Person sub-entities. Basically Seller table should have an unique identifier column (Seller ID) along with the seller type (Company/Person)
Seller ID should be brought as the foreign key to the Company / Person table. Also, these tables should have their respective primary keys as company ID and Person ID
The association table Contact Person should have the company ID, Person ID. This table should primarily answer 3 questions
i) Given a company name, it should list out all the possible contact persons and vice-versa
ii) If the company has multiple contact persons, who is the primary/default (Though your use-case has asked for it, in terms of scalability, this should be considered)
iii) If the company has multiple contact persons, what is the relation of that person with the company

How should I make the relation work in this Database model

(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.

Modeling 3 entities with relationships

Say we have three entities in our environment, Teacher, Student and Course.
Every teacher has (teaches) 1 or more Courses and each Course is offered by 0 or more teachers
Every Student has taken 1 or more Courses and each Course is taken by 0 or more Students
Every Teacher has 0 or more Students and each Student has 1 or more Teachers
In this relationships, each relationship could be inferred from the two others, for example to know which Students are being taught by Teacher T1, go through the relationship between Teacher and Course to see what Courses are being taught by the teacher T1, and then go through the relationship between Course and Student to see which Students has taken these Courses. These Students are the ones that are being taught by teacher T1.
So we don't need an explicit relationship between Student and Teacher, because "Conceptually" this relationship exists.
Finally the question is:
In Conceptual Design is it necessary to show all the three relationships?
And as an extra information, how would it be in Logical Design (designing database tables and relationships), should the relationship remain as an inferred relationship or should be explicitly defined ?
Here is an example,
Conceptual (using NORMA)
Teacher teaches Course
It is possible that some Teacher teaches more than one Course and that for some Course, more than one Teacher teaches that Course.
In each population of Teacher teaches Course, each Teacher, Course combination occurs at most once.
Student takes Course
It is possible that some Student takes more than one Course and that for some Course, more than one Student takes that Course.
In each population of Student takes Course, each Student, Course combination occurs at most once.
Teacher tutors Student on Course
For each Student and Course, at most one Teacher tutors that Student on that Course.
Constraints
For each Teacher and Course, that Teacher tutors some Student on that Course if and only if that Teacher teaches that Course.
For each Student and Course, some Teacher tutors that Student on that Course if and only if that Student takes that Course.
Logical

Entity Relationship diagram for a three-way relationship

I want to create an entity relationship diagram for a three way relationship in the following contrived situation:
Each COMPANY has many DEPARTMENTS. An EMPLOYEE can work simultaneously for many DEPARTMENTs. However, an EMPLOYEE can work for only one DEPARTMENT of a COMPANY. In other words, the EMPLOYEE works for as many DEPARTMENTS as COMPANYs.
What kind of associations and relationships will such a diagram have? My purpose is not to create tables in a database but just as an aid to understanding.
Thanks in advance for your help!
COMPANY_EMPLOYEE_DEPARTMENT:
COMPANY (PK)
EMPLOYEE (PK)
DEPARTMENT
Each combination of company and employee, can only be associated with one department. That is, an employee can only work for one department in each company.
This should work as long as a department does not belong to more than one company, and that the COMPANY_EMPLOYEE_DEPARTMENT relation does not link a department of one company with another company.

Resources