The Entity-Relationship Diagram ER Diagram • Entity Relationship (ER) Diagram – A detailed, logical

  • View
    2

  • Download
    0

Embed Size (px)

Text of The Entity-Relationship Diagram ER Diagram • Entity Relationship (ER) Diagram – A...

  • The Entity-Relationship Diagram

  • Overview of Database Design

    • Conceptual design: (ER Model is used at this stage.) – What are the entities and relationships in the

    enterprise? – What information about these entities and relationships – What information about these entities and relationships

    should we store in the database? – What are the integrity constraints or business rules that

    hold? – A database “schema” in the ER Model can be

    represented pictorially (ER diagrams). – We can map an ER diagram into a relational schema.

  • ER Diagram

    • Entity Relationship (ER) Diagram – A detailed, logical representation of the entities,

    associations and data elements for an organization or

    business

    – An entity-relationship (ER) diagram is a specialized graphic that illustrates the interrelationships between entities in a

    database.

  • Framework for E/R

    • The E/R model allows us to sketch database schema designs

    • Design is a serious business. • The “boss” knows they want a database, but they

    4

    • The “boss” knows they want a database, but they don’t know what they want in it.

    • Sketching the key components is an efficient way to develop a working database.

  • Main constructors of ER

    – Data entities

    – Relationships– Relationships

    – Attributes

  • ER Model Basics

    • Entity: Real-world object distinguishable from other objects. An entity is described (in DB) using a set of attributes.DB) using a set of attributes.

    • An entity is shown in a rectangle.

    • Entity Set: A collection of similar entities. E.g., all employees. – All entities in an entity set have the same set of

    attributes. (Until we consider ISA hierarchies, anyway!)

  • Entities

    • Examples of entities: – Person: EMPLOYEE, STUDENT, PATIENT – Place: STORE, WAREHOUSE – Object: MACHINE, PRODUCT, CAR – Event: SALE,REGISTRATION, RENEWAL – Concept: ACCOUNT, COURSE– Concept: ACCOUNT, COURSE

    • Guidelines for naming and defining entity types: – An entity type name is a singular noun – An entity type should be descriptive and specific – An entity name should be concise – Event entity types should be named for the result of the event, not the

    activity or process of the event.

  • An entity’s name should be: • Unique in the entire organization; furthermore, try to avoid similar

    names for different entities, such as PROJECT and P ROJECTION.

    Choose a non-confusing name for both.

    PROJECT PROJECTION

  • If different terms are used to define the same thin g under different departments synonyms can be defined. For example, some departments may call it a CUSTOMER while other s may call a CLIENT.

    Finally one has to be chosen in database but when s peaking toFinally one has to be chosen in database but when s peaking to different people we must choose their terms.

  • Instances of entities If you are not certain whether something is an enti ty or not, it may help to ask yourself the question,

    “What are the instances (examples) of this entity?”

  • To make sure your list includes real entities,

    Here are some other ways:

    Validate Entities

    Is its name a noun? Not all nouns represent entitie s, but all entity names should be nouns.

  • To make sure your list includes real entities,

    Here are some other ways:

    Validate Entities

    Does this entity have any attributes?

    For example, if you think you have an entity named STUDENT, do you need to store facts about students?

    Name, Student Number, Address, Birth Date .... YES, IT IS AN ENTITY.

  • To make sure your list includes real entities,

    Here are some other ways:

    Validate Entities

    If you think you have an entity called CUSTOMER NAM E, ask the same question: Does it have any facts, attributes t o store? The country of origin, number of wovels, meaning of the name ....

    Are these really important facts to store in your d atabase?

    NOT! Then CUSTOMER NAME is not an entity.

  • Summary

    • An entity is a thing of significance about which information needs to be stored; a class or category of thing; a named thing.

    • When considering whether something is an entity or not, it helps to ask yourself the question, “What would some instances of this entity be?”

    • An entity’s name should be unique in the entire organization and familiar to all.

    • Once you have identified an entity and named it, you should diagram it; the diagram pictorially represents entities, the vital business relationships between them and the attributes to describe them.

    • An attribute is any detail that serves to qualify, identify, classify, quantify, or express the state of an entity.

  • Logical DB Design: ER to Relational

    • Entity sets to tables: CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot INTEGER,

    ssn name

    lot lot INTEGER, PRIMARY KEY (ssn))

    Employees

  • Attributes

    • An attribute is a property or characteristic for an entity or a relationship type.

    • It is shown in an oval.

    • Example of entity types and associated attributes:

    STUDENT: Student_ID, Student_Name,

    Home_Address, Phone_Number, Major

  • Guidelines for naming attributes

    – An attribute name is a noun.

    – An attribute name should be unique

    – To make an attribute name unique and clear, each – To make an attribute name unique and clear, each attribute name should follow a standard format

    – Similar attributes of different entity types should use similar but distinguishing names.

  • Simple and Composite attributes

    • A simple(atomic) attribute is an attribute composed of a single component with an independent

    existence.

    • can not be further subdivided into smaller components.

    • A composite attribute, sometimes called a group attribute, is an attribute composed of multiple

    components, each with an independent existence.

    • The names chosen for composite attributes should be descriptive and general

  • Composite Attribute

  • Single-valued and Multi-valued attribute

    • Single-valued attribute that holds a single value for each occurrence of an entity type.

    • Multi-valued attribute that holds multiple values for each occurrence of an entity type.

    • Multi-valued attributes are mapped by using additional • Multi-valued attributes are mapped by using additional relation schema. For each multi-valued attribute A, create a new relation R.

    • This relation will include attribute corresponding to A plus the primary key K of the entity type or relationship type that has A as attribute. Combination of A and K becomes primary key of R.

  • Example: multivalued attribute

    Multivalued attribute… an employee

    may have more than one skill.

  • Derived attributes

    • An attribute that represents a value that is derivable from the value of a related attribute or set of

    attributes, not necessarily in the same entity type.

    • The values are held by some attributes may be derived.

    • The oval representing a derived attribute is drawn with a dash line

  • Candidate Keys

    • Some tables contain more than one column (or combination of columns –composite key) that can act as a primary key. These columns all possess the uniqueness property of a primary key. Here, the uniqueness property of a primary key. Here, also, null values are not allowed. These columns are called candidate keys. However, only one is designated as the primary key

    • All candidate keys which are not chosen as "primary key" are Alternate keys.

  • Primary Key

    • A primary key is used to uniquely identify each row in a table.

    • this key does not allow null values and also does not allow duplicate values.not allow duplicate values.

    • Primary keys can be specified either when the table is created (using CREATE TABLE) or by changing the existing table structure (using ALTER TABLE).

  • Example

    • CREATE TABLE Student (SID integer,

    Last_Name varchar(30), Last_Name varchar(30),

    First_Name varchar(30),

    PRIMARY KEY (SID));

  • Foreign Key

    • A foreign key is a field (or fields) that points to the primary key of another table. The purpose

    of the foreign key is to ensure referential

    integrity of the data. In other words, only integrity of the data. In other words, only

    values that are supposed to appear in the

    database are permitted.

  • Example

    • create table Enroll (Student_SID integer, Courses_CID char(10),

    Foreign Key(Student_SID) references

    Student(SID),Student(SID),

    Foreign Key(Courses_CID)references

    Courses(CID)

    );

  • Entity Type Key

    • Every (regular) entity type has at least one key • The entity type key is defined in a similar way as the rel