Presentation is loading. Please wait.

Presentation is loading. Please wait.

Entities and Attributes

Similar presentations

Presentation on theme: "Entities and Attributes"— Presentation transcript:

1 Entities and Attributes
The most basic object that the ER model represents is an entity An entity maybe an object with a physical existence (a person, a car, house…) or it maybe an object with conceptual existance (a company, a job, or a course) Each entity has Attributes --- the particular properties that describe it

2 Attributes Several types of attribute occur in the ER model
Simple vs. Composite Single value vs. Multi-value Stored vs. Derived

3 Composite vs. Simple Attributes
Composite attributes can be divided into smaller subparts. For example: Address attribute of the EMPLOYEE entity can be further subdivided into street_address, city, state, zip_code Simple attributes can not be further divisible For example, street_address can be subdivided into Number, street, and apt# The value of composite attribute is the concatenation of the values of its constituent simple attributes

4 Example of a composite attribute

5 Single value vs. Multi-value
Most attributes have a single value for a particular entity; such attribute are called single-valued In some cases an attribute can have a set of value for the same entity --- for example, colors attribute for a car, or a college_degree for a person Such attributes are called multivalued A multivalued attribute may have lower and upper bonds to constrain the number of values allowed for each entity

6 Stored vs. Derived In some cases, two (or more) attribute values are related --- for example, the Age and Birth_date of a person The Age attribute is called a derived attribute and is said to be derived from the Birth_date attribute, which is called a stored value

7 NULL Values In some cases, a particular entity may not have an applicable value for an attribute For example, apt#, college degree, NULL can also be used if we do not know the value of an attribute for a particular entity---home phone The meaning of the former type of NULL is not applicable, whereas the meaning of the later is unknown

8 Entity Types A database usually contains groups of entities that are similar An entity type defines a collection of entities that have the same attributes For example---EMPLOYEE An entity type is represented in ER diagrams as a rectangular box enclosing the entity type name Attributes names are enclosed in ovals and are attached to their entity type by straight lines Composite attributes are attached to their component attributes by straight lines Multivalued attributes are displayed in double ovals

9 Entity Type CAR with two keys and a corresponding Entity Set

10 Key Attributes An important constrain on the entities of an entity type is the KEY on attributes An attribute of an entity type for which each entity must have a unique value is called a key attribute of the entity type. For example, SSN of EMPLOYEE.

11 Entity Types and Key Attributes (2)
A key attribute may be composite. VehicleTagNumber is a key of the CAR entity type with components (Number, State). An entity type may have more than one key. The CAR entity type may have two keys: VehicleIdentificationNumber (popularly called VIN) VehicleTagNumber (Number, State), also called license plate number. Each key is underlined

12 Entity Type CAR with two keys and a corresponding Entity Set

13 Initial Design of Entity Types for the COMPANY Database Schema
Based on the requirements, we can identify four initial entity types in the COMPANY database: DEPARTMENT PROJECT EMPLOYEE DEPENDENT Their initial design is shown on the following slide The initial attributes shown are derived from the requirements description

14 Department The company is organized into DEPARTMENTs. Each department has a name, number and an employee who manages the department. We keep track of the start date of the department manager. A department may have several locations.

15 Projects Each department controls a number of PROJECTs. Each project has a unique name, unique number and is located at a single location.

16 EMPLOYEE We store each EMPLOYEE’s name, social security number, address, salary, sex, and birthdate. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee.

17 Dependent Each employee may have a number of DEPENDENTs.
For each dependent, we keep track of their name, sex, birthdate, and relationship to the employee.


19 Relationship ER model has three main concepts:
Entities (and their entity types and entity sets) Attributes (simple, composite, multivalued) Relationships (and their relationship types and relationship sets)

20 Relationship In ER diagrams, we represent the relationship type as follows: Diamond-shaped box is used to display a relationship type Connected to the participating entity types via straight lines

21 Relationship example Consider a relationship type work_for between the two entities type EMPLOYEE and DEPARTMENT Each relationship instance in the relationship set associates one EMPLOYEE entity and one DEPARTMENT entity

22 Relationship between EMPLOYEE and DEPARTMENT

23 Degree of Relationship Type
The degree of a relationship is the number of participating entity types A relationship type of degree two is called Binary, and one of degree three is called Ternary Work_for relationship is binary An example of ternary relationship is SUPPLY---where S supply part P to project J

24 Recursive Relationship
In some cases, the same entity type participates more than once in a relationship type in different roles Example Employee and supervised

25 Constrains on Relationship types
Sometimes if we want to describe “each employee must work for exactly one department”, then we would like to describe this constrain in the schema The cardinality ratio for a binary relationship specifies the max number of relationship instances that an entity can participate in. For example---in the Works_for binary relationship, DEPARTMENT:EMPLOYEE is of cardinality ration 1:N, meaning each department can be related to any number of employees, but an employee can only be related to one department

26 Relationship between EMPLOYEE and DEPARTMENT

27 cardinality ratio The possible cardinality ratio for binary relationships are 1:1, 1:N, N:1, M:N Example: 1:1 Manages relationship between employee and department M:N an employee can work on several projects and a project can have several employees


