Using Chen's notation on an entity relationship model, for database design. Is this the correct way to illustrate the following relation. 'Many employees report to one employee':
I think the below image would be more approapraiate
E-R Diagrams
DATA MODEL
STACK SIMILAR QUESTION
You dont need the diamond. You can have the direct relationship. Unless the relationship itself has attributes, the diamond is not used.
Related
I see that there are two different ways to make entity relationship on the example illustrated below (either by one to one or by many to many). Which one is better method? (What is the better method in terms of common practice or widely accepted convention. Possibly, which one is more efficient? If there is no better method what would be the trade-off of using one instead of another?)
One-to-one method
Many-to-many method
First of all, neither diagram is an entity-relationship diagram. Entity-relationship diagrams should be able to represent entity-relationship concepts, but the notation you used doesn't distinguish between entity relations and relationship relations, and shows columns, types and foreign key constraints, which belong in a physical model rather than a conceptual one. What you have is better described as table diagrams. For ERDs, I recommend Chen's original notation or something close to it.
The first diagram mixes a higher-level abstraction into an otherwise physical model, and for that reason, I recommend the second style as it's more consistent.
Note that in either diagram, CompanyType_ID in General appears at odds with the type of relationship you're trying to represent. It may not necessarily be wrong (entities described in General may each have a primary or distinguished CompanyType in addition to a set of secondary types) but even if it's modeled that way intentionally, it warrants a second look at least.
I came to know that there is Crow's foot ER diagram notation, and got a good quick reference. Have a look at the below diagram:
I did get some clarity on these symbols, however I have difficulty in understanding:
1) Why we have the "connector symbols" on both side of the line?
2) How to interpret them?
Can anyone please help me understand this?
Your reference is somewhat incorrect. The Entity-Relationship model doesn't use Crow's foot. Chen's notation and extensions to that notation can be called ER diagrams.
Your diagram is a generalization of table diagrams, modified to allow many-to-many associations and hide attributes. However, it doesn't represent relationships using their own shapes, and I see no indication of support for ternary or higher relationships. There's also no indication of other ER concepts like weak entities, associative entities, identifying relationships or keys.
Data models that only support binary relationships are usually based on the network data model, not on the Entity-Relationship model. Relationships in the ER model, when physically implemented, are represented by two or more entity columns in the same table, not by any kind of link between tables. In actual table diagrams, many-to-many relationships are represented by their own table, with two one-to-many association lines. In those cases, the cardinality indicators represent the number and optionality of records with matching values for matching PK/FK columns.
The interpretation of the Crow's foot symbols are indicated in the orange column. For more information about modeling with Crow's foot, see Entity Modelling. However, don't confuse this with the Entity-Relationship model as described by Chen, or either of them with the Relational model.
I have entities Image and Post. Post has a uni-directional Nullify relationship to Image. It's a relationship and not an attribute because I want to benefit from lazy loading of relationships, making initial fetches of Post entities very fast. As you can guess, Image contains image data.
Apple generally discourages uni-directional relationships (Link) unless there a good reason not to have an inverse relationship.
My reason for not having it is Image is a generic entity, so having inverse relationships to all entities that use it seemed like overkill. However, I wonder if there is a better way to go about this without violating Apple's recommendation.
Parent entities.
Comment, BlogPost and Tweet all inherit the images relationship. And the inverse relationship points to a TextContent object, which can be a Comment, BlogPost, Tweet or TextContent itself.
As Apple says... Unidirections Relationships
It is not strictly necessary to model a relationship in both
directions
BTW I think attributes also could be loaded lazily (by system) if CoreData detects that is better to do this...
You can be interested in this then to
avoid warnings in your project
I have entity called Item. It has attribute title and I want it to have collection of subitems (type of Item).
One item can have many (sub)items. (sub)item is part of right one item. For example, there is item titled as car. It has subitems titled wheels, engine and cabine. Cabine has subitems seat and steering wheel.
How to model it? Should I set inverse to subitems? If I set no inverse, I'm getting warning. And whether it is inverse or not, it is still many-to-many. No way to set it one-to-many.
How should I think of this problem? I don't have much experience with databases and I think there is also difference between modeling in Core Data and in SQL.
EDIT: There should be subitems instead of subitem in the picture
I've added relationship superitem as inverse to subitems. superitem is to-one type with nullify delete rule and subitems is to-many type with cascade delete rule. Seems to be the most perfect solution for my case. As bonus I don't have to write my own - addSubitem: method (as it is not generated for Swift) because it is automatically added if I set item's superitem.
Object modeling and relational database design are quite different, at least on the surface. The concepts of encapsulation, inheritance, and polymorphism have no exact analog in the relational data model. You are going to have to think about the problem in two different ways in order to do both object modeling and relational database design.
There is a model that is sort of half way between them. It's called the "Entity Relationship model", and this has been around almost as long as the relational model. This is useful for thinking about the problem and analyzing the data requirements at a conceptual level. ER modeling is very parallel to object modeling, except that object modeling models behavior as well as data, and ER modeling only models data.
The problem with learning ER modeling for this purpose is that in the present state of affairs, most of the professionals who use ER diagrams do not use them to depict a conceptual model. They use them to depict a relational design for a database. So if you learn ER modeling from them, you'll learn a design methodology, and not an analysis methodology.
Data analysis and database design are really very different activities, and it's useful to keep them separate in your mind, even if a single project requires you to do both of them. Oddly enough, the same division ultimately comes up in object modeling as well. Some object models are analysis models, and try to clarify the problem space. Other object models are design models, and try to clarify the solution space.
Acknowledging what Mitty said. You need wrap your brain around objects (not relational tables). Considering your example I would break it down as follows. The top level object is an item such as a car, truck, airplane, boat, etc. Items can have systems such as engines, transmissions, cabins. Systems can have components such as pistons, spark plugs, seats, steering wheels, tires. If you think of all these things as objects, then perhaps the beginning of a model would look like this:
An item may have many systems. Systems may have many components. Apple recommends setting the inverse, but you should worry more about the relationships and their cardinality (i.e. one-to-one, one-to-many). You can use a reflexive relationship (to self) as you depicted, but I think that limits your ability to really leverage the power of the object model as all 'things' would be represented as 'item' and you wouldn't have the nice distinction of system and component (IMO)
all the attributes include in ER diagram or not?
My database have 8 tables and nearly 50 attributes, i include these 50 attributes in a single diagram OR not?
First thing - ER diagram is something that is first created usually and then later on converted into a data model like relational. So the data storing requirements are modeled into an ER diagram first and later on are converted into tables. There is rarely a case where you have to reverse engineer an existing data model into the ER diagram level (Conceptual Level).
During this process, tables are created for enitities and relationships accordingly (using some algorithmic process).
And a good way of practice is to draw the ER diagram with only entities and relationships without the attributes as it makes it very clumsy and difficult to concentrate on the actual entities and the relationships between them. Later on in a separate document or a page, you can list all the attributes corresponding to entities individually.
Hope this gives you a basic idea.