+ All Categories
Home > Documents > Unit3 Mapping ERDs into Relations.pdf

Unit3 Mapping ERDs into Relations.pdf

Date post: 08-Aug-2018
Category:
Upload: divyasindhuri
View: 226 times
Download: 0 times
Share this document with a friend

of 53

Transcript
  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    1/53

    Unit 3 :

    Mapping ERDs into Relations

    Pratian Technologies (India) Pvt. Ltd.www.pratian.com

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    2/53

    Topics

    RDBMS Terminology

    Primary Key

    Foreign Key

    Candidate Key

    Integrity Constraints

    Copyright 2012 Pratian Technologies

    www.pratian.com

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    3/53

    Purpose information requirements structure

    Deliverable detailed design specifications

    Project Identification

    and Selection

    Project Initiation

    and Planning

    Analysis

    Logical Design

    Logical Design

    SDLC revisited

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Maintenance

    Database activity

    logical database design

    Physical Design

    Implementation

    Maintenance

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    4/53

    Sample Database Table

    C

    a

    r

    d

    Attributes

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Relation

    Degree

    i

    n

    a

    li

    t

    y

    Tuples

    Instance

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    5/53

    RDBMS Terminology

    Formal Relational Term Informal Equivalents

    Relation Table

    Tuple Row, Record

    Cardinality Number of Rows

    Attribute Column Field

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Degree Number of Columns

    Primary Key Unique Identifier

    Domain Set of legal values

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    6/53

    Candidate Key, Primary Key, Alternate Key

    A candidate key is an attribute that can uniquely identify arow in a table.

    ELEMENT

    Symbol Name AtomicNo MeltingPoint BoilingPoint

    Al Aluminium 13 933 2792

    Fe Iron 26 1811 3134

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Ni Nickel 28 1728 3186

    Cu Copper 29 1357 3200

    Ag Silver 47 1235 2435

    Au Gold 79 1337 3129

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    7/53

    Definitions

    Primary Key An attribute ( or combination of attributes ) that uniquely

    identifies each row in a relation

    Composite key

    A primary key that consists of more than one attribute

    Copyright 2012 Pratian Technologies

    www.pratian.com

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    8/53

    Foreign Key

    Attribute or attribute combination of one table whosevalues are required to match those of the primary key of

    some other table

    Each Foreign key represents a relationship between twoentity types.

    Copyright 2012 Pratian Technologies

    www.pratian.com

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    9/53

    Foreign Key - Definition

    They are added to relations as we go throughmapping process

    They allow the relations to be linked together

    A relation can have several foreign keys

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Generally there will be a foreign key from each table arelation is related to

    Foreign keys are usually show in italics or wigglyunderline

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    10/53

    AUTHORS TABLE

    AUTHORID NAME CITY COUNTRY

    A1 SHOBHA DE MUMBAI INDIA

    PUBLISHER TABLE

    Foreign Key

    Copyright 2012 Pratian Technologies

    www.pratian.com

    _

    P1 MCGRAW HILL NEW YORK U.S.A

    WORK TABLE

    AUTHORID PUB_ID TITLE

    A1 P1 SISTERS

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    11/53

    Integrity Constraints

    Domain Constraints All the values that appear in a column must be taken

    from the same domain

    Domain definition consists of the following components

    Domain Name

    Meaning

    Data type

    Size/ Length

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Allowable values or range

    Entity Integrity Primary key

    Referential Integrity

    Involves foreign key

    Operational Constraints Implement real world limitations

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    12/53

    Transforming E R Models to Relations

    name

    sex

    name dateofbirth

    empnodeptid

    EMPLOYEE

    EMPLOYEE ( empno , name, sex, dateofbirth, deptid)

    Copyright 2012 Pratian Technologies

    www.pratian.com

    EmpNo Name Sex DateOfBirth DeptId

    1 Mohan M 01-01-1978 10

    2 Sarvesh M 12-01-1980 20

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    13/53

    Properties of a Relation

    Each entity or a table in a database has a uniquename

    An entry at the intersection of each row and column

    is atomic. There can be no multivalued attributes in arelation

    Each row is unique.

    Copyright 2012 Pratian Technologies

    www.pratian.com

    ac a r u e or co umn w n a a e as a un quename.

    The sequence / arrangement of columns isinsignificant

    The sequence / arrangement of rows is insignificant

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    14/53

    Mapping the ER Model

    Mapping Strong entity

    name

    deptname costcenter

    deptid

    DEPARTMENT

    DEPARTMENT ( DeptId, DeptName, CostCenter)

    Copyright 2012 Pratian Technologies

    www.pratian.com

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    15/53

    Mapping 1:1 Relationship

    Mandatory at both ends

    Mandatory at one end and optional at theother

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Optional at both ends

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    16/53

    Mandatory at both ends Option 1

    EMPLOYEE (empno, name)

    CONTRACT (contractno, startdate, duedate)

    EMPLOYEE CONTRACThas

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Amalgamated into one as

    EMPLOYEE (empno, name, contractno, startdate, duedate)

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    17/53

    Mandatory at both ends Option 2

    EMPLOYEE (empno, name)

    CONTRACT (contractno, startdate, duedate)

    EMPLOYEE CONTRACThas

    Copyright 2012 Pratian Technologies

    www.pratian.com

    The same can be kept apart using Foreign Key

    EMPLOYEE (empno, name, contractno)

    CONTRACT (contractno, startdate, duedate)

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    18/53

    Mandatory at both ends Option 3

    EMPLOYEE (empno, name)

    CONTRACT (contractno, startdate, duedate)

    EMPLOYEE CONTRACThas

    Copyright 2012 Pratian Technologies

    www.pratian.com

    r

    EMPLOYEE (empno, name)CONTRACT (contractno, startdate, duedate, empno)

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    19/53

    Mandatory at one end and Optional at other end

    EMPLOYEE CONTRACThas

    EMPLOYEE (empno, name)

    CONTRACT (contractno, startdate, duedate)

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Amalgamated into one as

    EMPLOYEE (empno, name, contractno, startdate,duedate)

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    20/53

    Mandatory at one end and Optional at other end

    EMPLOYEE CONTRACThas

    EMPLOYEE (empno, name) CONTRACT (contractno, startdate, duedate)

    Copyright 2012 Pratian Technologies

    www.pratian.com

    The same can be kept apart using Foreign KeyEMPLOYEE (empno, name, contractno)CONTRACT (contractno, startdate, duedate)

    Map the foreign key into Employee - the key is null foremployee without a contract. Incorrect Design

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    21/53

    FK in EMPLOYEE

    Empno Name Contract No

    10 Gordon 1

    11 Andrew NULL

    EMPLOYEE

    CONTRACT

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Contractno StartDate DueDate

    1 1st

    Jan 2007 10th

    Oct 2007

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    22/53

    Mandatory at one end and Optional at other end

    EMPLOYEE CONTRACThas

    EMPLOYEE (empno, name)CONTRACT (contractno, startdate, duedate)

    Copyright 2012 Pratian Technologies

    www.pratian.com

    EMPLOYEE (empno, name)CONTRACT (contractno, startdate, duedate, empno)

    Map the foreign key into Contract

    empno is mandatory thus never null.

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    23/53

    FK in CONTRACT

    Empno Name

    EMPLOYEE

    So for 1:1 optional relationships, take the primary keyfrom the mandatory end and add it to the optional end

    as a foreign key.

    Copyright 2012 Pratian Technologies

    www.pratian.com

    11 Andrew

    CONTRACT

    Contractno StartDate EndDate Empno

    1 1st Jan 2007 10th Oct 2007 10

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    24/53

    Optional Participation at Both Ends

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Such examples cannot be amalgamated as you

    could not select a primary key.

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    25/53

    Mapping 1:M Relationships

    DEPARTMENT (Deptid, name, type, location) EMPLOYEE (empno, name)

    DEPARTMENT EMPLOYEEhas

    Copyright 2012 Pratian Technologies

    www.pratian.com

    After Mapping the foll relations are produced

    DEPARTMENT (Deptid, name, type, location)EMPLOYEE (empno, name, Deptid)

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    26/53

    Mapping 1:M in Unary Relationships

    Employee manages employees

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Employee(employee_no, manager_no, name,...)

    Foreign keyPrimary key

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    27/53

    EMPNO ENAME JOB MGR SAL

    7369 SMITH CLERK 7902 1800

    7499 ALLEN SALESMAN 7698 1600

    7521 WARD SALESMAN 7698 1250

    7566 JONES MANAGER 7839 2975

    7654 MARTIN SALESMAN 7698 1250

    7698 BLAKE MANAGER 7839 2850

    Mapping 1:M in Unary Relationships

    Copyright 2012 Pratian Technologies

    www.pratian.com

    7788 SCOTT ANALYST 7566 3000

    7839 KING PRESIDENT 6000

    7844 TURNER SALESMAN 7698 9300

    7876 ADAMS CLERK 7788 2100

    7900 JAMES CLERK 7698 1950

    7902 FORD ANALYST 7566 7777

    7934 MILL CLERK 7782 7654

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    28/53

    Mapping M:N Relationships

    A new table has to be created to map M : N relations

    AUTHOR PUBLISHER

    M N

    Copyright 2012 Pratian Technologies

    www.pratian.com

    authorid name

    city country

    pub_id name

    city country

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    29/53

    Mapping N:M Relationships

    AUTHOR PUBLISHERAuthor_Publisher1 N N 1

    authorid pub_id title

    Copyright 2012 Pratian Technologies

    www.pratian.com

    authoridname

    city country

    pub_id name

    city country

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    30/53

    Mapping N:M Relationships

    AUTHORS TABLE

    AUTHORID NAME CITY COUNTRY

    A1 SHOBHA DE MUMBAI INDIA

    PUBLISHER TABLE

    PUB ID NAME CITY COUNTRY

    Copyright 2012 Pratian Technologies

    www.pratian.com

    _

    P1 MCGRAW HILL NEW YORK U.S.A

    WORK TABLE

    AUTHORID PUB_ID TITLE

    A1 P1 SISTERS

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    31/53

    Summary

    1-1 relationshipsDepending on the requirement of the relationship,the entities are either combined or the primary keyof one entity type is placed as a foreign key in the

    other relation.

    1-m r l i n hi

    Copyright 2012 Pratian Technologies

    www.pratian.com

    The primary key from the one side is placed as aforeign key in the many side.

    m-n relationshipsA new relation is created with the primary keysfrom each entity forming a composite key.

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    32/53

    Lets check our understanding!!!

    Copyright 2012 Pratian Technologies

    www.pratian.com

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    33/53

    Primary Key

    Forei n Ke

    Identify keys in these relations

    Copyright 2012 Pratian Technologies

    www.pratian.com

    (implements 1:N relationship

    between customer and order)

    Combined, these are a composite

    primary key (uniquely identifies the

    order line)individually they are

    foreign keys (implement M:N

    relationship between order and product)

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    34/53

    (a) CUSTOMERentity type withsimple

    attributes

    Write Customer relation for the foll.

    Copyright 2012 Pratian Technologies

    www.pratian.com

    (b) CUSTOMER relation

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    35/53

    (a) CUSTOMERentity type withcompositeattribute

    Map the foll into a relation

    Copyright 2012 Pratian Technologies

    www.pratian.com

    (b) CUSTOMER relation with address detail

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    36/53

    Map the foll. into relations

    (a)

    Copyright 2012 Pratian Technologies

    www.pratian.com1tomany relationship between original entity and new relation

    Multivalued attribute becomes a separate relation with foreign key(b)

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    37/53

    Map the foll ERD

    Copyright 2012 Pratian Technologies

    www.pratian.com

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    38/53

    NOTE: the domain constraint

    for the foreign key shouldNOT allow null value if

    DEPENDENT is a weak

    entity

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Foreign key

    Composite primary key

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    39/53

    Map the Relationship between customers and orders

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Note the mandatory one

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    40/53

    Mapping the relationship

    Again, no null value in the

    foreign keythis is

    Copyright 2012 Pratian Technologies

    www.pratian.com

    because of the mandatory

    minimum cardinality

    Foreign key

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    41/53

    Map an M:N relationship into relations

    E-R diagram (M:N)

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Hint :The Supplies relationship will need to become a separate relatio

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    42/53

    Solution: Three resulting relations

    Composite primary key

    Copyright 2012 Pratian Technologies

    www.pratian.com

    intersectionrelation

    Foreign key

    Foreign key

    M bi l i hi

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    43/53

    Map a binary 1:1 relationship

    In_charge relationship

    Copyright 2012 Pratian Technologies

    www.pratian.com

    S l ti R lti l ti

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    44/53

    Solution: Resulting relations

    Copyright 2012 Pratian Technologies

    www.pratian.com

    M th f ll ERD i t l ti

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    45/53

    Map the foll ERD into relations

    Copyright 2012 Pratian Technologies

    www.pratian.com

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    46/53

    Copyright 2012 Pratian Technologies

    www.pratian.com

    M h f ll ERD i i i i h id ifi

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    47/53

    Map the foll ERD : an associative entity with an identifier

    Associative entity

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Three resulting relations

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    48/53

    Three resulting relations

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Map a unary 1:N relationship

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    49/53

    Map a unary 1:N relationship

    (a) EMPLOYEE entity with

    Manages relationship

    Copyright 2012 Pratian Technologies

    www.pratian.com

    (b) EMPLOYEErelation with

    recursive foreign

    key

    Map a unary M:N relationship

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    50/53

    Map a unary M:N relationship

    (a) Bill-of-materials

    relationships (M:N)

    Copyright 2012 Pratian Technologies

    www.pratian.com

    (b) ITEM and

    COMPONENT

    relations

    Map a ternary relationship

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    51/53

    Map a ternary relationship

    Ternary relationship with associative entity

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Solution

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    52/53

    Solution

    Copyright 2012 Pratian Technologies

    www.pratian.com

    Remember that theprimary key MUST be

    unique

    Question time

  • 8/22/2019 Unit3 Mapping ERDs into Relations.pdf

    53/53

    Please try to limit the questions to the topics discussed during the session. Thank you.

    Question time

    Copyright 2012 Pratian Technologies

    www.pratian.com


Recommended