实体vs Attribute
实体关系建模(ERM)技术被广泛用于建模数据库。实体关系建模是提出数据的抽象和概念表示的过程。ERM的主要构建块之一是一个实体。实体代表一个现实世界的对象或可以独立站立并可以独特地识别的事物。属性是这些实体的属性。ER图是实体关系建模的产物。ER图是使用实体,属性和其他符号(例如关系)绘制的。
什么是实体?
An entity represents a thing that can exist independently and that can be identified uniquely. More specifically, an entity often represents a class, group or category of similar objects. Most often, an entity represents a real world object such as a car or an employee. Entities can be though of as nouns that come up during the description of the problem to be solved. Entities are represented as tables in relational databases. In general, each entity will map to exactly one table in the database. Individual rows in the tables correspond to the actual instances of the object/thing represented by the entity. For example, in an Employee database, each row corresponds to records of individual employees of the company.
What is an Attribute?
In the entity-relationship modeling, properties of entities are called attributes. In other words, attributes represent a sub group of information of the object represented by the entity. Attributes define the individual instances and help to differentiate between each instance by describing their characteristic. It is important to note that attributes cannot be set-valued and they should be atomic. In relational databases, where entities are realized as tables, each column represents the attributes of these entities. For example, in the Employee table, columns such as department, rank and salary are examples of attributes of the employees. In order to differentiate between individual instances of the entity, one or more attribute fields with unique values (for all instances) can be selected as a key. For example, the social security number attribute (which is unique for all employees) is often used as the primary key of an Employee table. Sometimes multiple attributes can makeup the primary key as well.
What is the difference between an Entity and an Attribute?
In entity-relationship modeling, entities represent real world objects/things that can be identified as unique and independent, while attributes represent the properties of those entities. In relational databases, entities become tables (each row representing individual instances), whereas attributes become columns of those corresponding tables. When designing databases, it is common to have confusion over choosing an entity vs. an attribute to represent a certain real word object. For example, should the address of the employee represented as an attribute or another entity (connected to employee entity through a relationship)? A general rule of thumb is, if an employee has more than one address, then the address must be an entity (because attributes are not set-valued). Similarly, if the structure of the address is important to capture, then again the address should be an entity (because attributes are atomic).
Leave a Reply