29 Enhanced Entity-Relationship Model
Since 1970s there has been an increase in emergence of new database applications with more demanding requirements. Basic concepts of ER modeling are not sufficient to represent requirements of newer, more complex applications. Response is development of additional ‘semantic’ modeling concepts.

30 Enhanced-ER (EER) Model Concepts
Includes all modeling concepts of basic ER Additional concepts: subclasses/superclasses, specialization/generalization, categories, attribute inheritance The resulting model is called the enhanced-ER or Extended ER (E2R or EER) model It is used to model applications more completely and accurately if needed It includes some object-oriented concepts, such as inheritance

31 Subclasses and Superclasses (1)
An entity type may have additional meaningful subgroupings of its entities Example: EMPLOYEE may be further grouped into SECRETARY, ENGINEER, MANAGER, TECHNICIAN, SALARIED_EMPLOYEE, HOURLY_EMPLOYEE,… Each of these groupings is a subset of EMPLOYEE entities Each is called a subclass of EMPLOYEE EMPLOYEE is the superclass for each of these subclasses These are called superclass/subclass relationships. Example: EMPLOYEE/SECRETARY, EMPLOYEE/TECHNICIAN


33 Subclasses and Superclasses (2)
These are also called IS-A relationships (SECRETARY IS-A EMPLOYEE, TECHNICIAN IS-A EMPLOYEE, …). Note: An entity that is member of a subclass represents the same real-world entity as some member of the superclass The Subclass member is the same entity in a distinct specific role An entity cannot exist in the database by being a member of a subclass; it must also be a member of the superclass A member of the superclass can be optionally included as a member of any number of its subclasses Example: A salaried employee who is also an engineer belongs to the two subclasses ENGINEER and SALARIED_EMPLOYEE It is not necessary that every entity in a superclass be a member of some subclass

34 Attribute Inheritance in Superclass / Subclass Relationships
An entity that is member of a subclass inherits all attributes of the entity as a member of the superclass It also inherits all relationships

35 Specialization Is the process of defining a set of subclasses of a superclass The set of subclasses is based upon some distinguishing characteristics of the entities in the superclass Example: {SECRETARY, ENGINEER, TECHNICIAN} is a specialization of EMPLOYEE based upon job type. May have several specializations of the same superclass Example: Another specialization of EMPLOYEE based in method of pay is {SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}. Superclass/subclass relationships and specialization can be diagrammatically represented in EER diagrams Attributes of a subclass are called specific attributes. For example, TypingSpeed of SECRETARY The subclass can participate in specific relationship types. For example, BELONGS_TO of HOURLY_EMPLOYEE

36 Example of a Specialization

37 Generalization The reverse of the specialization process
Several classes with common features are generalized into a superclass; original classes become its subclasses Example: CAR, TRUCK generalized into VEHICLE; both CAR, TRUCK become subclasses of the superclass VEHICLE. We can view {CAR, TRUCK} as a specialization of VEHICLE Alternatively, we can view VEHICLE as a generalization of CAR and TRUCK

38 Generalization and Specialization
Arrow pointing to the generalized superclass represents a generalization Arrows pointing to the specialized subclasses represent a specialization We do not use this notation because it is often subjective as to which process is more appropriate for a particular situation We advocate not drawing any arrows in these situations A superclass or subclass represents a set of entities Shown in rectangles in EER diagrams (as are entity types) Sometimes, all entity sets are simply called classes, whether they are entity types, superclasses, or subclasses

39 Generalization A bottom-up design process – combine a number of entity sets that share the same features into a higher-level entity set. Specialization and generalization are simple inversions of each other; they are represented in an E-R diagram in the same way. The terms specialization and generalization are used interchangeably.

40 Constraints on Specialization and Generalization (1)
If we can determine exactly those entities that will become members of each subclass by a condition, the subclasses are called predicate-defined (or condition-defined) subclasses Condition is a constraint that determines subclass members Display a predicate-defined subclass by writing the predicate condition next to the line attaching the subclass to its superclass If all subclasses in a specialization have membership condition on same attribute of the superclass, specialization is called an attribute defined-specialization Attribute is called the defining attribute of the specialization Example: JobType is the defining attribute of the specialization {SECRETARY, TECHNICIAN, ENGINEER} of EMPLOYEE If no condition determines membership, the subclass is called user-defined Membership in a subclass is determined by the database users by applying an operation to add an entity to the subclass Membership in the subclass is specified individually for each entity in the superclass by the user

41 Constraints on Specialization and Generalization (2)
Two other conditions apply to a specialization/generalization: Disjointness Constraint: Specifies that the subclasses of the specialization must be disjointed (an entity can be a member of at most one of the subclasses of the specialization) Specified by d in EER diagram If not disjointed, overlap; that is the same entity may be a member of more than one subclass of the specialization Specified by o in EER diagram Completeness Constraint: Total specifies that every entity in the superclass must be a member of some subclass in the specialization/ generalization Shown in EER diagrams by a double line Partial allows an entity not to belong to any of the subclasses Shown in EER diagrams by a single line

42 Constraints on Specialization and Generalization (3)
Hence, we have four types of specialization/generalization: Disjoint, total Disjoint, partial Overlapping, total Overlapping, partial Note: Generalization usually is total because the superclass is derived from the subclasses.

43 Example of disjoint partial Specialization

Download ppt "Entities and Attributes"

Similar presentations

Ads by Google