Overview of Relational DBMS

  • Upload
    dierz

  • View
    254

  • Download
    0

Embed Size (px)

Citation preview

  • 7/28/2019 Overview of Relational DBMS

    1/34

    Overview Of Relational DBMSPresented by

    Satrio Agung Wicaksono

  • 7/28/2019 Overview of Relational DBMS

    2/34

    Relational Database Concepts A database is a repository of data, designed to support

    efficient data storage, retrieval and maintenance

    Relational databaseis a database modeled by relations

    RelationR defined over n sets D1, D2, Dnwhere Di

    represents some domain.

    n-tuple(tuple) is a set < d1, d2, , dn> where d1D1,d2D2,

  • 7/28/2019 Overview of Relational DBMS

    3/34

    Sample Database Scheme

    The relation schemas for this database can be defined as

    follows:

    EMP(ENO, ENAME, TITLE, SAL, PNO, RESP, DUR)

    PROJ(PNO,PNAME, BUDGET)

  • 7/28/2019 Overview of Relational DBMS

    4/34

    Key Super Key:

    uses keys to define identifiers for a relations tuples

    used to enforce rules and/or constraints on database data.

    Candidate Key

    is a unique identifier for the tuples of a relation

    most relations have multiple candidate keys

    Primary Key

    candidate key that is chosen to represent the relation in the database and to provide a wayto uniquely identify each tuple of the relation

    Alternate Key

    the remaining candidate keys

  • 7/28/2019 Overview of Relational DBMS

    5/34

    The problem of redundancy Data redundancy implies finding the same data in

    more than one location within deatabase tables

    The following problems Repetition anomaly

    Insertion Anomalies

    Deletion Anomalies

    Update Anomalies

    Contd.

  • 7/28/2019 Overview of Relational DBMS

    6/34

    Repetition anomaly

    Repetition anomaly :

    Certain information may be repeated unnecessarily

    This is obviously a waste of storage and is contrary to the spirit of

    databases

    NIM NAMA PRODI K_MK THN_MK THN_AKADEMIK SEMESTER NAMA_MK SKS NILAI

    10509xxx Wira Ilkom SIF15012 2012 2012 Ganjil BDT 3 A

    10509xxx Wira Ilkom SIF15011 2012 2012 Ganjil ABD 3 A

  • 7/28/2019 Overview of Relational DBMS

    7/34

    Insertion Anomalies

    insertion anomaly : happens when the insertion of a

    data record is not possible unless we also add someadditional unrelated data to the record

    NIM NAMA PRODI K_MK THN_MK THN_AKADEMIK SEMESTER NAMA_MK SKS NILAI

    10509xxx Wira Ilkom SIF15012 2012 2012 Ganjil BDT 3 A

    10509xxx Wira Ilkom SIF15011 2012 2012 Ganjil ABD 3 A

  • 7/28/2019 Overview of Relational DBMS

    8/34

    Deletion Anomalies

    deletion anomaly happens when deletion of a data

    record results in losing some unrelatedinformation that was stored as part of the record

    that was deleted from a table

    NIM NAMA PRODI K_MK THN_MK THN_AKADEMIK SEMESTER NAMA_M

    K

    SKS NILAI

    10509xxx Wira Ilkom SIF15012 2012 2012 Ganjil BDT 3 A

    10506xxx Wiri TIF SIF15012 2012 2012 Ganjil BDT 3 A

  • 7/28/2019 Overview of Relational DBMS

    9/34

  • 7/28/2019 Overview of Relational DBMS

    10/34

    Decompositions

    Decomposition in relational database design implies breaking down a relational

    schema into smaller and simpler relations that avoid redundancy.

    The idea is to be able to query the smaller relations for any information that we

    were previously able to retrieve from the original relational schema

    NIM NAMA PRODI K_MK THN_MK THN_AKADEMIK SEMESTER NAMA_MK SKS NILAI

    10509xxx Wira Ilkom SIF15012 2012 2012 Ganjil BDT 3 A

    10506xxx Wiri TIF SIF15012 2012 2012 Ganjil BDT 3 A

    NIM NAMA PRODI

    10509xxx Wira Ilkom

    10506xxx Wiri TIF

    NIM K_MK THN_MK THN_AKADEMIK SEMESTER NAMA_MK SKS NILAI

    10509xxx SIF15012 2012 2012 Ganjil BDT 3 A

    10506xxx SIF15012 2012 2012 Ganjil BDT 3 A

  • 7/28/2019 Overview of Relational DBMS

    11/34

    Functional Dependencies Functional Dependency (FD) i:

    a type of integrity constraint that extends the idea of a super key.

    It defines a dependency between subsets of attributes of a given relation

    Functional Dependency can be understood as A determines B, B is

    dependent on A or A implies B and denoted as A B.

  • 7/28/2019 Overview of Relational DBMS

    12/34

    Functional Dependencies Example

    Set Of Functional Dependecies ?

    NIM NAMA PRODI K_MK THN_KURIKULUM THN_AKADEMIK SEMESTER NAMA_MK NILAI

    10509xxx Wira Ilkom SIF15012 2012 2012 Ganjil BDT A

    10509xxx Wira Ilkom SIF15011 2012 2012 Ganjil ABD A

  • 7/28/2019 Overview of Relational DBMS

    13/34

    Normal Forms Normalization is a procedure in relational database design that

    aims at converting relational schemas into a more desirableform

    The goal is to remove redundancy in relations and the problemsthat follow from it, namely insertion, deletion and updateanomalies.

    Type of Normal Form:

    First Normal Form (1NF)

    Second Normal Form (2NF)

    Third Normal Form (3NF)

    Boyce-Codd Normal Form (BCNF

  • 7/28/2019 Overview of Relational DBMS

    14/34

    First Normal Form (1NF) A relation is considered to be infirst normal form if all of its attributes have

    domains that are indivisible or atomic

    A table is in 1NF if and only if it satisfies the following five conditions :

    There is no top-to-bottom ordering to the rows.

    There is no left-to-right ordering to the columns.

    There are no duplicate rows

    Every row-and-column intersection contains exactly one value from the applicable domain

    (and nothing else).

    All columns are regular [i.e. rows have no hidden components such as row IDs, object IDs,

    or hidden timestamps].

    Contd.

  • 7/28/2019 Overview of Relational DBMS

    15/34

    First Normal Form (1NF)NIM NAM

    A

    NO_HP FAK PROD

    I

    K_MK THN_KURIK

    ULUM

    THN_AKADE

    MIK

    SEMESTE

    R

    NAMA_

    MK

    SKS NILA

    I

    10509xx

    x

    Wira 0821xxx

    08775xx

    PTIIK Ilkom SIF150

    12

    2012 2012 Ganjil BDT 3 A

    10506xx

    x

    Wiri 08555xx

    0888xxx

    PTIIK TIF SIF150

    12

    2012 2012 Ganjil BDT 3 A

    NIM NAM

    A

    NO_HP FAK PRO

    DI

    K_MK THN_KURI

    KULUM

    THN_AKADE

    MIK

    SEMESTE

    R

    NAMA_

    MK

    SKS NIL

    AI

    10509xx

    x

    Wira 0821xxx PTII

    K

    Ilkom SIF1501

    2

    2012 2012 Ganjil BDT 3 A

    10509xx

    x

    Wira 08775xx PTII

    K

    Ilkom SIF1501

    2

    2012 2012 Ganjil BDT 3 A

    10506xx

    x

    Wiri 08555xx PTII

    K

    TIF SIF1501

    2

    2012 2012 Ganjil BDT 3 A

    10506xxx

    Wiri 0888xxx PTIIK

    TIF SIF15012

    2012 2012 Ganjil BDT 3 A

    1NF transformation

  • 7/28/2019 Overview of Relational DBMS

    16/34

    First Normal Form (1NF)NIM NAM

    A

    NO_HP FAK PRO

    DI

    K_MK THN_

    MK

    THN_AKADE

    MIK

    SEMEST

    ER

    NAMA_

    MK

    SKS NILAI

    10509xx

    x

    Wira 0821xxx

    08775xx

    PTIIK Ilkom SIF150

    12

    2012 2012 Ganjil BDT 3 A

    10506xx

    x

    Wiri 08555xx

    0888xxx

    PTIIK TIF SIF150

    12

    2012 2012 Ganjil BDT 3 A

    NIM NAMA FAK PRODI

    10509xxx Wira PTIIK Ilkom

    10506xxx Wiri PTIIK TIF NIM NO_HP

    10509xxx 0821xxx

    10509xxx 08775xx

    10506xxx 08555xx

    10506xxx 0888xxx

    NIM K_MK THN_M

    K

    THN_AKADEM

    IK

    SEMESTE

    R

    NAMA_

    MK

    SKS NILA

    I

    10509xx

    x

    SIF150

    12

    2012 2012 Ganjil BDT 3 A

    10506xx

    x

    SIF150

    12

    2012 2012 Ganjil BDT 3 A

  • 7/28/2019 Overview of Relational DBMS

    17/34

    Second Normal Form (2NF)

    A relation is in second formal form when it is in 1NF and there is no suchnon-key attribute that depends on part of the candidate key, but on the

    entire candidate key

    NIM NAMA FAK PRODI

    10509xxx Wira PTIIK Ilkom

    10506xxx Wiri PTIIK TIF

    NIM NO_HP

    10509xxx 0821xxx

    10509xxx 08775xx

    10506xxx 08555xx

    10506xxx 0888xxx

    NIM K_MK THN_MK THN_AKADEMIK SEMESTER NILAI

    10509xxx SIF15012 2012 2012 Ganjil A

    10506xxx SIF15012 2012 2012 Ganjil A

    K_MK THN_MK NAMA_MK SKS

    SIF15

    012

    2012 BDT 3

    SIF15

    012

    2012 BDT 3

  • 7/28/2019 Overview of Relational DBMS

    18/34

    Third Normal Form (3NF) A relation is in third normal form if it is in 2NF and there is no such non-key

    attribute that depends transitively on the candidate key.

    That is every attribute depends directly on the primary key and not through

    a transitive relation where an attribute Z may depend on a non-key attributeY and Y in turn depends on the primary key X

    Transitivity means that when XY and Y Z, then XZ.

    Contd

  • 7/28/2019 Overview of Relational DBMS

    19/34

    Third Normal Form (3NF)

    NIM NAMA PRODI

    10509xxx Wira Ilkom

    10506xxx Wiri TIF

    NIM NO_HP

    10509xxx 0821xxx

    10509xxx 08775xx

    10506xxx 08555xx

    10506xxx 0888xxx

    NIM K_MK THN_MK THN_AKADEMIK SEMESTER NILAI

    10509xxx SIF15012 2012 2012 Ganjil A

    10506xxx SIF15012 2012 2012 Ganjil A

    K_MK THN_MK NAMA_MK SKS

    SIF15

    012

    2012 BDT 3

    SIF15

    012

    2012 BDT 3

    FAK PRODI

    PTIIK Ilkom

    PTIIK TIF

  • 7/28/2019 Overview of Relational DBMS

    20/34

    Boyce-Codd Normal Form (BCNF) Boyce-Codd Normal Form is a stricter version of 3NF that applies to

    relations where there may be overlapping candidate keys.

    A relation is said to be in Boyce-Codd normal form if it is in 3NF and everynon-trivial FD given for this relation has a candidate key as its determinant.

    That is, for every X Y, X is a candidate key.

  • 7/28/2019 Overview of Relational DBMS

    21/34

    Boyce-Codd Normal Form (BCNF)K_MK THN_MK THN_AKADEMIK SEMESTER KELAS PRODI HARI_KE

    SIF15012 2012 2012 Ganjil A ILKOM 1

    SIF15012 2012 2012 Ganjil A TIF 2

    PTI15007 2012 2012 Ganjil A TIF 2

    PTI15007 2012 2012 Ganjil A TIF 5

  • 7/28/2019 Overview of Relational DBMS

    22/34

    Relational Algebra Relational algebra is a set of operators to

    manipulate relations

    Defined 8 such operators, two groups of 4 each:

    The traditional set operations: union, intersection,

    difference and Cartesian product

    The special relational operations: select, project, join anddivide

  • 7/28/2019 Overview of Relational DBMS

    23/34

    Union The union of two union-compatible relations R1 and R2, R1 UNION R2, is the set of all

    tuples t belonging to either R1 or R2 or both

    The formal notation for a union operation is U

  • 7/28/2019 Overview of Relational DBMS

    24/34

    Intersection The intersection of two union-compatible relations R1 and R2, R1

    INTERSECT R2, is the set of all tuples t belonging to both R1 and R2.

    The formal notation for an intersect operation is .

  • 7/28/2019 Overview of Relational DBMS

    25/34

    Difference The difference between two union-compatible relations R1 and R2, R1

    MINUS R2, is the set of all tuples t belonging to R1 and not to R2.

    The formal notation for a difference operation is -

  • 7/28/2019 Overview of Relational DBMS

    26/34

    Cartesian product The Cartesian productbetween two relations R1 and R2, R1 TIMES R2, is the set of all tuples t

    such that t is the concatenation of a tuple r belonging to R1 and a tuple s belonging to R2. The

    concatenation of a tuple r = (r1, r2, , rm) and a tuple s = (sm+1, sm+2, , sm+n) is the tuple t

    = (r1, r2, , rm, sm+1, sm+2, , sm+n).

    R1 and R2 dont have to be union-compatible.

    The formal notation for a Cartesian product operation is

  • 7/28/2019 Overview of Relational DBMS

    27/34

    Selection The selectoperation selects a subset of tuples from a relation.

    It is a unary operator, that is, it applies on a single relation.

    The tuples subset must satisfy a selection condition or predicate.

    The formal notation for a select operation is:

    ()

    where is

    / [AND/OR/NOT

    /]

    The comparison operator can be , =, =, and it depends on attribute domain or

    data type constant value

  • 7/28/2019 Overview of Relational DBMS

    28/34

    Selection

  • 7/28/2019 Overview of Relational DBMS

    29/34

    Projection Theprojectoperation builds another relation by selecting a subset of

    attributes of an existing relation.

    Duplicate tuples from the resulting relation are eliminated. It is also a unary

    operator.

    The formal notation for a project operation is:

    ()

    where is the subset attributes of an existing relation

  • 7/28/2019 Overview of Relational DBMS

    30/34

    Projection

  • 7/28/2019 Overview of Relational DBMS

    31/34

    JOIN Thejoin operation concatenates two relations based on a joining condition

    or predicate.

    The relations must have at least one common attribute with the same

    underlying domain, and on such attributes a joining condition can bespecified.

    The formal notation for a join operation is:

    R S

    where is

    <

    The comparison operator can be , =, =, and it depends on attributes domain.

  • 7/28/2019 Overview of Relational DBMS

    32/34

    JOIN

  • 7/28/2019 Overview of Relational DBMS

    33/34

    Division The division operator divides a relation R1 of degree (n+m) by a relation R2

    of degree m and produces a relation of degree n.

    The (n+i)th attribute ofR1 and the ith attribute from R2 should be defined

    on the same domain.

    The result of a division operation between R1 and R2 is another relation,

    which contains all the tuples that concatenated with all R2 tuples are

    belonging to R1 relation.

    The formal notation for a division operation is .

  • 7/28/2019 Overview of Relational DBMS

    34/34

    Division