Entity RelationshiEp Model

20
Element of E-R Model Entity An entity is a person, place, thing or event for which the data is collected and maintained. Some example of entity is as follow Person: Teacher, Student, Doctor Place: Country, City, Province Object: Vehicle, Toy, Furniture Event: Purchase, Admission, Registration Entity Type A set of entity with same attributes is called entity type. It is also known as entity class. For example, student entity type has attribute like name, roll no and age etc. Entity Instance A member of an entity class is known as an entity instance. It is also known as entity occurrence. For example class representative (CR) is an entity instance in entity type Student. Entity Set A set of all entities of a particular entity type in the database at a given point of time is called an entity set. For example an entity set student contains all students in the university. Note: Normally same name is used for both entity type and entity set. Weak Entity Teacher

description

Entity Relationship Model and Examples -Database Management Systems

Transcript of Entity RelationshiEp Model

Element of E-R ModelEntity

TeacherAn entity is a person, place, thing or event for which the data is collected and maintained. Some example of entity is as follow

Person: Teacher, Student, DoctorPlace: Country, City, ProvinceObject: Vehicle, Toy, FurnitureEvent: Purchase, Admission, RegistrationEntity TypeA set of entity with same attributes is called entity type. It is also known as entity class. For example, student entity type has attribute like name, roll no and age etc.Entity InstanceA member of an entity class is known as an entity instance. It is also known as entity occurrence. For example class representative (CR) is an entity instance in entity type Student.Entity Set A set of all entities of a particular entity type in the database at a given point of time is called an entity set. For example an entity set student contains all students in the university.Note: Normally same name is used for both entity type and entity set.Weak EntityAn entity that exists only if another entity exists is known as weak entity. It means that a week entity depend upon the existence of another entity.

Strong EntityAn entity that can exist without the existence of another entity is known as strong entity. A strong entity is also known as parent, owner or dominant entity.

Class

Fig: Strong Entity Class and Weak Entity StudentsFor example parent entity and child entity or Class entity and Student entity. In the above example parent and class are strong entity and child and students are week entity because they depend upon parent and Class respectively for their existence. A relationship between strong and weak entity is identifying relationship.Associative EntityAssociative entity is a type of entity that associates the instance of one or many entity types with one another. The attribute of associative represent the relationship between the entity instances.

Fig: Associative Entity

Professors

Fig: Associative EntityAttributesThe characteristics of an entity are called attributes or properties. For example name, address, class and email of a student are his attributes.

Attribute DomainAn attribute domain is a set of possible values for an attribute. All attribute have domain. The domain may consist of a range of values or some discrete values. For example Grade Point Average (GPA) can only be from 0 to 4.Simple Attributes

NameAn attribute that cannot be subdivided into smaller component is known as simple attribute or atomic attribute. For example a person can have only one gender and data of birth.

Student

Composite Attributes

Country Street CityAn attribute that can be subdivided into smaller component is known as composite attribute. For example address can be subdivided into street, city and country.

Address Employee

Single-Valued AttributeAn attribute that may contain single value is called single-value attribute. For example, age or gender of a person is single-value attribute.Multi-Valued AttributeAn attribute that may contain two or more values is called multi-value attribute. For example, a persons degrees, employees skill or persons profession.

Street Country City

Emp_ID

Address Employee

Stored AttributesAn attribute that is stored in the database is called stored attribute. Most of the attributes are stored attributes.Derived AttributesAn attribute which is not stored in database but derived from another value is called derived attribute. For example you can calculate age of a person from date of birth. Identifiers

RollNoIdentifier is an attribute that identifies an entity instance among other instance in entity set. For example there may be many instances of student entity set. But a student is uniquely identified by student ROLLNO.

An identifier can be unique or non-unique. Similarly an identifier can be simple or composite. It is simple if it consists of one attribute and it is composite if it consists of two or more attributes.RelationshipsA relationship is a logical connection between different entities. The entities that participate in a relationship are called participants. The relationship may be between different entities or between an entity and itself.

