Simple entity relationship diagrams questions

simple entity relationship diagrams questions

Database Questions and Answers – Entity-Relationship Diagrams This set of Database Multiple Choice Questions & Answers (MCQs). Using the basic ER approach, we may have the ER diagram. Q: Can we combine .. Question: Is the resulting relational schema in normal form? Advantages. The ultimate guide to ER diagram including origins, uses, examples, components , limitations and guidelines on how to draw them with Lucidchart.

In the future, some maintenance of the database may be necessary. The person doing it who may not be the original designer needs to know the overall design and will expect to find the E-R diagram in the technical manual! We will now look at the building blocks of E-R diagrams. One-to-many relationships In this database, there are two tables. A relationship between 2 entities must be read in two directions.

In other words, to fully describe the relationship between two entities, you need two sentences, not one. The process of reading E-R diagrams is very mechanical. Add the entity name. Add the verb or phrase closest to that entity. Follow the relationship line to the other entity. Finally, write down the name of the other Entity.

Entity-Relationship (E-R) diagrams

The line used to show a one-to-many relationship is this: An E-R diagram is constructed in the following way: Each entity is shown in a box. The correct type of relationship line is drawn, the right way round! Verbs or phrases are added to aid understanding. Many-to-many relationships The symbol used to represent a many-to-many relationship is: Here is an example of a many-to-many relationship: Using the same method as before, we need to describe the relationship with two sentences: Each pupil studies many GCSEs.

Each GCSE is studied by many pupils. How would you implement this database? To help us understand the design, we will put some records in the tables, as before. This is a far from ideal solution! For a start, how many attributes will you need in the GCSE table? You could have many indeed if there were lots of pupils taking a particular GCSE. More importantly, however, is that you or rather Access or whichever software you are using are going to have a problem recombining the two tables back into one!

For example, a record in the GCSE table doesn't match to just one record in the pupil table. One GCSE will match back to many different records in the pupil table. This is not good! Resolving many-to-many relationships Fortunately, the solution is straightforward. It is known as 'resolving a many-to-many relationship'. If you have a many-to-many relationship, you can turn it into two one-to-many relationships by creating an extra linking table.

In other words, this: A simple primary key is a primary key that is made up of only one attribute. A compound primary key is a primary key that is made up of more than one attribute. Reading the relationships, we have: Each record in the Pupil table i.

Have a look at pupil number one. This record is related to only one record in the Pupil table. This particular record relates only to pupil number 2. It appears in the second record and in the last one. We have resolved our many-to-many relationship. We store the details about each GCSE only once.

This is also good! We have a third table that matches up each pupil to every GCSE they are taking. This table has a compound primary key made up of the primary key from the pupil table and the primary key from the GCSE table. Each compound primary key combination is unique!

Introduction to Entity-relationship modelling

Each row is unique - you cannot have two rows the same. At any time, we can recombine the data from any related records from the three tables into one record!

One-to-one relationships This type of relationship is shown with a simple straight line. An example of this kind of relationship is shown below: This kind of relationship is used to keep the database design compact and clear. Some of those products are CDs and some are, for example, fish!

If you are keeping information attributes about the products, one possible set of attributes for the PRODUCT table might be the following: Of course, the number of attributes needed could be very large. They will include items such as clothes, insurance, cars, fresh vegetables and so on. Each of these products will need their own specialist attributes. For example, you might need an attribute to hold the size of clothes. In other words, for every one department there can be, at most, one managing employee.

This information can also be represented in the ER diagram: As you might have determined, the M part of a relationship is represented by putting an M next to the appropriate entity type in the relationship while the 1 part is represented by a 1. The ER diagram now represents much more information than it did above: Any one division can contain many departments.

Any one department can be contained in, at most, one division. Any department can have, at most, one managing employee or manager. Any manager can manage, at most, one department.

If you are a bit confused about all this 1: Several other questions remain about this situation that are not addressed in the description: What is the minimum number of departments in a division? Does a department have to be associated with a division? Does a department have to have a manager? These questions would have to be answered before we complete the ER model. And we will answer these questions later.

For now we are going to stop this part of the analysis since the purpose of this example is to demonstrate what ER modelling is all about. The ER modelling process is not something for which a set of steps can be given and then performed. The process contains almost as much art as science. Some steps are performed many times and many decisions are re-visited and revised.

Given these conditions, a broad outline can be given: Determine what entity types are involved. Determine which entity types are related. Refine the definition of the relationships.

Understand now that there are several methods for representing ER models graphically. Notice what has happened with this situation. Initially we had a text description of the problem.

After analysing it and making some necessary assumptions, we created an ER diagram that reflects the situation accurately and makes explicit the relationship among the entity types.

This is why we perform ER modelling. It is quite a straight-forward step to go from this ER model to an implemented database. Remember why we are doing all this: We are finding out all we need to know to create a database that will hold our data. And a well-defined database can be a very useful tool for solving business problemsand it is also in high demand by recruiters.

EER Diagram Example & Solution

You will learn how to perform the steps necessary to create such a database in later chapters. In this section I present more detail on some of the basic concepts.

In the example in an earlier section, we saw that divisions are directly associated with departments and departments are directly associated with employees. No direct association between division and employee was given. This does not mean that there is no relationship between division and employee. In fact, the ER diagram tells us that there is a relationship between the two: Given any one division, there can be many employees managing departments within that division.

