The ER diagram is also called the Entity Relationship Diagram, which provides a method for representing entity types, attributes, and relationships to describe the conceptual model of the real world.
Basic elements of the ER model
- Entity : It is represented by a box , and the entity is a noun (generally, concepts such as entities and entity sets are called entities)
- Attribute (a characteristic of the entity)
- In an entity, the attribute or attribute set that can uniquely identify the entity is called the "entity identifier"
- An entity has only one identifier, and the entity identifier is also called the entity's primary key
- The attribute is represented by an oval box , and the underlined attribute is the identifier (primary key)
- Connection : indicates the association relationship between one or more entities (1 to 1, 1 to many, many to many), the connection is represented by a diamond box , and the connection name is a verb
Entity type conversion to relational model
- Add the primary key of one party to multiple parties as the foreign key of multiple parties
- If it is many-to-many, add the primary key of both sides as the foreign key to the element of the diamond box, which becomes the new primary key of the diamond box element
- If it is one-to-one, you need to create two tables, and add the primary key of the other as a foreign key in one