Degree of RelationshipA relationship may consist of many entities. The number of entities in a relationship is called degree of relationship.Unary RelationshipUnary relationship is a type of relationship that is established between the instances of same entity type. This is also known as recursive relationship.

Plays withPlayerTeacherLives withStudy withStudent

Binary RelationshipBinary relationship is a type of relationship that exists between two entity types.

One-to-One RelationshipThis type of relationship is exist when for each instance in first entity type there is only one instance in the second entity type and for each instance of second entity type there is only one instance in the first entity type.

HasCountryPresident

One-to-Many RelationshipThis type of relationship is exist when for each instance in first entity type there can be many instances in the second entity type and for each instance of second entity type there is only one instance in the first entity type.

HasCountryCity

Many-to-Many RelationshipThis type of relationship is exist when for each instance in first entity type there can be many instances in the second entity type and for each instance of second entity type there can be many instance in the first entity type.

StudiesStudent Course

Ternary RelationshipTernary relationship is a type of relationship that exists among the instances of three entity types.

works onDBASoftware Eng.

Project

Cardinality ConstraintsThe maximum number of relationship is called cardinality. The cardinality constraint specifies the number of instance of one entity that can be associated with each instance of the other entity. Three symbols normally used A circle means zero. A line means one. A crows foot symbol means many.Minimum CardinalityThe minimum number of instances of one entity that may be associated with each instance of another entity is known as minimum cardinality.If minimum cardinality is zero we say that it is optional. If the minimum cardinality is 1 then we say that it is mandatory.Maximum CardinalityThe maximum number of instances of one entity that may be associated with each instance of another entity is known as maximum cardinality. It can be either One or Many.Optional One

Optional Many

Mandatory One

Mandatory Many

HumanSubtype and Supertype Entities.

Non-MuslimsMuslimEE

In the above example individual and organization is the subtype of customer. It means that customer is super type of both the individual and organization. The curve in the line indicates that it is a subtype. The symbol E also indicates a subtype. This structure of super and subtype are also called generalization hierarchies because customer is a generalization of both individual and organization. It is also known as IS-A relationship because individual is a customer and organization also is a Customer.Generalization.Generalization is a process of identifying more general entity types. For example Human is a more general entity type than Muslim and Non Muslim. The entity type Human contains attribute that are more general than other two entity types for example Name, Age and Gender.Specialization.Specialization is a process of identifying more specific entity type. For example Muslim and Non Muslim is a more specific entity type than Human. The entity type Muslim contains attribute that are more specific to Muslim entity type than Human entity type for example IsScholar, ZakatPayer Etc.

Projects: A company has a number of employees. Each employee may be assigned to one or more project or may not be assigned to a project. A project must have at least one employee assigned and may have several employees assigned.

Assigned toEmployeeProject

A hospital has a patient history. Each patient has one or more history records. Each patient history record belongs to exactly one patient.

HasPatientRecord

An account can be charged against many projects though it may not be changed against any. A project must have at least one accounts charged against it. It may have many accounts charged against it.

Charged to AccountProject

An employee must manage exactly one department. A department have atleast one employee to manage it.

ManagessEmployeeDepartment

A department employs many persons. A person is employed by one department at most.

EmploysDepartmentPerson

A manager manages one department at most. A department is managed by one manager at most.

ManagesManagerDepartment

A team consists of many players. A player plays for only one team.

EmploysTeamPlayer

A lecturer teaches one course at most. A course is taught by exactly on lecturer.

TeacherLecturerCourse

A purchase order may be for many products. A product may appear on many purchase orders.

ContainsPurchase orderProduct

In school a student may be assigned one or more post like perfect, monitor or chairman. A post must be assigned to exactly one student. A student id identified with student ID, name, address and Date of birth. A post is identified with post_id and name. Draw ER diagram to show relationship between Student and Post with cardinality.

Name Stud_ID Post_IDAssigned toStudentsPost