Certainly, this is not earth shattering news. But it is in the ER diagram. The above fact is not represented as a separate relationship between division and employee because it can be inferred from existing relationships. An ER diagram should contain the minimum number of relationships necessary to reflect the situation. For relationships between two entity types, there are three basic cardinalities.

Each of the following descriptions are given in terms of a relationship between entity type X and entity type Y. One entity of type Y can be associated with, at most, one entity of type X.

A car has only one steering wheel and a steering wheel can only be installed in one car. M one-to-many One entity of type X can be associated with many entities of type Y.

A building can have many rooms but a room can be in, at most, one building. M many-to-many One entity of type X can be associated with many entities of type Y. One entity of type Y can be associated with many entities of type X. A car can have many options and an option can be installed on many cars.

Determine the cardinality of the relationships between the following four pairs of entity types. For each relationship you have to answer two questions: Answering these two questions gives you the answer to the following questions.

For example, if you answered M to the first question and 1 for the second question, then this relationship between entity types X and Y is of cardinality M: Patient under care of primary care physician Physician performs operation Doctors have speciality in disease Needle injected into patient It would seem that at any particular time a patient can only have one primary care physician and that any physician can have many patients M: One physician can perform many operations and one operation can be performed by many physicians M: One doctor can have specialities in many diseases and one disease can be the speciality of many doctors M: In this section we examine the minimum number of entities in a relationship.

Existence is given as optional, mandatory, or unknown. This is best clarified with an example. Consider again the example discussed in Section 2. Specifically, focus on the manage relationship between department and employee. We know the cardinality is 1: This tells us that at most one department is managed by an employee and an employee can manage, at most, one department. Be sure you understand the distinction between these two phrases. The existence of this relationship tells us the fewest number of departments that can be managed by an employee and the fewest number of employees that can manage a department.

Only one of the following can be true: Similarly, only one of the following may be true: For each set of three above, which ones would you choose? It is not entirely clear from the situation description which of the above are true.

I make the relatively standard assumptions that a department must have at least one manager and that an employee need not be the manager of any department. Thus, the existence of this relationship is mandatory in one direction and optional in the other.

Entity-Relationship (E-R) diagrams notes

Going back to the definition of existence, we can also look at this situation in this way: Given any randomly chosen department, there must be an employee on the other side of the manage relationship. Thus, the relationship is mandatory in this direction. Given any randomly chosen employee, there need not be any department on the other side of the manage relationship. Thus, the relationship is optional in this direction.

I assume that the contains relationship is mandatory in both directions. Given this information, the ER diagram is modified in the following manner: This diagram is beginning to look a little complicated but remember the following pieces of information and it gets a little easier: The marks on the lines tell you the minimum number in a relationship. A dash on the line looks like a 1; it tells you the minimum number in the relationship is one so the existence is mandatory.

A circle on the line looks line a 0; it tells you the minimum number in the relationship is zero so the existence is optional. If there are not any marks on the line, then the existence is unknown. The marks below the line tell you the maximum number in a relationship.

simple entity relationship diagrams questions

An M tells you the cardinality is many while a 1 tells you it is one. Look at the manages relationship again. Cover up the line connecting the manages diamond with the department rectangle.

Now all you see are the department entity type, the employee entity type, and the right side of the line with a dash on it and a one below it. This tells us that a department is managed by at least the dash one employee and at most the 1 one employee.

A department is managed by one and only one employee. Cover up the line connecting the manages diamond with the employee rectangle. Now all you see are the department entity type, the employee entity type, and the left side of the line with a circle on it and a 1 below it. This tells us that an employee does not have to manage any departments the circle and may manage at most the 1 one department. An employee may manage no more than one department. For each of the relationships listed in Problem 5: Define the existence in both directions.

simple entity relationship diagrams questions

Draw the ER diagram for the relationship. Write out two sentences that represent what the ER diagram says. If it is not important, it should not be in the database.

In an accounting database you would expect to find entity types for expenses, assets, liabilities, expenditures, deposits, etc. You would not expect to find entity types for colour of check, quality of dollar bills received, etc. The database is supposed to reflect realitybut only the part of reality that is important to the company. This allows us to make generalisations about that type. This is a powerful capability; however, sometimes we want to make a generalisation only about a certain subset of those entities and another generalisation about the rest of the entities.

Consider a simple example. Suppose you have an accounting database which keeps track of accounts receivable and accounts payable. Of course the database keeps track of the companies to which you owe money and the companies that owe you money. For all these companies, you keep track of their mailing address and a contact person. For the companies that owe you money you keep track of how much they owe you.

For the companies that you owe money you keep track of how much you owe them. Should we have three entity types: That would be a mess. That is why the concept of entity subtypes was created. In this company example, what is the entity type? What are the subtypes?

In this database you should define a company entity type with two subtypes: The company entity type stores all facts that are common attributesin this case, the address and contact person. There are many situations in which subtypes can be created but should not be.

Only create subtypes if the subtype is involved in relationships that the other subtypes are not or if the subtype needs to have additional facts stored with it. If one of these two requirements is not met, then do not create the subtype.

What is the relationship among the following? List a few facts common to all items for each question.