yrazlik
yrazlik

Reputation: 10787

One-to many relationships in ER diagram

I am trying to show the following in the ER diagram:

There are instructors and courses, a course is taught by only one instructor
whereas an instructor can give many courses.

enter image description here

enter image description here

My question is, is there any difference between two diagrams, in other words, does it matter which line we turn into an arrow, or what only matters is only the direction of the arrow?

Also, if we think about the mapping cardinalities; is it 1 to many or many to 1? If we think in terms of courses, then it is many to one but if we think in terms of instructors, then it is one to many. How do we decide this? Thank you.

Upvotes: 26

Views: 129914

Answers (4)

Naveesh Kumar V
Naveesh Kumar V

Reputation: 81

Consider an 'employee' entity set and 'department' entity set, having relationship set as 'manage'. Employee-------------Manage--------------------Department (entity set) (Relationship set) (entity set) One to many relationship means one entity of employee set can be associated with more than one entity of Department entity set but, an entity of Department set can be associated with at most one entity of employee entity set. That means if there is one to many relationship between employee and department entity sets, then each employee can manage more than one department and at the same time each department is managed by at most one employer.

Upvotes: 0

Yogendra
Yogendra

Reputation: 1

Both are having exactly opposite cardinality

🔸Simple clean line means many.

🔸Arrow means one.

If we consider both with same cardinality.

then, many to many should be represented by following the second convention as (please assume diamond for relationship set and rectangle for entity set)

   INSTRUCTOR <---- TEACHES -----> COURSE 

which is actually of no meaning.

If we consider both with opposite cardinality.

then, many to many should be represented by following the second convention as (please assume diamond for relationship set and rectangle for entity set)

  INSTRUCTOR ----- TEACHES ------ COURSE

No explicit arrow is always considered many to many. So, it is correct (only if we consider both opposite)

Upvotes: 0

debater
debater

Reputation: 476

I don't think the other answer is fully correct.

I would say that one should use arrows, and one should use a notation that gives a meaningful name to each direction of the relationship. In this case it will be "teaches" in one direction, and "is taught by" in the other. Either use arrows next to the names or put the name near to the entity to which it refers. You could use one line (with two arrow heads) or two lines (with one arrow each).

I would also suggest that cardinality is just one kind of constraint, and the notation should reflect that. For example, the two names for the relationship could be "teaches (many)" and "is taught by (exactly one)". The point is you might have "teaches (one or two)" or "is taught by (exactly two)" and so on.

It is better to be explicit and clear about exactly what your constraints really are.

Upvotes: 2

Dulantha
Dulantha

Reputation: 516

In ER diagrams when the relationship is denoted the arrows are not used. Some instructors use this arrow when they want to decide the cardinalities but that is just to get the cardinality (1:1, 1:M and N:M)

I have attached the ER diagram for this in Chen notation and also using Crow Notation you can use either of them.

ER Digram

Deciding the cardinality for a relationship is a practical scenario there is no hard and pass rule to obtain it. What you need to do is start from one side of the relationship and take one tuple (instance) and see how many tuples from the other entity participate for the relationship. Then do the vise versa. Then you know the participation number of tuples) from each entity to the relationship. Think about set theory and functions in mathematics when you decide the cardinality (ie Set of instructors, Set of Courses and set of Teaches relationship type) then this is so easy but if you are not from a mathematic background just think of practical scenario.

For Example

a) For 1 instructor he or she can teach Many (M) courses

b) For 1 Course there is only 1 instructor

so in instructor side there is always 1 in a) and b) but in Courses there is M and 1 in a) and b) there for Instructor:Course cardinality is 1:M

Upvotes: 50

Related Questions