Post_Name Date_Birth Address

In a school a teacher teaches one or more classes. Each class is taught by one or more teachers. A teacher is identified with teachers ID as identifier and name. A class is identified with class code and location. Draw ER diagram to show relationship between TEACHER and CLASS with cardinality.

Class_code Teacher_ID

TeachesTeacherClass

Location Name

A company has a number of employees. The attribute of employee include employee_id (identifier), name, address and birthday. The company also has several projects with attribute project_id (identifier), project_name and start_date. Each employee may be assigned to one or more project or may not be assigned to a project. A project must have at least one employee assigned and may have any number of employees assigned. An employee billing rate vary from project to project and company record the BILL_RATE for each employee when assigned to a particular project.

Billing_Rate

Is_Assigned Name Emp_ID Proj_IDEmployeeProject

Proj_ID DateBirth

Proj_Name Address

A university has large no of courses to offer. Course attribute includes Course_name, Course_No and units. Each course may have one or more courses as prerequisites or may have no prerequisites. Similarly a particular course may be a prerequisites for any number of courses or may not be prerequisite for any other course.

Course_Name Course_No

Is_prerequisiteCourse

Units

A laboratory has several chemists who work on one or more projects. Chemist also may use several type of equipment on each project. Attribute of chemist include Employee_ID (identifier), Name and phone_no. Attribute of Project includes Project_ID (identifier) and start_Date. Attribute of equipment include serial_no and Cost. The organization also wishes to record Assign_Date i.e. the data when equipment item was assigned to a particular chemist working on a particular project. A chemist must be assign to at least one project and one equipment item. An equipment item needs not to be assigned and a given project need not be assigned either a chemist or an equipment item.

Assign_Date

Assigned NameEmp_IDProj_IDChemistProject

Start_Date

EquipmentPhone

Serial_NoCost

A college course may have one or more dependent scheduled sections or may not have a schedule section. Attributes of Course include Course_ID, Course_Name, and units. Attributes of SECTION includes Section_Name and Semester_ID. Semester_ID is composed of two pairs: Semester and Year. Section_Number is an integer such as 1 or 2 that distinguishes one section from another for the same course but does not uniquely identify a section.

Section_NOCourse_ID

Has_Scheduled NameCOURSE

Semester_ID

Units

Year Semester

A hospital has a large number of registered physicians. Attribute of Physician include Physician and Specialty. Patients are admitted to the hospital by physician. Attribute of PATIENT include Patient_ID and Patient_Name. Any admitted must have exactly one admitting physician. A physician may admit any number of patients. Once admitted, a given patient must be treated by at least one physician. A particular physician may treat any number of patients or may not treat any patients. Whenever a patient is treated by a physician, the hospital records the details of the treatment (Treatment_date). Component of treatment_Detail include Date, Time and results.

Physician_IDAdmitsPatient_ID

PhysicianPatient

Patient_NameTreats

Speciality

Treatment_Detail

ResultsTimeDate

The firm has a number of sales offices in several states. Attribute of sale office include office_no (identifier) and Location. Each sale office is assigned one or more employees. Attribute of employee are employee_id (identifier) and employee_Name. An employee must be assigned to only one sale office.For each sale office there is always one employee assigned to manage that office. An employee may manage only the sales office to which he is assigned.The firm also lists property for sale. Attribute of property are property_ID (identifier) and Location. Component of location includes address, city, state and zip_code. Each unit of property must be listed with only one of the sales office. A sale office may have any number of properties listed, or may have no properties listed.Furthermore each unit of property has one or more owners. Attributes of owners are owner_id(identifier) and owner_name. An owner may own one or more units of property. An attribute of the relationship between property and owner is percent_Owned.

IsAssignedOffice_NoEmployee_ID

Sale OfficeEmployee

LocationEmployee_NameManages

Lists

Property_ID

Address

CityLocationProperty

State

Zip_Code

Parcent_OwnerOwns

Owner_ID

Owner_NameOwner