MELJUN CORTES MANUAL DataBase System CSCI12

  • View
    219

  • Download
    0

Embed Size (px)

Text of MELJUN CORTES MANUAL DataBase System CSCI12

  • 8/13/2019 MELJUN CORTES MANUAL DataBase System CSCI12

    1/37

    CSCI12 Instructional Manual

    2nd trimester, SY 2007-2008Prepared by: ELJUN P. CORTES

    PRELIM PERIOD

    Lecture no. 1: DATABASE SYSTEMS

    1.1 Introduction to Database Systems

    Database DB!- An integrated collection of related data

    By relateddata we mean tat te data represents logically coerent facts abo!t some

    aspects of te real world tat are re"!ired by an application

    Uni"erse o# discourse or mini$%or&d- #e part of te real world tat a database is

    designed to model witin a comp!ter

    By integratedwe mean tat te data for m!ltiple applications is stored togeter

    and manip!lated in a uniform wayon a secondary storage s!c as a magnetic or an optical

    dis$% #e primary goal of integration is to s!pport information saring across m!ltiple

    applications%

    a Database System consists of &' an application specific database, 2' te (B)S tat

    maintains tat database, and *' te application software tat manip!lates te database

    College of Computer Studies Prepared by: ELJUN P.CORTES1

  • 8/13/2019 MELJUN CORTES MANUAL DataBase System CSCI12

    2/37

    CSCI12 Instructional Manual

    2nd trimester, SY 2007-2008Prepared by: ELJUN P. CORTES

    Database Systems and Database Mana'ement Systems

    A Database Mana'ement System DBMS) is a collection of programs tat controls a

    database% Specifically, it pro+ides !s wit an interface to create, maintain, and manip!late

    m!ltiple databases

    (B)S is a general-p!rpose software system tat we can !se not only to create and

    maintain m!ltiple databases b!t also to implement database systems for different applications as

    well%

    As opposed to a (B)S, wic is general-p!rpose, a database system is de+eloped to

    s!pport te operations of a specific organiation or a specific set of applications%

    T(E DATABASE APPROA)(ES

    .ays of /andling (atabases'

    &% Manua& * man!al manip!lation of data

    E+.)an!al card catalog

    2% )om,uteri-ed electronic data andling

    Traditiona& i&e Processin' System TPS!

    Database Mana'ement System DBMS!

    DBMS "s TPS

    TPS $ application programs directlyfilenames and data definitions are embedded in

    eac program%'

    -data are integrated in a single, sared data file, all application programs tat

    sare te data file m!st be aware of all te data in te file, incl!ding tose data

    items tat tey do not ma$e !se of or need to $now

    - #e problem gets worse wen a new field is added to a data file

    Disad"anta'es o# TPS

    &% 1ncontrolled ed!ndancy

    2% 3nconsistent (ata

    *% 3nfle4ibility

    5% 6imited (ata Saring

    College of Computer Studies Prepared by: ELJUN P.CORTES2

  • 8/13/2019 MELJUN CORTES MANUAL DataBase System CSCI12

    3/37

    CSCI12 Instructional Manual

    2nd trimester, SY 2007-2008Prepared by: ELJUN P. CORTES

    % Poor nforcement of Standards

    9% 6ow Programmer Prod!cti+ity

    7% 4cessi+e Program )aintenance

    DBMS $ stores te str!ct!re of te data as part of te description of te database in te

    system catalog, separately from te application programs

    )/aracteristics o# DBMS

    Data Abstraction

    (B)Ss allow data to be str!ct!red in ways tat ma$e it more !nderstandable and

    meaningf!l to te applications tan te ways data are pysically stored on dis$s% #ey pro+ide

    !sers wit ig-le+el, concept!al

    re+arwwwappscon+ersiontmpscratc;9&ect-oriented (B)Ss, to gi+e two e4amples=wile tey

    ide storage details tat are not of interest to most database !sers%

    program-data independence - te pysical organiation of data can be canged wito!t

    affecting te application programs

    program-operation independence- te implementation of abstract operations can be

    canged wito!t affecting te code of te application programs, - as long as teir calling interface

    stays te same

    Data abstractionand, in partic!lar, data inde,endenceis wat facilitates data saring

    and integration% #is is te main ad+antage of (B)S against #raditional ?ile processing wose

    application programs depend on te low-le+el str!ct!re of te data or storage organiation, eac

    program stores its data in a separate data file

    Re&iabi&ity

    (B)Ss pro+ide ig reliability by &' enforcing integrity constraints and 2' ens!ring data

    consistencydespite ardware or software fail!res%

    College of Computer Studies Prepared by: ELJUN P.CORTES3

  • 8/13/2019 MELJUN CORTES MANUAL DataBase System CSCI12

    4/37

    CSCI12 Instructional Manual

    2nd trimester, SY 2007-2008Prepared by: ELJUN P. CORTES

    Inte'rity constraints reflect te meaning or, te semantics' of te data and of te

    application e4% (ata type'

    Constraints conditions, restrictions

    Data consistencytat is, interr!pted !pdate operations do not corr!pt te database wit

    +al!es tat +iolate te integrity constraints and no data in te database is lost%

    After a fail!re, a (B)S a!tomatically reco+ers, restoring te database to te

    consistent state in wic it e4isted >!st prior to te interr!ption% #is consistent state is

    constr!cted as follows% (!ring reco+ery, a (B)S ro&&s bac0all interr!pted transactions,

    obliterating teir !pdates from te database, and re-e4ec!tes s!ccessf!lly terminated

    transactions as necessary, restoring teir !pdates in te database

    E##iciency

    (B)Ss s!pport bot efficient space !tiliation and efficient access to data% By ma$ing !se of te

    data description in te catalog, (B)Ss are able to minimie data red!ndancy, wic in t!rn sa+es

    botspace,by storing eac data item only once, andprocessing time,by eliminating te need of

    m!ltiple !pdates to $eep te replicas consistent and !p-to-date%

    (B)Ss enance te performance of "!eries by means of optimiations and te !se of access

    metods to data based on teir +al!es% @ptimiations simplify te "!eries so tat tey can e4ec!te

    faster,

    and access metods allow direct access to locations were rele+ant data are stored, in a way

    similar to te access pro+ided by te inde4 in te bac$ of a boo$%

    (B)Ss decrease response time of transactions by allowing m!ltiple !sers to access te

    database conc!rrently

    1. Re&ationa& Databases

    Re&ationa& Database Sc/ema

    A relational database schema is a set of table scemas and a set of integrity constraints%

    3ntegrity constraints can be sorted into two $inds:

    str!ct!ral model-specific' integrity constraints tat are imposed by te model as

    disc!ssed below, and

    semantic application-specific' integrity constraints imposed by te application, s!c as

    te constraint, for e4ample, tat te balance of a sa+ings acco!nt cannot be negati+e%

    College of Computer Studies Prepared by: ELJUN P.CORTES4

  • 8/13/2019 MELJUN CORTES MANUAL DataBase System CSCI12

    5/37

    CSCI12 Instructional Manual

    2nd trimester, SY 2007-2008Prepared by: ELJUN P. CORTES

    2eys $ eys are col!mns wose +al!es are s!fficient to !ni"!ely identify a row

    TYPES O 2EYS

    &% Primary ey !ni"!ely identifies a record

    2% Secondary ey !sed to access a gro!p of records wit common attrib!tes

    *% Alternate ey candidate to be Primary ey

    5% omposite ey composed of two or more col!mns to access a !ni"!e record

    % ?oreign ey - a non- key attributeordinary col!mn ' in one table, b!t a primary $ey

    in anoter%

    - establises associationrelationsips' among tables witin one database

    in a relational database scema'

    DDL Data De#inition Lan'ua'e!

    #e command to create a table in SC6 is te A# #AB6 command% SC6

    s!pports all te basic data types fo!nd in most programming lang!ages: integer, float,

    caracter, and caracter string% SC6 commands are not case sensiti+e%

    A# #AB6 ))B

    )emDo integer5',

    (ri+er6ic integer,

    ?name car&0',

    )3 car,

    6name car&',

    PoneD!mber car&5',

    P3)AY Y )emDo',

    1D3C1 (ri+er6ic'

    'E

    #e primary $ey is specified !sing te P3)AY Y directi+e, alternate $eys !sing te

    UNIQUEdirecti+e

    College of Computer Studies Prepared by: ELJUN P.CORTES5

  • 8/13/2019 MELJUN CORTES MANUAL DataBase System CSCI12

    6/37

    CSCI12 Instructional Manual

    2nd trimester, SY 2007-2008Prepared by: ELJUN P. CORTES

    DML Data Mani,u&ation Lana'ua'e!

    3,date O,erations

    elational ()6 allows !s to insertand deleterows in a table as well as to update te

    +al!es of one or more col!mns in a row%

    3n SC6, only one row can be inserted at a time, by specifying te +al!es of eac col!mn,

    as in te following e4ample:

    3DS# 3D#@ ))B

    VALUES (101, 6876588, 'Susan', W, 'Jones', '4123768888'!"

    #is statement inserts a new row for S!san .% Fones in te ))B table% 3n SC6,

    strings are enclosed witin single "!otes%

    Delete and updatecan be applied to m!ltiple rows tat satisfy a selection condition% 3n SC6, a

    selection condition in a deletion is specified by a ./ cla!se% 3n te simplest case, a row is

    selected by specifying te +al!e of its primary $ey% ?or e4ample, te statement

    (6# ?@) ))B

    ./ )emDo G &02E

    deletes te row wit member n!mber &02 from te ))B table% #e following statement

    canges te middle initial of te member &0& in te ))B table%

    1P(A# )ember

    S# )3 G S

    ./ )emDo G &0&E

    An !pdate operation s!cceeds if it does not +iolate any integrity constraints% ?or e4ample,

    an insert operation will not s!cceed if it attempts to insert a row wose $eys, primary and