ER Diagram Introduction and Example Exercises

ER图

introduce

Also known as entity-relationship diagram (Entity Relationship Diagram), it provides a way to represent entity types, attributes and connections, and is used to describe the conceptual model of the real world.
In the ER diagram, a rectangle is used to represent an entity, an ellipse or a rounded rectangle to represent an attribute, and a diamond to represent a relationship, which is connected by a solid undirected line segment, as shown in the following figure
insert image description here

general constraints

There are three kinds of quantity constraints for the contact type in the entity-relationship data model: one-to-one, one-to-many, and many-to-many One-to-one
:
one-to-many: For example, a factory can have many employees, but each employee belongs to only one Factories, constituting a one-to-many relationship.
Many-to-many: If students choose courses, each student can choose multiple courses, and each course can also be selected by multiple students, forming a many-to-many relationship.
As shown below
insert image description here

Example exercises

1. Assume that there are two entities of store customers, the attributes of "store" are: store number, store name, address, phone number; the attributes of "customer" are: customer number, name, address, age, gender. A shopping mall has multiple customers shopping, and customers can also go to different shopping malls. Every time a customer goes to the supermarket to shop, there is a consumption amount and date. Try to draw an ER diagram.
Detailed explanation: "Assume that there are two entities of store customer", the entity is represented by a rectangle
insert image description here
"The attributes of "store" are: store number, store name, address, phone number; the attributes of "customer" are: customer number, name, address, age, gender. "
The attribute is an oval, and each attribute is connected to its corresponding entity.
insert image description here
Customers come to the mall to shop, and when shopping, "there is a consumption amount and date", which represents the associated attribute, like this
insert image description here
"A mall has multiple customers shopping , Customers can also go to different shopping malls" indicates that it is a many-to-many relationship, and then optimize the shape of the ER diagram, and this question is completed 2.
insert image description here
Assume that a departmental database includes the following
employee information: employee number, name, address , Department
Department information: all employees of the department, department name, manager, products sold
Product information: product name, manufacturer, price, model, product internal number
Manufacturer information: manufacturer number, name, address, phone number

Answer:insert image description here

3. Please design a scientific research project management database of a certain unit. The main entities include:
scientific research project team, scientific research personnel and scientific research projects. The relationship between them is as follows: each scientific research project group can have multiple scientific research personnel, and each scientific research personnel can belong to multiple scientific research project groups; each scientific research project group can be
responsible for multiple scientific research projects, and each scientific research project can only have one The scientific research project team is responsible;
each scientific researcher can participate in the work of multiple scientific research projects, and each scientific research project is composed of multiple scientific research personnel.
Design the main attributes of each type of entity by yourself, and draw the ER diagram

Answer: insert image description here
4. Assume that each student takes several elective courses, each teacher is only responsible for teaching one course, and one course is taught by several teachers.
The attributes of "student" are: student number, name, address, age, gender; the
attributes of "teacher" are: employee number, teacher name, title;
the attributes of "course" are: course number, course name.
Draw ER Diagram

Answer:insert image description here

5. Suppose there are three entity sets in the database of a commercial company.
One is "company", the attributes are: company number, company name, address; the
second is the "warehouse" entity set, the attributes are: warehouse number, warehouse name, address; the
third is the "employee" entity set, the attributes are: employee number, name, gender.
Each company has several warehouses, and each warehouse can only belong to one company, and each warehouse can employ several employees, and each employee can only work in one warehouse, and the warehouse employs employees with employment terms and wages. Draw the ER diagram.

Answer:insert image description here

Guess you like

Origin blog.csdn.net/m0_68681879/article/details/129360782