Entity Relationship model
Mehwish sabih
RECAP
• Basic Definition
• Collection of data files
• Complex definition
• A database is a structure that contains information about many kinds of
entitiesand about the relationshipsbetween those entities.
Entity/data object
• Entity is a real world item or a concept which can exist on its own. It
can be a physical object or it can be a concept. The entity is
represented by a rectangular shape.
Entity
• Entity can be a week entity which means that entity must be defined
by a foreign key relationship with another entity and it can’t be
defined independently or by its attributes only. Week entity is
represented as follows:
Attribute
• These are the properties that describe the entities.
• Attributes are further divided into following types:
• Simple attribute
• Single-valued attribute
• Multi-valued attribute
• Derived attribute
Relationship
• When attribute of one entity refers to the attribute of another entity
then there exists a relationship between these two entities.
Keys
• They are used to establish and identify relationships between tables.
• They uniquely identify any record or row of data inside a table.
• A Key can be a single attribute or a group of attributes, where the
combination may act as a key.
• Types:
• Primary key
• Candidate key
• Composite key
• Foreign key
Primary key
• Key that is unique for each record. E.g.
• Roll#
• Empid
• National Identity Card Number
Composite key
• A key that is composed of more than one attributes.
• Doctor(empid, name, specialization)
• Patient(pid, name, address, age)
• Appointment(pid, empid, Adate, status)
Candidate key
Foreign key
Cardinality
• Type of Relationships
• For a single record in one entity how many records in the adjacent
entity exist.
• 1:1
• 1:M
• M:M
Chen style of erd
Martin Style of
ERD
ERD-Example1 University Admissions System
Activity 1: Manufacturer
A manufacturing company produces products. The following product
information is stored: product name, product ID and quantity on hand. These
products are made up of many components. Each component can be
supplied by one or more suppliers. The following component information is
kept: component ID, name, description, suppliers who supply them, and
products in which they are used.
Assumptions
• A supplier can exist without providing components.
• A component does not have to be associated with a supplier.
• A component does not have to be associated with a product. Not all
components are used in products.
• A product cannot exist without components.
Activity 2: car dealership
The dealership sells both new and used cars, and it operates a service facility. Base your
design on the following business rules:
• A salesperson may sell many cars, but each car is sold by only one salesperson.
• A customer may buy many cars, but each car is bought by only one customer.
• A salesperson writes a single invoice for each car he or she sells.
• A customer gets an invoice for each car he or she buys.
• A customer may come in just to have his or her car serviced; that is, a customer need not
buy a car to be classified as a customer.
• When a customer takes one or more cars in for repair or service, one service ticket is
written for each car.
• The car dealership maintains a service history for each of the cars serviced. The
service records are referenced by the car’s serial number.
• A car brought in for service can be worked on by many mechanics, and each mechanic
may work on many cars.
• A car that is serviced may or may not need parts (e.g., adjusting a carburetor or cleaning
a fuel injector nozzle does not require providing new parts).
Activity 3- Automechanics
• Employee(empid, name, specialization, experience, rate)
• Customer(custid, name, address)
• Car(VPN, make, model, color)
• Service(servId, name, cost, hours_required)
• workOrder(woid, date, car)
• workOrder is created as an appointment for the car. There may be
many services provided by multiple employees for a particular
workorder called workOrderItems. For each workOrderItem employee
records wrapUpNotes.
Keep the schema and erd save for sql

ERD introduction in databases model.pptx

  • 1.
  • 2.
    RECAP • Basic Definition •Collection of data files • Complex definition • A database is a structure that contains information about many kinds of entitiesand about the relationshipsbetween those entities.
  • 3.
    Entity/data object • Entityis a real world item or a concept which can exist on its own. It can be a physical object or it can be a concept. The entity is represented by a rectangular shape.
  • 4.
    Entity • Entity canbe a week entity which means that entity must be defined by a foreign key relationship with another entity and it can’t be defined independently or by its attributes only. Week entity is represented as follows:
  • 5.
    Attribute • These arethe properties that describe the entities. • Attributes are further divided into following types: • Simple attribute • Single-valued attribute • Multi-valued attribute • Derived attribute
  • 6.
    Relationship • When attributeof one entity refers to the attribute of another entity then there exists a relationship between these two entities.
  • 7.
    Keys • They areused to establish and identify relationships between tables. • They uniquely identify any record or row of data inside a table. • A Key can be a single attribute or a group of attributes, where the combination may act as a key. • Types: • Primary key • Candidate key • Composite key • Foreign key
  • 8.
    Primary key • Keythat is unique for each record. E.g. • Roll# • Empid • National Identity Card Number
  • 9.
    Composite key • Akey that is composed of more than one attributes. • Doctor(empid, name, specialization) • Patient(pid, name, address, age) • Appointment(pid, empid, Adate, status)
  • 10.
  • 11.
  • 12.
    Cardinality • Type ofRelationships • For a single record in one entity how many records in the adjacent entity exist. • 1:1 • 1:M • M:M
  • 13.
  • 14.
  • 15.
  • 16.
    Activity 1: Manufacturer Amanufacturing company produces products. The following product information is stored: product name, product ID and quantity on hand. These products are made up of many components. Each component can be supplied by one or more suppliers. The following component information is kept: component ID, name, description, suppliers who supply them, and products in which they are used. Assumptions • A supplier can exist without providing components. • A component does not have to be associated with a supplier. • A component does not have to be associated with a product. Not all components are used in products. • A product cannot exist without components.
  • 17.
    Activity 2: cardealership The dealership sells both new and used cars, and it operates a service facility. Base your design on the following business rules: • A salesperson may sell many cars, but each car is sold by only one salesperson. • A customer may buy many cars, but each car is bought by only one customer. • A salesperson writes a single invoice for each car he or she sells. • A customer gets an invoice for each car he or she buys. • A customer may come in just to have his or her car serviced; that is, a customer need not buy a car to be classified as a customer. • When a customer takes one or more cars in for repair or service, one service ticket is written for each car. • The car dealership maintains a service history for each of the cars serviced. The service records are referenced by the car’s serial number. • A car brought in for service can be worked on by many mechanics, and each mechanic may work on many cars. • A car that is serviced may or may not need parts (e.g., adjusting a carburetor or cleaning a fuel injector nozzle does not require providing new parts).
  • 18.
    Activity 3- Automechanics •Employee(empid, name, specialization, experience, rate) • Customer(custid, name, address) • Car(VPN, make, model, color) • Service(servId, name, cost, hours_required) • workOrder(woid, date, car) • workOrder is created as an appointment for the car. There may be many services provided by multiple employees for a particular workorder called workOrderItems. For each workOrderItem employee records wrapUpNotes.
  • 22.
    Keep the schemaand erd save for sql