DBMS-PPT 5

download DBMS-PPT 5

of 22

Transcript of DBMS-PPT 5

  • 8/12/2019 DBMS-PPT 5

    1/22

    Unit IIIUnit III -- Chapter 5Chapter 5

    Logical Database DesignLogical Database Design

    and theand the

    Mohit Agrawal @GU 1

  • 8/12/2019 DBMS-PPT 5

    2/22

    Relational Database Model

    Represents data in the form of tables.

    Consists of three components: Data strctre ! "ables with rows and colmns

    Data Maniplation Data #ntegrit$

    Mohit Agrawal @GU %

  • 8/12/2019 DBMS-PPT 5

    3/22

    Re ationRe ation AA relationrelation isis aa named&named& twotwo''dimensionaldimensional tabletable ofof datadata

    "able"able consistsconsists ofof rowsrows (records)(records) andand colmnscolmns (attribte(attribteoror field)field)

    Re*irementsRe*irements forfor aa tabletable toto *alif$*alif$ asas aa relationrelation::

    #t#t mstmst ha+eha+e aa ni*eni*e namename ,+er$,+er$ attribteattribte +ale+ale mstmst bebe atomicatomic (not(not mltimlti''

    +aled&+aled& notnot composite)composite)

    ,+er$,+er$ rowrow mstmst bebe ni*eni*e (can-t(can-t ha+eha+e twotwo rowsrowswithwith eactl$eactl$ thethe samesame +ales+ales forfor allall theirtheir fields)fields)

    AttribtesAttribtes (colmns)(colmns) inin tablestables mstmst ha+eha+e ni*eni*e

    /

    namesnames "he"he orderorder ofof thethe colmnscolmns mstmst bebe irrele+antirrele+ant

    "he"he orderorder ofof thethe rowsrows mstmst bebe irrele+antirrele+ant

    AlsoAlso calledcalled thethe 11stst NormalNormal FormFormMohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    4/22

    #s this a relation00

    Employee_ID Name Department Course Age

    122 A 3

    4544&

    Research

    $rs&months& 1%

    da$s

    162 7 8 "a& 9a+a

    /% $ears&

    months& %6

    da$s

    Mohit Agrawal @GU 6

    162 7 8 "a

    &

    months& %6da$s

  • 8/12/2019 DBMS-PPT 5

    5/22

    Con+ersion to Relation...

    Employee

    ID Name Department Course Age_Year

    Age_o

    nths Age_Days

    _

    122 A 3 4544 % / 1%

    122 A 3 Research % / 1%

    Mohit Agrawal @GU ;

    162 7 8 "a /% %6

    162 7 8 9a+a /% %6

  • 8/12/2019 DBMS-PPT 5

    6/22

    QuestionIs this a relation?AnswerYes: Unique rows and no

    multivalued attributes

    QuestionWhats the primary key? AnswerComposite: Emp_ID, Course_Title

    Mohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    7/22

    Correspondence with ,Correspondence with ,''R ModelR Model Relations (tables) correspond with entit$ t$pesRelations (tables) correspond with entit$ t$pes

    Rows correspond with entit$ instancesRows correspond with entit$ instances

    Colmns correspond with attribtesColmns correspond with attribtes

  • 8/12/2019 DBMS-PPT 5

    8/22

    >e$ ?ields>e$ ?ields >e$s>e$s areare specialspecial fieldsfields thatthat ser+eser+e twotwo mainmain prposesprposes::

    PrimaryPrimary keyskeys areare ni*eni*e identifiersidentifiers ofof thethe relationrelation ininestionestion..

    ,amples,amples incldeinclde emplo$eeemplo$ee nmbers&nmbers& socialsocial secrit$secrit$nmbers&nmbers& etcetc.. ThisThis isis howhow wewe cancan guaranteeguarantee thatthat allallrowsrows areare uniqueunique

    RelationshipsRelationships betweenbetween relationsrelations isis accomplishedaccomplished throghthroghForeignForeign keyskeys..

    ForeignForeign KeyKey isis anan attribteattribte inin aa relationrelation thatthat ser+esser+es asas aa

    primar$primar$ e$e$ oo anot eranot er re ationre ation

    >e$s>e$s cancan bebe simplesimple (a(a singlesingle field)field) oror compositecomposite (more(more thanthanoneone field)field)

    >e$s>e$s sall$sall$ areare sedsed asas indeesindees toto speedspeed pp thethe responseresponse toto

    serser *eries*eriesMohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    9/22

    Relational 4chema

    Foreign Key

    B

    Composite primary key

    Mohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    10/22

    =becti+es=becti+es

    Con+ertCon+ert anan ,R,R DiagramDiagram toto RelationalRelational 4chema4chema

    forfor frtherfrther implementationimplementation

    LearnLearn thethe processprocess ofof

  • 8/12/2019 DBMS-PPT 5

    11/22

    Integrity ConstraintsIntegrity Constraints

    datadata inin aa databasedatabase

    DomainDomain ConstraintsConstraints

    ,ntit$,ntit$ #ntegrit$#ntegrit$

    ReferentialReferential #ntegrit$#ntegrit$

    11

    ActionAction AssertionsAssertions FF 7siness7siness rlesrles..

    Mohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    12/22

    Domain Constraints

    Domain is the possible set of +ales that ma$

    e ass gne o an$ a r e

    Attri!ute Domain Name Description Domain

    Customer_ID Customer_IDs "et o# all possi!le

    customer IDs Character$ si%e 5

    Mohit Agrawal @GU 1%

    Customer_Name Customer_Names "et o# all possi!le

    customer Names Character$ si%e &5

    City Cities "et o# all possi!le

    cities

    Character$ si%e &'

  • 8/12/2019 DBMS-PPT 5

    13/22

    Entity Integrity

  • 8/12/2019 DBMS-PPT 5

    14/22

    Referential #ntegrit$

    Customer_

    ID Name Address City "tate (ostal_Code

    1222 A A7C Delhi Delhi 1%/6;

    1221 7 38 Mmbai Maharashtra 1%;6/

    122% C 4"U

  • 8/12/2019 DBMS-PPT 5

    15/22

    Referential #ntegrit$

    "ables"ables areare associatedassociated singsing ?oreign?oreign >e$s>e$s

    ReferentialReferential #ntegrit$#ntegrit$ rlerle statesstates thatthat ifif therethere isisaa foreignforeign e$e$ inin oneone relation&relation&

    eithereither eacheach foreignforeign e$e$ +ale+ale mstmst matchmatch aaprimar$primar$ e$e$ +ale+ale inin anotheranother relationrelation (Mandator$(Mandator$

    relations)orrelations)or

    thethe foreignforeign e$e$ mstmst bebe

  • 8/12/2019 DBMS-PPT 5

    16/22

    Referential

    integrity

    constraints aredrawn via arrows

    from dependent to

    1

    parent ta e

    Mohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    17/22

    7siness Rles7siness Rles

    4tatements4tatements thatthat definedefine oror constrainconstrain somesome

    aspecaspec oo ee s nesss ness AssertAssert bsinessbsiness strctrestrctre

    ControlFinflenceControlFinflence bsinessbsiness beha+iorbeha+ior ,pressed,pressed inin termsterms familiarfamiliar toto endend serssers

    1

    AtomatedAtomated throghthrogh D7M4D7M4 softwaresoftware

    Mohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    18/22

    ,ell,ell--"tructured +elations"tructured +elations

    AA relationrelation thatthat containscontains minimalminimal datadataredndanc$redndanc$ andand allowsallows serssers toto insert&insert&deletedelete andand date date rowsrows withotwithot casincasin

    datadata inconsistenciesinconsistencies

    GoalGoal isis toto a+oida+oid anomaliesanomalies

    InsertionInsertion AnomalyAnomaly!!addingadding newnew rowsrows forcesforcesserser toto createcreate dplicatedplicate datadata

    DeletionDeletion AnomalAnomal !!deletindeletin rowsrows mama casecase aa

    1

    lossloss ofof datadata thatthat woldwold bebe neededneeded forfor otherotherftreftre rowsrows

    odi#icationodi#ication AnomalyAnomaly!!changingchanging datadata inin aa rowrow

    forcesforces changeschanges toto otherother rowsrows becasebecase ofofdplicationdplication Mohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    19/22

    InsertionInsertion!!can-t enter a new emplo$ee withot ha+ing thecan-t enter a new emplo$ee withot ha+ing the

    em lo ee tae a classem lo ee tae a class

    Mohit Agrawal @GU 1B

    DeletionDeletion!!if we remo+e emplo$ee 162& we lose informationif we remo+e emplo$ee 162& we lose informationabot the eistence of a "a Acc classabot the eistence of a "a Acc class

    odi#icationodi#ication!!gi+ing a salar$ increase to emplo$ee 122 forcesgi+ing a salar$ increase to emplo$ee 122 forces

    s to pdate mltiple recordss to pdate mltiple records

  • 8/12/2019 DBMS-PPT 5

    20/22

    Data Normali%ationData Normali%ation

    5rimaril$5rimaril$ aa tooltool toto +alidate+alidate andand impro+eimpro+e aalogicallogical designdesign soso thatthat itit satisfiessatisfies certaincertain

    cons ra n scons ra n s aa avoavo unnecessaryunnecessaryduplicationduplication ofof datadata

    "he"he processprocess ofof decomposingdecomposing relationsrelations withwithanomaliesanomalies toto prodceprodce smaller&smaller&wellwell--structuredstructured

    %2 Mohit Agrawal @GU

  • 8/12/2019 DBMS-PPT 5

    21/22

    4teps in Con+ersion

  • 8/12/2019 DBMS-PPT 5

    22/22

    4teps in Con+ersion

    4",5 1 ! Map Reglar ,ntities Composite Attribtes

    Mlti'Haled Attribtes

    4",5 % ! Map ea ,ntities 4",5 / ! Map 7inar$ Relationships

    =ne to Man$

    Man$ to Man$

    =ne to =ne

    4",5 6 ! Map Associati+e ,ntities

    4",5 ; ! Map Unar$ Relationships

    4",5 ! Map ternar$ Relationships

    Mohit Agrawal @GU %%