AIS relational databases

Embed Size (px)

Citation preview

  • 8/19/2019 AIS relational databases

    1/79

    Copyright © Pearson Education Limited 2015.

    Relational Databases

    Chapter

    !1

  • 8/19/2019 AIS relational databases

    2/79

    Copyright © Pearson Education Limited 2015.

    Learning Objectives

    " E#plain the importance and ad$antages o% databases& as 'ell as thedi%%erence bet'een database and %ile!based legacy systems.

    " E#plain the di%%erence bet'een logical and physical $ie's o% adatabase.

    " E#plain %undamental concepts o% database systems such as D()*&schemas& the data dictionary& and D()* languages.

    " Describe 'hat a relational database is and ho' it organi+es data.

    " Create a set o% 'ell!structured tables to properly store data in arelational database.

    !2

  • 8/19/2019 AIS relational databases

    3/79

    Copyright © Pearson Education Limited 2015.

    INTRODUCTION

    " Relational databases underlie most modernintegrated ,-*s. /hey are the most popular type o% database used

    %or transaction processing. -n this chapter& 'ell de%ine the concept o% a

    database.

  • 8/19/2019 AIS relational databases

    4/79

    Copyright © Pearson Education Limited 2015.

    What Is a Database?

    " E%%iciently and centrally coordinates in%ormation %or arelated group o% %iles

    "  , %ile is a related group o% records

    "  , record is a related group o% %ields"  , %ield is a speci%ic attribute o%

    interest %or the entity record

    !3

  • 8/19/2019 AIS relational databases

    5/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES" Lets e#amine some basic principles about ho' data are

    stored in computer systems.  ,n entity is anything about 'hich the organi+ation 'ishes to

    store data. ,t your college or uni$ersity& one entity 'ould be thestudent.

    STUDENTS

    Student ID Last Name First NamePhone

    Number Birth Date

    333-33-3333 Simpson Alice 333-3333 10/11/84

    111-11-1111 Sanders Ned 444-4444 11/24/86

    123-45-6789 Moore Artie 555-5555 04/20/85

  • 8/19/2019 AIS relational databases

    6/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES -n%ormation about the attributes o% an entity e.g.&

    the students -D number and birth date are stored in fields.

    STUDENTS

    Student ID Last Name First NamePhone

    Number Birth Date

    333-33-3333 Simpson Alice 333-3333 10/11/84

    111-11-1111 Sanders Ned 444-4444 11/24/86

    123-45-6789 Moore Artie 555-5555 04/20/85

  • 8/19/2019 AIS relational databases

    7/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES  ,ll the %ields containing data about one entity e.g.&

    one student %orm a record . /he e#ample belo' sho's the record %or ,rtie )oore.

    STUDENTS

    Student ID Last Name First NamePhone

    Number Birth Date

    333-33-3333 Simpson Alice 333-3333 10/11/84

    111-11-1111 Sanders Ned 444-4444 11/24/86

    123-45-6789 Moore Artie 555-5555 04/20/85

  • 8/19/2019 AIS relational databases

    8/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES

     , set o% all related records %orms a file e.g.& thestudent %ile.

    -% this uni$ersity only had three students and %i$e %ields%or each student& then the entire %ile 'ould be depicted

     belo'.STUDENTS

    Student ID Last Name First NamePhone

    Number Birth Date

    333-33-3333 Simpson Alice 333-3333 10/11/84

    111-11-1111 Sanders Ned 444-4444 11/24/86

    123-45-6789 Moore Artie 555-5555 04/20/85

  • 8/19/2019 AIS relational databases

    9/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES  , set o% interrelated& centrally coordinated %iles %orms

    a database.

    *tudent4ile

    Class4ile

     ,d$isor4ile

  • 8/19/2019 AIS relational databases

    10/79

  • 8/19/2019 AIS relational databases

    11/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES

    " /his proli%eration o% master%iles created problems 6%ten the same in%ormation 'as

    stored in multiple master %iles.

    )ade it more di%%icult toe%%ecti$ely integrate data andobtain an organi+ation!'ide $ie'o% the data.

     ,lso& the same in%ormation maynot ha$e been consistent bet'een

    %iles. -% a student changed his phonenumber& it may ha$e beenupdated in one master %ile butnot another.

    )aster 4ile 14act , 4act (4act C

    )aster 4ile 24act , 4act D4act 4

    )aster 4ile 14act , 4act (

    4act 4

    EnrollmentProgram

    4inancial ,idProgram

    7radesProgram

  • 8/19/2019 AIS relational databases

    12/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES

    " , database is a set o%inter!related& centrallycoordinated %iles.

    Database4act , 4act (4act C 4act D4act E 4act 4

    EnrollmentProgram

    4inancial ,idProgram

    7radesProgram

    Database)anagement

    *ystem

  • 8/19/2019 AIS relational databases

    13/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES

    " /he database approachtreats data as anorgani+ational resourcethat should be used byand managed %or theentire organi+ation& not 8ust a particulardepartment.

    "  , databasemanagement system

    (DBMS) ser$es as theinter%ace bet'een thedatabase and the $ariousapplication programs.

    Database4act , 4act (4act C 4act D4act E 4act 4

    EnrollmentProgram

    4inancial ,idProgram

    7radesProgram

    Database)anagement

    *ystem

  • 8/19/2019 AIS relational databases

    14/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES

    " /he combination o%the database& theD()*& and the

    application programsthat access thedatabase is re%erred toas the database

    system.

    Database4act , 4act (4act C 4act D4act E 4act 4

    EnrollmentProgram

    4inancial ,idProgram

    7radesProgram

    Database)anagement

    *ystem

  • 8/19/2019 AIS relational databases

    15/79

    Copyright © Pearson Education Limited 2015.

    FILE VS. DATAASES

    " /he personresponsible %or thedatabase is thedatabaseadministrator .

    " ,s technologyimpro$es& many largecompanies arede$eloping $ery largedatabases called datawarehouses.

    Database4act , 4act (4act C 4act D4act E 4act 4

    EnrollmentProgram

    4inancial ,idProgram

    7radesProgram

    Database)anagement

    *ystem

  • 8/19/2019 AIS relational databases

    16/79

    Copyright © Pearson Education Limited 2015.

    I!"ORTANCE AND ADVANTA#ES OF DATAASE

    S$STE!S" Database technology is e$ery'here.

    )ost ne' ,-*s implement a database approach.

     9irtually all main%rame computer sites usedatabase technology.

    :se o% databases 'ith PCs is gro'ing also.

  • 8/19/2019 AIS relational databases

    17/79

    Copyright © Pearson Education Limited 2015.

    I!"ORTANCE AND ADVANTA#ES OF DATAASE

    S$STE!S" ,s accountants& you are li;ely to audit or 'or;

    %or companies that use database technology tostore& process& and report accountingtransactions. )any accountants 'or; directly 'ith databases and

     'ill enter& process& and

  • 8/19/2019 AIS relational databases

    18/79

    Copyright © Pearson Education Limited 2015.

    I!"ORTANCE AND ADVANTA#ES OF DATAASE

    S$STE!S" Database technology pro$ides the %ollo'ing bene%its to organi+ations Data integration

    Data sharing Reporting %le#ibility 

    )inimal data redundancy and inconsistencies

    Data independence

    Central management o% data Cross!%unctional analysis

  • 8/19/2019 AIS relational databases

    19/79

    Copyright © Pearson Education Limited 2015.

    I!"ORTANCE AND ADVANTA#ES OF DATAASE

    S$STE!S" /he importance o% good data

    (ad data leads to (ad decisions

    Embarrassment

     ,ngry users

    Data =arehousing -nstitute estimates that dirtydata costs >?00 billion per year in unnecessarypostage& mar;eting costs& and lost customer

    credibility.

  • 8/19/2019 AIS relational databases

    20/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " Logical and physical views of data -n %ile!oriented systems& programmers must ;no'

    the physical location and layout o% records used by

    a program. /hey must re%erence the location& length& and %ormat

    o% e$ery %ield they utili+e.

     =hen data is used %rom se$eral %iles& this process becomes more comple#.

  • 8/19/2019 AIS relational databases

    21/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " Database systems o$ercome this problem byseparating the storage and use o% data elements. /'o separate $ie's o% the data are pro$ided

    Logical $ie'  Physical $ie' 

    Separating these views facilitatesapplication development, because

    programmers can focus on coding the logicand not be concerned with storage details.

  • 8/19/2019 AIS relational databases

    22/79

    Copyright © Pearson Education Limited 2015.

     Database

    Logical View—User Logical View—User B

    D()*

    6perating

    *ystem

    The DB!S translatesusers" logical #iews

    into instructions as to

    which data should be

    retrie#ed $rom the

    database%

    Enrollment b& 'lass*cholarship Distribution

    4r.

    5@*oph.

    2@

    Ar.

    3B@

    *r.

    33@

  • 8/19/2019 AIS relational databases

    23/79

    Copyright © Pearson Education Limited 2015.

     Database

    Enrollment b& 'lass

    Logical View—User Logical View—User B

    D()*

    6perating

    *ystem

    The o(erating s&stem

    translates DB!S

    re)uests into

    instructions to

    (h&sicall& retrie#e

    data $rom #arious

    dis*s%

    *cholarship Distribution4r.

    5@*oph.

    2@

    Ar.

    3B@

    *r.

    33@

  • 8/19/2019 AIS relational databases

    24/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " /he D()* handles the lin; bet'een the physicaland logical $ie's o% the data.  ,llo's the user to access&

  • 8/19/2019 AIS relational databases

    25/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " *eparating the logical and physical $ie's o% dataalso means users can change theirconceptuali+ations o% the data relationships 'ithout ma;ing changes in the physical storage.

    " /he database administrator can also change thephysical storage o% the data 'ithout a%%ecting

    users or application programs.

  • 8/19/2019 AIS relational databases

    26/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " Schemas  , schema describes the logical and physical

    structures o% a database.

    /here are three le$els o% schema. Conceptual level

    • /he organi+ation!'ide $ie' o% the entire databasei.e.& the big picture.

    • Lists all data elements and the relationships bet'een them.

  • 8/19/2019 AIS relational databases

    27/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S" Schemas

     , schema describes the logical and physicalstructures o% a database.

    /here are three le$els o% schema. Conceptual le$el

    External level

    •  , set o% indi$idual user $ie's o% portions o% thedatabase& i.e.& ho' each user sees the portion o%the system 'ith 'hich he interacts.

    • /hese indi$idual $ie's are re%erred to assubschema.

  • 8/19/2019 AIS relational databases

    28/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " Schemas  , schema describes the logical and physical

    structures o% a database.

    /here are three le$els o% schema. Conceptual le$el

    E#ternal le$el

    Internal level

    •  , lo'!le$el $ie' o% the database.

    • -t describes ho' the data are actuallystored and accessed including

     – Record layouts – De%initions

     –  ,ddresses

     – -nde#es

  • 8/19/2019 AIS relational databases

    29/79

    Copyright © Pearson Education Limited 2015.

    Subschema++User Subschema++User B Subschema++User '

    Enroll

    CashReceipt

    Classes *tudent

    Student ,ecord 'lass ,ecord

    Student No --c!aracter "9# $lass Name --c!aracter "9#

    Student Name --c!aracter "26# %ept No --inte&er "4#' non-null' inde()item(

    SA* Score --inte&er "2#' non-null' inde()item( $ourse No --inte&er "4#' non-null' inde()item(

    !a((ing e-ternal+le#el #iews to conce(tual+le#el schema

    !a((ing conce(tual+le#el items to internal+le#el descri(tions

    *mith . . . , Aones . . . (

     ,rnold . . .D

  • 8/19/2019 AIS relational databases

    30/79

    Copyright © Pearson Education Limited 2015.

    Subschema++User Subschema++User B Subschema++User '

    Enroll

    CashReceipt

    Classes *tudent

    Student ,ecord 'lass ,ecord

    Student No --c!aracter "9# $lass Name --c!aracter "9#

    Student Name --c!aracter "26# %ept No --inte&er "4#' non-null' inde()item(

    SA* Score --inte&er "2#' non-null' inde()item( $ourse No --inte&er "4#' non-null' inde()item(

    !a((ing e-ternal+le#el #iews to conce(tual+le#el schema

    !a((ing conce(tual+le#el items to internal+le#el descri(tions

    The

    bidirectional

    arrowsre(resent

    ma((ings

    between the

    schema%

    *mith . . . , Aones . . . (

     ,rnold . . .D

  • 8/19/2019 AIS relational databases

    31/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S" /he D()* uses the mappings to translate a

    re

  • 8/19/2019 AIS relational databases

    32/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " ,ccountants are %re

  • 8/19/2019 AIS relational databases

    33/79

    Copyright © Pearson Education Limited 2015.

    Database Users an% Designers

    " Di%%erent users o% the database in%ormation areat an e#ternal le$el o% the database. /hese usersha$e logical views o% the data.

    " ,t an internal le$el o% the database is thephysical view o% the data 'hich is ho' the datais actually physically stored in the system.

    " Designers o% a database need to understand

    users needs and the conceptual le$el o% theentire database as 'ell as the physical $ie'.

    !5

  • 8/19/2019 AIS relational databases

    34/79

    Copyright © Pearson Education Limited 2015.

    Database Design

    " /o design a database& you need to ha$e aconceptual $ie' o% the entire database. /heconceptual $ie' illustrates the di%%erent %iles and

    relationships bet'een the %iles.

    " /he data dictionary is a blueprint o% thestructure o% the database and includes dataelements& %ield types& programs that use the dataelement& outputs& and so on.

    !?

  • 8/19/2019 AIS relational databases

    35/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " The data dictionary   , ;ey component o% a D()* is the data

    dictionary. Contains in%ormation about the data elements in the

    database such as meaning& relationships to otherdata& origin& usage& and %ormat.

    4or each data element& there is a corresponding

    record in the data dictionary describing thatelement.

  • 8/19/2019 AIS relational databases

    36/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " -n%ormation pro$ided %or each element includes  , description or e#planation o% the element.

    /he records in 'hich it is contained.

    -ts source. /he length and type o% the %ield in 'hich it is stored.

    /he programs in 'hich it is used.

    /he outputs in 'hich it is contained.

    /he authori+ed users o% the element. 6ther names %or the element.

  • 8/19/2019 AIS relational databases

    37/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S• ,ccountants should participate in the

    de$elopment o% the data dictionary because theyha$e a good understanding o% the data elements

    in a business organi+ation& as 'ell as 'herethose elements originate and ho' they are used.

  • 8/19/2019 AIS relational databases

    38/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " /he D()* usually maintains the datadictionary. -t is o%ten one o% the %irst applications o% a ne'ly

    implemented database system. -nputs to the dictionary include

    Records o% ne' or deleted data elements. Changes in names& descriptions& or uses o% e#isting elements.

    6utputs include Reports that are use%ul to programmers& database designers&

    and -* users in Designing and implementing the system. Documenting the system. Creating an audit trail.

  • 8/19/2019 AIS relational databases

    39/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " !"S Languages E$ery D()* must pro$ide a means o%

    per%orming the three basic %unctions o% Creating a database Changing a database Fuerying a database

  • 8/19/2019 AIS relational databases

    40/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S" Creating a database

    /he set o% commands used to create the databaseis ;no'n as data definition language (DDL).DDL is used to (uild the data dictionary  -nitiali+e or create the database Describe the logical $ie's %or each indi$idual user or

    programmer

    *peci%y any limitations or constraints on securityimposed on database records or %ields

  • 8/19/2019 AIS relational databases

    41/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S" Changing a database

    /he set o% commands used to change the databaseis ;no'n as data manipulation language

    (DML). D)L is used %or maintaining the dataincluding :pdating data

    -nserting data

    Deleting portions o% the database

  • 8/19/2019 AIS relational databases

    42/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S" Fuerying a database

    /he set o% commands used to

  • 8/19/2019 AIS relational databases

    43/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S" Report =riter

    )any D()* pac;ages also include a report writer &a language that simpli%ies the creation o% reports.

    :sers typically speci%y  =hat elements they 'ant printed

    Go' the report should be %ormatted

    /he report 'riter then *earches the database

    E#tracts speci%ied data Prints them out according to speci%ied %ormat

  • 8/19/2019 AIS relational databases

    44/79

    Copyright © Pearson Education Limited 2015.

    DATAASE S$STE!S

    " :sers typically ha$e access to both DFL andreport 'riter.

    " ,ccess to DDL and D)L are typically restricted

    to employees 'ith administrati$e andprogramming responsibilities.

  • 8/19/2019 AIS relational databases

    45/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES

    " , D()* is characteri+ed by the type o% logicaldata model on 'hich it is based.  , data model  is an abstract representation o%

    the contents o% a database. )ost ne' D()*s are called relational

    databases because they use the relational modelde$eloped by E. 4. Codd in 1HI0.

  • 8/19/2019 AIS relational databases

    46/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES

    " /he relational data model  representse$erything in the database as being stored in the%orms o% tables a;a& relations.

    " /his model only describes ho' the data appear  in the conceptual! and e#ternal!le$el schemas.

    " /he data are physically stored  according to thedescription in the internal!le$el schema.

  • 8/19/2019 AIS relational databases

    47/79

    Copyright © Pearson Education Limited 2015.

    Each row is

    called a tu(le.

    which rh&mes

    with /cou(le%0

    E h

  • 8/19/2019 AIS relational databases

    48/79

    Copyright © Pearson Education Limited 2015.

    Each row

    contains data

    about a s(eci$ic

    occurrence o$

    the t&(e o$ entit&in the table%

  • 8/19/2019 AIS relational databases

    49/79

    Copyright © Pearson Education Limited 2015.

    Each column in

    a table contains

    in$ormation

    about a s(eci$icattribute o$ the

    entit&%

  • 8/19/2019 AIS relational databases

    50/79

    Copyright © Pearson Education Limited 2015.

    (rimar& *e& is theattribute or combination

    o$ attributes that

    uni)uel& identi$ies a

    s(eci$ic row in a table%

  • 8/19/2019 AIS relational databases

    51/79

    Copyright © Pearson Education Limited 2015.

    In some tables. two or more attributes

    ma& be 1oined to $orm the (rimar& *e&%

  • 8/19/2019 AIS relational databases

    52/79

    Copyright © Pearson Education Limited 2015.

    DVIS2,S

    d#isor No% Last Name First Name 2$$ice No%

    1418 +o,ard len 420

    1419 Melton Am. 316

    1503 !an& i 202

    1506 ado,si % 203

    STUDENTS

    Student ID Last NameFirst

    Name Phone No%d#isor

    No%

    333-33-3333 Simpson Alice 333-3333 1418111-11-1111 Sanders Ned 444-4444 1418

    123-45-6789 Moore Artie 555-5555 1503

    $oreign *e& is an attribute in one table that is a (rimar& *e& in

    another table%

  • 8/19/2019 AIS relational databases

    53/79

    Copyright © Pearson Education Limited 2015.

    DVIS2,S

    d#isor No% Last Name First Name 2$$ice No%

    1418 +o,ard len 420

    1419 Melton Am. 316

    1503 !an& i 202

    1506 ado,si % 203

    Foreign *e&s are used to lin* tables together%

    STUDENTS

    Student ID Last NameFirst

    Name Phone No%d#isor

    No%

    333-33-3333 Simpson Alice 333-3333 1418111-11-1111 Sanders Ned 444-4444 1418

    123-45-6789 Moore Artie 555-5555 1503

  • 8/19/2019 AIS relational databases

    54/79

    Copyright © Pearson Education Limited 2015.

    DVIS2,S

    d#isor No% Last Name First Name 2$$ice No%

    1418 +o,ard len 420

    1419 Melton Am. 316

    1503 !an& i 202

    1506 ado,si % 203

    2ther non+*e& attributes in each table store im(ortant

    in$ormation about the entit&%

    STUDENTS

    Student ID Last NameFirst

    Name Phone No%d#isor

    No%

    333-33-3333 Simpson Alice 333-3333 1418111-11-1111 Sanders Ned 444-4444 1418

    123-45-6789 Moore Artie 555-5555 1503

  • 8/19/2019 AIS relational databases

    55/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES" ,lternati$es %or storing data

    6ne possible alternate approach 'ould be to storeall data in one uni%orm table.

    4or e#ample& instead o% separate tables %orstudents and classes& 'e could store all data in onetable and ha$e a separate line %or each student #class combination.

  • 8/19/2019 AIS relational databases

    56/79

    Copyright © Pearson Education Limited 2015.

    Student IDLast

    NameFirstName Phone No% 'ourse No% Section Da& Time

    333-33-3333 Simpson Alice 333-3333 A$$*-3603 1 M 900 AM

    333-33-3333 Simpson Alice 333-3333 N-3213 3 *! 1100 AM

    333-33-3333 Simpson Alice 333-3333 MM*-3021 11 *! 1200 M

    111-11-1111 Sanders Ned 444-4444 A$$*-3433 2 * 1000 AM

    111-11-1111 Sanders Ned 444-4444 MM*-3021 5 800 AM

    111-11-1111 Sanders Ned 444-4444 ANS-1422 7 900 AM

    123-45-6789 Moore Artie 555-5555 A$$*-3433 2 * 1000 AM

    123-45-6789 Moore Artie 555-5555 N-3213 3 *! 1100 AM

    • :sing the suggested approach& a student ta;ing three classes 'ould

    need three ro's in the table.

    • -n the abo$e& simpli%ied e#ample& a number o% problems arise.

  • 8/19/2019 AIS relational databases

    57/79

    Copyright © Pearson Education Limited 2015.

    Student IDLast

    NameFirstName Phone No% 'ourse No% Section Da& Time

    333-33-3333 Simpson Alice 333-3333 A$$*-3603 1 M 900 AM

    333-33-3333 Simpson Alice 333-3333 N-3213 3 *! 1100 AM

    333-33-3333 Simpson Alice 333-3333 MM*-3021 11 *! 1200 M

    111-11-1111 Sanders Ned 444-4444 A$$*-3433 2 * 1000 AM

    111-11-1111 Sanders Ned 444-4444 MM*-3021 5 800 AM

    111-11-1111 Sanders Ned 444-4444 ANS-1422 7 900 AM

    123-45-6789 Moore Artie 555-5555 A$$*-3433 2 * 1000 AM

    123-45-6789 Moore Artie 555-5555 N-3213 3 *! 1100 AM

    • *uppose ,lice *impson changes her phone number. Jou need to ma;e

    the change in three places. -% you %ail to change it in all three places orchange it incorrectly in one place& then the records %or ,lice 'ill beinconsistent.

    • /his problem is re%erred to as an update anomaly.

  • 8/19/2019 AIS relational databases

    58/79

    Copyright © Pearson Education Limited 2015.

    Student IDLast

    NameFirstName Phone No% 'ourse No% Section Da& Time

    333-33-3333 Simpson Alice 333-3333 A$$*-3603 1 M 900 AM

    333-33-3333 Simpson Alice 333-3333 N-3213 3 *! 1100 AM

    333-33-3333 Simpson Alice 333-3333 MM*-3021 11 *! 1200 M

    111-11-1111 Sanders Ned 444-4444 A$$*-3433 2 * 1000 AM

    111-11-1111 Sanders Ned 444-4444 MM*-3021 5 800 AM

    111-11-1111 Sanders Ned 444-4444 ANS-1422 7 900 AM

    123-45-6789 Moore Artie 555-5555 A$$*-3433 2 * 1000 AM

    123-45-6789 Moore Artie 555-5555 N-3213 3 *! 1100 AM

    •  =hat happens i% you ha$e a ne' student to add& but he hasnt signed up

    %or any courses yetK

    • 6r 'hat i% there is a ne' class to add& but there are no students enrolledin it yetK -n either case& the record 'ill be partially blan;.

    • /his problem is re%erred to as an insert anomaly.

  • 8/19/2019 AIS relational databases

    59/79

    Copyright © Pearson Education Limited 2015.

    Student IDLast

    NameFirstName Phone No% 'ourse No% Section Da& Time

    333-33-3333 Simpson Alice 333-3333 A$$*-3603 1 M 900 AM

    333-33-3333 Simpson Alice 333-3333 N-3213 3 *! 1100 AM

    333-33-3333 Simpson Alice 333-3333 MM*-3021 11 *! 1200 M

    111-11-1111 Sanders Ned 444-4444 A$$*-3433 2 * 1000 AM

    111-11-1111 Sanders Ned 444-4444 MM*-3021 5 800 AM

    111-11-1111 Sanders Ned 444-4444 ANS-1422 7 900 AM

    123-45-6789 Moore Artie 555-5555 A$$*-3433 2 * 1000 AM

    123-45-6789 Moore Artie 555-5555 N-3213 3 *! 1100 AM

    • -% ed 'ithdra's %rom all his classes and you eliminate all three o% his

    ro's %rom the table& then you 'ill no longer ha$e a record o% ed. -% edis planning to ta;e classes ne#t semester& then you probably didntreally 'ant to delete all records o% him.

    • /his problem is re%erred to as a delete anomaly.

  • 8/19/2019 AIS relational databases

    60/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES

    " ,lternati$es %or storing data  ,nother possible approach 'ould be to store each

    student in one ro' o% the table and create multiple

    columns to accommodate each class that he ista;ing.

  • 8/19/2019 AIS relational databases

    61/79

    Copyright © Pearson Education Limited 2015.

    • /his approach is also %raught 'ith problems

     – Go' many classes should you allo' in building the tableK

     – /he abo$e table is

  • 8/19/2019 AIS relational databases

    62/79

    Copyright © Pearson Education Limited 2015.

    • /he solution to the preceding problems is

    to use a set o% tables in a relationaldatabase.

    • Each entity is stored in a separate table&and separate tables or %oreign ;eys can beused to lin; the entities together.

  • 8/19/2019 AIS relational databases

    63/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES" !asic re#uirements of a relational database

    E$ery column in a ro' must be single $alued. -n other 'ords& e$ery cell can ha$e one and only one $alue.

    -n the student table& you couldnt ha$e an attributenamed Phone umber i% a student could ha$emultiple phone numbers.

    /here might be an attribute named local phonenumber and an attribute named permanent phone

    number.  Jou could not ha$e an attribute named Class in the

    student table& because a student could ta;e multipleclasses.

  • 8/19/2019 AIS relational databases

    64/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES

    " !asic re#uirements of a relationaldatabase /he primary ;ey cannot be null.

    /he primary ;ey uni

  • 8/19/2019 AIS relational databases

    65/79

    Copyright © Pearson Education Limited 2015.

    • ote that 'ithin each table& there are noduplicate primary ;eys and no null primary;eys.

    • Consistent 'ith the entity integrity rule.

  • 8/19/2019 AIS relational databases

    66/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES" !asic re#uirements of a relational

    database  , %oreign ;ey must either be null or correspond to

    the $alue o% a primary ;ey in another table. /his rule is re%erred to as the referential

    integrity rule.

    /he rule is necessary because %oreign ;eys are usedto lin; ro's in one table to ro's in another table.

  • 8/19/2019 AIS relational databases

    67/79

    Copyright © Pearson Education Limited 2015.

    DVIS2,S

    d#isor No% Last Name First Name 2$$ice No%

    1418 +o,ard len 420

    1419 Melton Am. 316

    1503 !an& i 202

    1506 ado,si % 203

    STUDENTS

    Student ID Last NameFirst

    Name Phone No%d#isor

    No%

    333-33-3333 Simpson Alice 333-3333 1418111-11-1111 Sanders Ned 444-4444 1418

    123-45-6789 Moore Artie 555-5555 1503

    d#isor No% is a $oreign *e& in the STUDENTS table% E#er&

    incident o$ d#isor No% in the STUDENTS table either matches

    an instance o$ the (rimar& *e& in the DVIS2,S table or is null%

  • 8/19/2019 AIS relational databases

    68/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES" !asic re#uirements of a relational

    database  ,ll non!;ey attributes in a table should describe a

    characteristic o% the ob8ect identi%ied by theprimary ;ey. Could nationality be a non!;ey attribute in the

    student tableK

    Could adisor!s nationality be a non!;eyattribute in the student tableK

  • 8/19/2019 AIS relational databases

    69/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES

    " /he preceding %our constraints produce a 'ell!structured normali+ed database in 'hich Data are consistent.

    Redundancy is minimi+ed and controlled.

    " -n a normali+ed database& attributes appearmultiple times only 'hen they %unction as%oreign ;eys.

    " /he re%erential integrity rule ensures there 'ill be no update anomaly problem 'ith %oreign;eys.

  • 8/19/2019 AIS relational databases

    70/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES

    "  ,n important %eature is that data about $arious things o%interest entities are stored in separate tables. )a;es it easier to add ne' data to the system.

     Jou add a ne' student by adding a ro' to the student

    table.  Jou add a ne' course by adding a ro' to the course table. )eans you can add a student e$en i% he hasnt signed up

    %or any courses.  ,nd you can add a class e$en i% no students are yet

    enrolled in it.

    )a;es it easy to a$oid the insert anomaly." *pace is also used more e%%iciently than in the other

    schemes. /here should be no blan; ro's or attributes.

    •  ,dd a

  • 8/19/2019 AIS relational databases

    71/79

    Copyright © Pearson Education Limited 2015.

    studenthere.

    • Lea$es no

     blan;spaces.

    •  ,dd a course here.• Lea$es no blan; spaces.

    •  =hen a particular student enrolls %or aparticular course& add that in%o here.

  • 8/19/2019 AIS relational databases

    72/79

    Copyright © Pearson Education Limited 2015.

    RELATIONAL DATAASES" Deletion o% a class %or a student 'ould cause the

    elimination o% one record in the student # classtable.

    /he student still e#ists in the student table. /he class still e#ists in the class table.

     ,$oids the delete anomaly.

  • 8/19/2019 AIS relational databases

    73/79

    Copyright © Pearson Education Limited 2015.

    • ed stille#ists inthe student

    table.

    •E$en i% ed 'as the only student inthe class& ,CC/!3?03 still e#ists in thecourse table.

    • -% ed *anders drops ,CC/!3?03& remo$eeds class %rom this table.

  • 8/19/2019 AIS relational databases

    74/79

    Copyright © Pearson Education Limited 2015.

    Re&ati'na& Data Tab&es

    !10

  • 8/19/2019 AIS relational databases

    75/79

    Copyright © Pearson Education Limited 2015.

    Re&ati'na& Data Tab&es

    !11

    Primary Meys

    $oreign %ey Customer N is a 4oreign ;ey inthe *ales /able because it is a Primary ;ey that uni

  • 8/19/2019 AIS relational databases

    76/79

    Copyright © Pearson Education Limited 2015.

    Wh( )ave a Set '* Re&ate% Tab&es?

    " Data stored in one large table can be redundantand ine%%icient causing the %ollo'ing problems :pdate anomaly 

    -nsert anomaly 

    Delete anomaly 

    !12

  • 8/19/2019 AIS relational databases

    77/79

    Copyright © Pearson Education Limited 2015.

    Re&ati'na& Database Design R+&es

    " E$ery column in a ro' must be single $alued" Primary ;ey cannot be null empty also ;no'n as entity integrity 

    " -4 a %oreign ;ey is not null& it must ha$e a $alue that corresponds tothe $alue o% a primary ;ey in another table re%erential integrity

    "  ,ll other attributes in the table must describe characteristics o% the

    ob8ect identi%ied by the primary ;ey 

    4ollo'ing these rules allo's databases to be normali+ed and sol$es theupdate& insert& and delete anomalies.

    !13

  • 8/19/2019 AIS relational databases

    78/79

    Copyright © Pearson Education Limited 2015.

    ,e( Ter-s" Database

    " Database management systemD()*

    " Database system

    " Database administrator D(,

    " Data 'arehouse

    " (usiness intelligence

    " 6nline analytical processing6L,P

    " Data mining

    " Record layout

    " Logical $ie' 

    " Physical $ie' 

    " *chema

    " Conceptual!le$el schema

    " E#ternal!le$el schema

    " *ubschema" -nternal!le$el schema

    " Data dictionary 

    " Data de%inition languageDDL

    " Data manipulation languageD)L

    " Data

  • 8/19/2019 AIS relational databases

    79/79

    ,e( Ter-s c'ntin+e%/" :pdate anomaly 

    " -nsert anomaly 

    " Delete anomaly 

    " Relational database

    " Entity integrity rule

    " Re%erential integrity rule

    " ormali+ation

    " *emantic data modeling