database review 1a

Upload: suada-bow-weezy

Post on 03-Jun-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Database Review 1a

    1/40

    2. Data Models for Database Systems2 - 1

    Data World

    - Databaserepresents a real world which is changingcontinuously

    -Data model is the procedure for representing a real world

    3 Data Worlds

    real world(reality) conceptual world(concept) computer world(data)

    infornation

    modeling

    data

    modelingobject

    propertiesvalues

    entity set

    attributes

    values

    record type

    field

    values

  • 8/13/2019 Database Review 1a

    2/40

    2. Data Models for Database Systems2 - 2

    Data World (cont'd)

    Database and Real World

    real world conceptual worldinformation

    modeling

    data

    modeling

    logical data structure

    storeddatabase

    data

    structuringconsistency

    database

    design

  • 8/13/2019 Database Review 1a

    3/40

    2. Data Models for Database Systems2 - 3

    Data Model Concepts

    Data model- conceptual tools for describing data and data relationship

    - specify the overall logical structure of database

    Data models fall into three different group : conceptual data model,

    logical data model and physical data model.

    Conceptual data model (High-level)

    - relationship between entity sets, not considering physical storage

    device

    - human oriented data model

    - facilitate database design

    - Entity-Relationship (E-R) model

    - OO data model

  • 8/13/2019 Database Review 1a

    4/40

    2. Data Models for Database Systems2 - 4

    Data Model Concepts (cont'd)

    Logical data model (Representational, Implementation)

    - describing relationship between data field (record-based)

    - overall logical structure of a database

    - high level description of the implementation

    - hierachical model

    collection of trees

    - network model

    collection of record types and links, i.e.,graphs- relational model

    collection of tables

  • 8/13/2019 Database Review 1a

    5/40

    2. Data Models for Database Systems2 - 5

    Data Model Concepts (cont'd)

    Physical data model (Low-level)

    - describe how data is stored in the computer

    - e.g. record format, record orderings, and access paths

    data

    modeling

    logical, representational model

    (logical data structure)

    storeddatabase

    data

    structuringconsistency

    physical, low-level model

  • 8/13/2019 Database Review 1a

    6/40

    2. Data Models for Database Systems2 - 6

    E-R Model

    - by Peter Chen, 1976

    - based on a perception of real world which consists of a set of basic

    objects called entitiesand relationshipsamong these objects

    -E-R diagram is graphical database structure in E-R model which

    is consist of entity set, relationship, attributeand link

    Entity- an object that exists and is distinguishable from other objects

    - ex) Yoon S. A. with social security number 700123-1684321

    - may be abstract, such as a holiday or a concept

  • 8/13/2019 Database Review 1a

    7/402. Data Models for Database Systems2 - 7

    E-R Model (cont'd)

    EntitySet

    - a set of entites of the same type

    - ex) customer: set of all persons having an account at a bank

    account: set of all accounts maintained at a bank

    - rectangles, which represent entity sets- entity sets need notbe disjoint

    a person entity may be an (bank) employee entity,

    a customer entity, both, or neither

    Attribute

    - entity is represented by a set of attributes

    - ex) customer entity set's attributes arecustomer-name,

    security-number, street, and customer-city

  • 8/13/2019 Database Review 1a

    8/402. Data Models for Database Systems2 - 8

    E-R Model (cont'd)

    Domain

    - a set of permitted values

    - ex) domain of customer--name: set of all text strings

    of a certain length

    Relationship- an association among several entities

    - ex) Harris(customer) 401(account)

    Relationship Set

    - a set of relationships of the same type- {(e1, e2, ... , en) | e1 E1, e2 E2, ... , en En}

    - ex) CustAcctdenote association between customersand accounts

    - ternary relationship set CAB : Harris, 401, and Redwood

  • 8/13/2019 Database Review 1a

    9/402. Data Models for Database Systems2 - 9

    E-R Model (cont'd)

    Attribute of Relationship

    - relationship set can have attributes

    - ex) CustAcct's (Harris, 401) has property {(date, 20 Sept 1995)}

  • 8/13/2019 Database Review 1a

    10/402. Data Models for Database Systems2 - 10

    Example

  • 8/13/2019 Database Review 1a

    11/402. Data Models for Database Systems2 - 11

    Constraints on Relationship Set

    Cardinality ratio constraint

    number of entities to which another entity can be associated

    - one-to-one : for each entity in either set, there is at mostone associated member of the other set

    Emp Depte1e2

    e3

    e4

    .

    .

    d1

    d2

    d3

    d4

    d5

    .

    ..

    .

    Manages

  • 8/13/2019 Database Review 1a

    12/402. Data Models for Database Systems2 - 12

    Constarints on Relationship Set (cont'd)

    - many-to-one : each entity in E1(Courses) is associated with at

    most one entity in E2(Teachers), but each entity

    in E2 can be associated any number of entities in E1

    Courses Teacherstaught-by

    - many-to-many : no restriction

    Countries Productsexport

  • 8/13/2019 Database Review 1a

    13/402. Data Models for Database Systems2 - 13

    Constarints on Relationship Set (cont'd)

    Participation constraintthe existence of an entity depends on the existence of

    the relationship to another entity

    - existency dependencythis means that ifyis deleted, so isx

    dominant entity,

    strong or regular entity

    subordinate entity,

    weak entity

  • 8/13/2019 Database Review 1a

    14/402. Data Models for Database Systems2 - 14

    Constarints on Relationship Set (cont'd)

    Account Log Transaction

    account# Balance transaction# date amount

    462-21-23 3,000 1 11 Oct 1996 +50

    262-45-20 6,000 4 12 Oct 1996 +350

    645-44-09 5,000 7 12 Oct 1996 - 150

    ... ...

    dominant, strong subordinate, weak

  • 8/13/2019 Database Review 1a

    15/40

    2. Data Models for Database Systems2 - 15

    Keys

    it is important to be able to discriminate how entities and

    relationships

    Superkey

    - a set of one or more attribute wich allow us to identifyuniquely an entity in the entity set

    - may have unnecessary attributes to distinct

    Candidate Key

    - minimal superkey

    Primary Key

    - a candidate key chosen by the DB designer

  • 8/13/2019 Database Review 1a

    16/40

    2. Data Models for Database Systems2 - 16

    E-R Diagram

    graphical database structure in E-R model

    - rectangle : (strong) entity set

    - double rectangle : weak entity set

    - ellipse : attribute

    - diamond : relationship set- line : (1) link attribute to entity set

    (2) link entity set to relationship set

    see Slide 2-11

  • 8/13/2019 Database Review 1a

    17/40

    2. Data Models for Database Systems2 - 17

    Reducing E-R diagrams to Tables

    (1) Representation of strong entity sets

    D1X D2X ..... Dnsee Fig. 2-14, Fig. 2-15 Korth Book

    (2) Representation of weak entity sets

    {attributes of weak entity set} U {primary key of strong entity set)see Fig. 2-16

    (3) Representation of relationship sets

    {primary key set} U {attribute of relationship set R)

    see Fig. 2-17, Fig 2-18

  • 8/13/2019 Database Review 1a

    18/40

    2. Data Models for Database Systems2 - 18

    Account Log Transaction

    account# Balance date transaction# date amount

    Reducing E-R diagrams to Tables (Ex)

    (1)

    (2)

    (3)

  • 8/13/2019 Database Review 1a

    19/40

    2. Data Models for Database Systems2 - 19

    Generalization

    There are similarities between the checking-accountentity set and

    thesaving-account entity set in the sense that they have several

    attribute in common. This commonalitycan be expressed by

    generalization.

    - Creation method : create a high-level entity set from two or more

    lower level entity set's common attributes

    - Usage : is used to emphasize thesimilaritiesamong lower level

    entity type and to hide their differences

    - Inheritance: lower level entity set (saving-accountand checking

    account) inherit the attributes of higher level entity set (account)

  • 8/13/2019 Database Review 1a

    20/40

    2. Data Models for Database Systems2 - 20

    account

    number

    Generalization (cont'd)

    balance

    account

    saving-

    account

    ISA

    checking-

    account

    interest-

    reteoverdraft-

    amount

    saving-account is an

    account

    account

    number

    balance

    account

    number

    balance

  • 8/13/2019 Database Review 1a

    21/40

    2. Data Models for Database Systems2 - 21

    Generalization (cont'd)

    Transforming E-R diagram including generalization totabular form

    (1) Primary key of high-level entity set plus lower level entity sets

    account + savings-account, checking-account

    (2) Only lower level entity sets

    savings-account, checking-account (including higher-level

    attributes)

  • 8/13/2019 Database Review 1a

    22/40

    2. Data Models for Database Systems2 - 22

    Aggregation

    One limitationof the E-R model is that is not possible to express

    relationship among relationships

    - Aggregation is anabstraction through which relationships are

    treated as high-level entities

    hospital

    hospitalization

    treatment patientsdoctor1 n

    m

    1

  • 8/13/2019 Database Review 1a

    23/40

    2. Data Models for Database Systems2 - 23

    DATA MODEL TYPES

  • 8/13/2019 Database Review 1a

    24/40

    2. Data Models for Database Systems2 - 24

    Hierarchical Data Model

    Basic Concepts and Structure- Hierarchical database consists of a collection of recordswhich

    are connected to one another records through links

    - record : collection of fields (attributes)

    link : inary relstionship (parent-child relationship)* restriction : only one-to-many

    subject

    studentlecturer

    lectureprerequisitesubject

    Hierarchical Definition Tree

    (subjectdatabase schema)

  • 8/13/2019 Database Review 1a

    25/40

    2. Data Models for Database Systems2 - 25

    Hierarchical Data Model (cont'd)

    subject

    student

    lecturer

    lecture (record type)prerequisite

    subject

    subject Database Tree

    (record occurrence)

    C100 Database 3

    L1 Tue-Thu 2-204L2 Mon-Wed 3-403

    S93001 Park E. Y. 90S93002 Hur S. 92

    S93002 Lee S. H. 85

    P94 Kim C. S. Computer

    C99

    ordered tree

    one-to-many

  • 8/13/2019 Database Review 1a

    26/40

    2. Data Models for Database Systems2 - 26

    Characteristics

    - parent-child relationship is one-to-many relationship

    - ordered tree (left to right)

    - n:m relationship can be represented by two 1:n representations

    Restrictions

    - all record occurrences except root record, must be connected

    to parent record

    * need to connect its parent for record insertion

    * have to delete all its child record for record deletion- one-to-many relationship : to associate with two its parent,

    make another tree (m:n => two 1:n relationship)

    Hierarchical Data Model (cont'd)

  • 8/13/2019 Database Review 1a

    27/40

    2. Data Models for Database Systems2 - 27

    Network Data Model

    Basic Concepts and Structure- Network database consists of a collection of recordswhich

    are connected to one another records through links

    but, Data Structure Diagram (DSD) which represent logical

    structure of network database, is networkform- extension of hierarchical data model

    - CODASYL(Conference on Data Systems Language) DBTG

    (Data Base Task Group) proposed the network data model formally

    many-to many link is not allowed (implementation problem)

    - Network Database System :IDMS (Computer Associates)

    TOTAL (Cincom Systems)

    IDS II (Honeywell Information Systems)

  • 8/13/2019 Database Review 1a

    28/40

    2. Data Models for Database Systems2 - 28

    Network Data Model (cont'd)

    Data Structure Diagram (DSD)

    customer

    name street city

    branch

    name assets city

    number balance

    account

    CustAcct BrncAcct

  • 8/13/2019 Database Review 1a

    29/40

    2. Data Models for Database Systems2 - 29

    Network Data Model (cont'd)

    Set Occurrence (database value)

    Kim Daesin Pusan

    Chung Choongmu Seoul

    Lee Hanbat Taejon

    Uam 5,000,000 Pusan

    Namsan 2,000,000 Ulsan

    305 500

    226 336

    177 205

    155 62

    402 100

    408 300

    1: nrelationship

    graph

  • 8/13/2019 Database Review 1a

    30/40

    2. Data Models for Database Systems2 - 30

    Relational Data Model

    Background- Proposed by E. F. Codd (1970, ACM TODS)

    - Non-procedual database language (easy to use)

    - Standard database language : SQL

    * ISO, ANSI, X/Open* SQL, SQL89, SQL2, SQL3, ....

    - Theoretical background (mathematics-based)

    - Relational DBMSs :

    Oracle - 2nd largest S/W maker in the world

    Informix - UNIX RDBMS special group

    Sybase - Client/Server DBMS

    Ingres - ?

  • 8/13/2019 Database Review 1a

    31/40

    2. Data Models for Database Systems2 - 31

    Relational Data Model (cont'd)

    OverviewRelational model = structure + constraints + operation

    Structure

    - Domain : set of atomic values

    - Relational scheme : set of attribute names- Relation : any subset of the Cartesian product of domains

    of attributes int relation scheme

    Set of Tuples

    Employee E# Ename City

    10 Smith LA

    20 James NY

    Workfor Ename Dname

    Smith Physics

    James Mathematics

  • 8/13/2019 Database Review 1a

    32/40

    2. Data Models for Database Systems2 - 32

    Relational Data Model (cont'd)

    - Terminologies

    table : relation

    row : tuple

    column : attribute

    - Arity(degree)number of attribute in the relation

    - Tuple

    ordered list of values from domain D1, D2, ... , Dn

    mapping from attribute names to values in the domainsex) (10, Smith, LA)

    m(E#) = 10, m(Ename) = Smith, m(City) = LA

  • 8/13/2019 Database Review 1a

    33/40

    2. Data Models for Database Systems2 - 33

    Relational Data Model (cont'd)

    Integrity Constraints

    - Entity integrity constraint

    no primary key can be null

    - Referential integrity constraints (foreign key constraints)

    foreign key : set of attributes which is the primary keyof another relation

    (ex) Dept = (Dname, Manager, Budget)

    Employee = (Ename, Bdate, Salary,Dname)

    Every value of the foreign key must existin the set of thecorresponding primary key values of another relation(Dept)

    foregin key

  • 8/13/2019 Database Review 1a

    34/40

    2. Data Models for Database Systems2 - 34

    Operation

    - Operation to manipulate a relation is needed

    - There are two types of operation, Relational Algebra and

    Relational Calculus

    Relational Algebra (How)

    query is expressed by applying specialized algebraic

    operators operators => SQL

    Relational Calculus (What)

    query is describes a desired set of tuples by specifying apredicate the tuples must satisfy => QUEL, QBE

    Relational Data Model (cont'd)

  • 8/13/2019 Database Review 1a

    35/40

    2. Data Models for Database Systems2 - 35

    Object-Oriented Data Model

    Shortcomings of the Conventional Database Technology

    - Too simple for modeling complexnested entities

    - A limited set of atomic data types

    - No frequently usefulsemanticconcepts

    -Impedance mismatchbetween programming languageand database language

    - Inappropriate for long-duration transactions necessary in

    interactive, cooperative design environments (CAD)

    - Unacceptable for various types of computer-intensiveapplications

  • 8/13/2019 Database Review 1a

    36/40

    2. Data Models for Database Systems2 - 36

    Object-Oriented Data Model (cont'd)

    Additional Features of the Next-Generation Database

    Systems

    - Represent and manipulate complex nested objects

    - Store and retrieve arbitary long data- Define and manipulate arbitary data types

    - Represent and manipulate varioussemantic modeling concepts

    - Specify rulesand extented constraints to support inferencing

    and constraint management

    - Manage long-duration cooperative transactions

  • 8/13/2019 Database Review 1a

    37/40

    2. Data Models for Database Systems2 - 37

    Object-Oriented Data Model (cont'd)

    Object-Oriented Approach

    - in Programming language

    from SIMULA-67 (K. Nygard, Norway)

    Smalltalk, Eiffel, C++, Java

    - in Artificial Intelligencefrom introduction of FRAME

    KEE, ART

    - in Database

    from semantic data modelE-R, EE-R, SDM, DAPLEX

  • 8/13/2019 Database Review 1a

    38/40

    2. Data Models for Database Systems2 - 38

    Object-Oriented Data Model (cont'd)

    Core Modeling Concepts

    - Object and Object Identifier

    object = data + operation

    - Attribute and Methodsattribute : specified property to represent an object

    method : an operation of an object ( = code)

    - Encapsulation and Message passing

    encapsulation : the data of an object can only be accessed viathe methods of the objects

    message : a request to perform an operation

    Balance

    5000

    Accountobject

    deposit

    withdraw

    A#

    100

  • 8/13/2019 Database Review 1a

    39/40

    2. Data Models for Database Systems2 - 39

    - Classclass : a templatefrom which objects with the same

    representation and the same behavior can be created

    - Class Hierarchy and Inheritance

    inheritance : a mechanism which allows a new class to beincrementally defined from an existing class

    Object-Oriented Data Model

    object 1object 2

    class

    instantiation instantiation

  • 8/13/2019 Database Review 1a

    40/40

    Object-Oriented Data Model

    Object-Oriented Database Concepts

    Name Age Salary

    Lee 25 500,000data part

    operation part (hire, change Age, change Salary)

    EMPLee is an EMP object

    Balance

    5000

    Accountobject

    pay-interest A#

    100

    : all 6%

    : $1000 -> 5%$1000 -> 6%