Database Fundamentals Presentation

Embed Size (px)

Citation preview

  • 8/6/2019 Database Fundamentals Presentation

    1/132

    14/01/2009 Lord's Kitchen 1

    Database FundamentalsDatabase FundamentalsBasic & Intermediate

  • 8/6/2019 Database Fundamentals Presentation

    2/132

    14/01/2009 Lord's Kitchen 2

    Icons usedIcons used

    Questions References

    Key Concepts

    A Welcome Break

    Demo

    Brain Teasers

  • 8/6/2019 Database Fundamentals Presentation

    3/132

    Module InformationModule InformationModule

    Description

    This module provides students with the basic knowledge

    and skills that are needed to understand the need fordatabases and how they can design them

    Level Basic & Intermediate

    Prerequisites Basic knowledge of data and files

  • 8/6/2019 Database Fundamentals Presentation

    4/132

    Lord's Kitchen

    Module Objective & OutlineModule Objective & Outline

    Module Objective:After completing this Module, you should :

    Understand what is a Database System

    Explain briefly different types of Database Systems

    Be able to create a Database environment with ER Modeling

    Have a broad overview on Relational Database Management System

    Have an introduction to Structured Query Language

    Understand how the DBMS & its host computer system intercommunicate

    Be aware of the new trends in Database

  • 8/6/2019 Database Fundamentals Presentation

    5/132

    Lord's Kitchen

    Module OutlineModule Outline

    Module Flow:

    4.Structured

    QueryLanguage

    2.Types of

    DatabaseSystems

    3.Creating a

    DatabaseEnvironment

    5.Internal

    Management

    1.What is aDatabase

    System

    6.Database

    Trends

  • 8/6/2019 Database Fundamentals Presentation

    6/132

    14/01/2009 Lord's Kitchen 6

    1.0 Database System1.0 Database System

    Learning Objective: At the end of this Topic you will be able to

    Understand what is a Database System

    Know how files are organized

    Appreciate the advantages of using a DBMS

    over a traditional file system

    Be aware of the Database Architecture

  • 8/6/2019 Database Fundamentals Presentation

    7/132

    14/01/2009 Lord's Kitchen 7

    What is a Database SystemWhat is a Database System

    A Database System is essentially a computerizedrecord-keeping system.

    A database-management system (DBMS) consists of

    a collection of interrelated data and a set ofprograms to access those data.

    Database systems are designed to manage large

    volume of information

  • 8/6/2019 Database Fundamentals Presentation

    8/132

    Lord's Kitchen

    File Organization : Terms and ConceptsFile Organization : Terms and Concepts

    Database: Group of related files

    File: Group of records of same type

    Record: Group of related fields

    Field: Group of words or a completenumber

    Byte: Group of bits that represents asingle character

    Bit: Smallest unit of data; binarydigit (0,1)

    Data Hierarchy in a Computer System

  • 8/6/2019 Database Fundamentals Presentation

    9/132

    Lord's Kitchen

    File Organization : Terms and ConceptsFile Organization : Terms and Concepts

    Entity: Person, place, thing, event about which information ismaintained

    Attribute: Description of a particular entity

    Key Field: Identifier field used to retrieve, update, sort a record

  • 8/6/2019 Database Fundamentals Presentation

    10/132

    Lord's Kitchen

    File Organization : Terms and ConceptsFile Organization : Terms and Concepts

    Data redundancy

    Program-Data dependence

    Lack of flexibility

    Poor security

    Lack of data-sharing andavailability

    No concurrency control

    Problems with the Traditional File Environment

    Traditional File Processing

  • 8/6/2019 Database Fundamentals Presentation

    11/132

    Lord's Kitchen

    DBMS and its AdvantagesDBMS and its AdvantagesvA Database Management System is a collection of programs that

    enables users to create and maintain a database. It is ageneral purpose software system that facilitates processes ofdefining, constructing and manipulating databases for variousapplications.

    vAdvantages of Database approach: Controlling Redundancy

    Restricting Unauthorized access

    Providing persistent storage for program objects and data structures

    Permitting inference and actions using deduction rules

    Providing multiple user interface

    Representing complex relationships among data Enforcing integrity constraints

    Providing backup and recovery

  • 8/6/2019 Database Fundamentals Presentation

    12/132

    Lord's Kitchen

    Database Management System (DBMS)Database Management System (DBMS)

  • 8/6/2019 Database Fundamentals Presentation

    13/132

    Lord's Kitchen

    DBMS ArchitectureDBMS Architecture

  • 8/6/2019 Database Fundamentals Presentation

    14/132

    Lord's Kitchen

    Data Independence Logical data independence : capacity to

    change conceptual schema without

    having to change external schema.

    Physical data independence : capacity to

    change internal schema without changing

    conceptual schema.

    DBMS ArchitectureDBMS Architecture

  • 8/6/2019 Database Fundamentals Presentation

    15/132

    Lord's Kitchen

    Functions of DBMSFunctions of DBMS Data definition :

    Specifies contentand structure of database and defines each data

    element

    Data manipulation :

    Manipulates data in a database

    Data security and integrity : Monitors user requests and rejects any unauthorized attempts

    Data recovery and concurrency :

    Enforces certain controls for recovery and concurrency

    Data dictionary:

    Stores definitions of data elements, and data characteristics

    Performance :

    Functions should be performed efficiently

  • 8/6/2019 Database Fundamentals Presentation

    16/132

    14/01/2009 Lord's Kitchen 16

    Requirements of a DBMSRequirements of a DBMS

  • 8/6/2019 Database Fundamentals Presentation

    17/132

    14/01/2009 Lord's Kitchen 17

    Database System : RecapDatabase System : RecapWhy do businesses have trouble finding the information

    they need in their information systems?

    How does a database management system help businesses

    improve the organization of their information?

    What are the advantages of using a DBMS over a

    traditional file system

    State the major functions and requirements of a DBMS

  • 8/6/2019 Database Fundamentals Presentation

    18/132

    14/01/2009 Lord's Kitchen 18

    QuizQuizIf a Customer Database has the following fields:

    EmpId, EmpName, Salary and DeptName, Whatwould be the ideal Key field and why ? EmpID

    EmpName

    DeptName

    EmpId+DeptName

  • 8/6/2019 Database Fundamentals Presentation

    19/132

    14/01/2009 Lord's Kitchen 19

    2.0 Types of Databases2.0 Types of Databases

    Learning Objective: At the end of this Topic you will be able to

    Explain briefly the various types of Database

    Systems

    Relational DBMSHierarchical DBMS

    Network DBMS

    Object-Oriented Databases

  • 8/6/2019 Database Fundamentals Presentation

    20/132

    14/01/2009 Lord's Kitchen 20

    Relational Database ModelRelational Database ModelRepresents data as two-dimensional tables called relations

    Relates data across tables based on common data element Examples: DB2, Oracle, MS SQL Server

  • 8/6/2019 Database Fundamentals Presentation

    21/132

    14/01/2009 Lord's Kitchen 21

    Three Basic Operations in aThree Basic Operations in aRelational DatabaseRelational Database

  • 8/6/2019 Database Fundamentals Presentation

    22/132

    14/01/2009 Lord's Kitchen 22

    Three Basic Operations in aThree Basic Operations in aRelational DatabaseRelational Database

    SELECT

    PROJECT

    JOIN

  • 8/6/2019 Database Fundamentals Presentation

    23/132

    14/01/2009 Lord's Kitchen 23

    Hierarchical Database ModelHierarchical Database ModelIt is a pointer based modelOrganizes data in a tree-like structureStores data in tables and views relationships as linksSupports one-to-many parent-child relationshipsPrevalent in large legacy systems

  • 8/6/2019 Database Fundamentals Presentation

    24/132

    14/01/2009 Lord's Kitchen 24

    Network DBMSNetwork DBMS

    Depicts data logically as many-to-manyrelationshipsOrganizes data in tables and views relationships

    as links

    It is also a pointer based modelOrganizes data in arbitrary graphs

  • 8/6/2019 Database Fundamentals Presentation

    25/132

    14/01/2009 Lord's Kitchen 25

    Hierarchical and Network DBMSHierarchical and Network DBMS

    Some of the Disadvantages Outdated

    Complex pointer based organization

    Less flexible compared to RDBMS

    Lack support for ad-hoc and English language-like queries

  • 8/6/2019 Database Fundamentals Presentation

    26/132

    14/01/2009 Lord's Kitchen 26

    Object-Oriented DatabasesObject-Oriented Databases

    Object-oriented DBMS: Stores data and

    procedures as objects that can be retrieved

    and shared automatically

    Object-relational DBMS: Provides capabilities of

    both object-oriented and relational DBMS

  • 8/6/2019 Database Fundamentals Presentation

    27/132

    14/01/2009 Lord's Kitchen 27

    Types of DatabasesTypes of Databases :: SummarySummary

    In a relational database the data is perceivedas tables (and nothing but tables) by the

    user

    The relational operators available are used to

    manipulate the data in the tables

  • 8/6/2019 Database Fundamentals Presentation

    28/132

    14/01/2009 Lord's Kitchen 28

    3.0 Creating a DB environment3.0 Creating a DB environment

    Learning Objective:

    At the end of this Topic you will

    Have the ability to model an application systembased on the E-R Modeling approach.

    Understand the Relational Database concepts likeNormalization, Data Integrity, Relational

    Operations like Union, Intersection etc.

    Be able to Design Relational Databases based on

    E-R Models or System Requirements for an

    application.

  • 8/6/2019 Database Fundamentals Presentation

    29/132

    14/01/2009 Lord's Kitchen 29

    Introduction to Data ModelingIntroduction to Data ModelingWhat is Data Modeling?

    A technique for analyzing requirements and for

    identifying the information needs of an organization

    Why Data Modeling is important?

    Cannot build a good system without knowing

    what data needs to be captured and how it needs to

    be organized

  • 8/6/2019 Database Fundamentals Presentation

    30/132

    14/01/2009 Lord's Kitchen 30

    Introduction to Data ModelingIntroduction to Data ModelingAn Overview :

    Conceptual representation of the data structures required by adatabase

    Data structures include the data objects, the associations betweendata objects, and the rules which govern operations on theobjects

    Focuses on what data is required and how it should be organized Independent of hardware or software constraints

    Data Model And Database Design:

    Data Model is to a Database what a Building plan or a blueprint isto a Building

    A Database Design translates a data model into a database

    A Data Model is the conceptual design of a database

  • 8/6/2019 Database Fundamentals Presentation

    31/132

    14/01/2009 Lord's Kitchen 31

    E-R ModelingE-R Modeling

    Originally proposed by Peter Chen (1976)Views the real world as entities and relationshipsKey component is the E-R DiagramMost common model used for designing relational databases

    Entity- An identifiable object or concept of

    significance

    Attribute- Property of an entity or relationship

    Relationship- An association between entities

    Identifier- one or more attributes identifying aninstance

    (occurrence) of an entity

  • 8/6/2019 Database Fundamentals Presentation

    32/132

    14/01/2009 Lord's Kitchen 32

    Entity relationship diagramEntity relationship diagram

  • 8/6/2019 Database Fundamentals Presentation

    33/132

    14/01/2009 Lord's Kitchen 33

    E-R ModelingE-R Modeling

    hasworksforDept No.

    Name

    NameEmp Id.

    Entity

    Relations

    hip

    Attributes

    EMPLOYEEDEPARTMENT

    Identifier

  • 8/6/2019 Database Fundamentals Presentation

    34/132

    14/01/2009 Lord's Kitchen 34

    Entity

    Any object or thing of significance about which data

    needs to be collected and maintained

    Could be

    Concrete or tangible like a person or a building

    Abstract like a concept or activity

    Analogous to a table in a relational database

    Examples: EMPLOYEES, PROJECTS, INVOICES

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    35/132

    14/01/2009 Lord's Kitchen 35

    Entity Rules

    Any thing or object may only be represented by one entity. Entities are

    mutually exclusive in all cases.

    Each entity must be uniquely identifiable. Each instance (occurrence) of

    an entity must be separate and distinctly identifiable from all other

    instances of that type of entity.

    Entity Classification and Types

    Classified as dependent and independent

    An independententity is one that does not rely on another for

    identification

    A dependent entity is one that relies on another for identification

    In some, methodologies, the terms used are strong and weak,

    respectively

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    36/132

    14/01/2009 Lord's Kitchen 36

    Entity Classification and Types

    Fundamental entity - An entity that exists and is of interest in its

    own right. Generally, most entities in the data model are

    fundamental entities.

    Example :Department and Employee are both fundamental entities

    Special Entity Types

    Associative Entity -Used to associate two entities in order to reconcile a

    many-many relationship

    Sub-type/super-type- Used in generalization hierarchies to

    represent a subset of instances of their of parent entity

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    37/132

  • 8/6/2019 Database Fundamentals Presentation

    38/132

    14/01/2009 Lord's Kitchen 38

    Generalization Hierarchies

    Generalization occurs when two or more entitiesrepresent categories of the same real-world object.

    Example: CAR and TRUCK represent categories of the

    same entity, VEHICLE is the super-type; CAR and TRUCK

    would be the subtypes

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    39/132

    14/01/2009 Lord's Kitchen 39

    Generalization Hierarchies

    Form of abstraction that specifies that two or more entities that

    share common attributes can be generalized into a higher level

    entity type called a super-type or generic entity.

    The lower-level of entities become the sub-type, or categories,

    to the super-type. Sub-types are dependent entities.

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    40/132

    14/01/2009 Lord's Kitchen 40

    Generalization Hierarchies

    Sub-types can be either mutually exclusive (disjoint) oroverlapping (inclusive)

    In an overlapping hierarchy an entity instance can be part of

    multiple subtypes

    Example: Entity PERSON represents people at a university. It has three subtypes,

    FACULTY, STAFF, and STUDENT. A STAFF member could also be registered as a

    STUDENT

    PERSON

    FACULTYSTUDENT STAFF

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    41/132

  • 8/6/2019 Database Fundamentals Presentation

    42/132

    14/01/2009 Lord's Kitchen 42

    Generalization Hierarchies - NestedGeneralization Hierarchies - Nested

    PERSON

    FACULTYSTUDENT

    UNDERGRAD GRADUATE

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    43/132

    14/01/2009 Lord's Kitchen 43

    AttributeAttributes describe a property or a characteristic of an

    entity

    A particular instance of an attribute is a value.

    For example John Doe is one value of the attribute Name.Simple attributeContains only atomic values

    Composite attributeHas component attributes

    StudentName

    FName

    LName

    MI

    DOB

    Simple Composite

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    44/132

    14/01/2009 Lord's Kitchen 44

    Attribute Classification

    Single-valued attribute

    Has exactly one value per instance of an entity

    Multi-valued attribute

    Contains repeating values per instance of an entity

    v

    Module

    Student

    Math

    Physics

    Id

    Multi-valued

    Single-

    valued

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    45/132

  • 8/6/2019 Database Fundamentals Presentation

    46/132

    14/01/2009 Lord's Kitchen 46

    Relationship

    Represents an association between two or more

    entities

    Examples

    - Employees work for Departments

    - Departments manage one or more projects

    - Employees are assigned to projects

    - Projects have sub-tasks

    - Orders have line items

    Defined in terms of:

    - Degree

    - Connectivity- Cardinality

    - Direction

    - Type

    - Existence

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    47/132

    14/01/2009 Lord's Kitchen 47

    Degree

    Number of entities associated with the relationshipBinary relationships, the association between two entities is the

    most common type in the real world. N-ary is the general form for

    degree n

    Connectivity

    Mapping of associated entity instances in the relationship.The values of connectivity are "one" or "many.

    Cardinality

    Actual number of related occurrences for each of the two entities.

    The basic types of connectivity for relations are: one-to-one, one-to-many,

    and many-to-many.

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    48/132

    14/01/2009 Lord's Kitchen 48

    Connectivity and Cardinality

    A one-to-one (1:1) relationship is when at most one instance of a entity A

    Is associated with one instance of entity B.

    For example:

    Employees in the company are each assigned their own office. For each

    Employee there exists a unique office and for each office there exists a

    unique employee.

    A one-to-many (1:N) relationships is when for one instance of entity A,

    there are zero, one, or many instances of entity B, but for one instance

    of entity B, there is only one instance of entity A.

    An example :

    A department has many employees each employee is assigned to one department

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    49/132

    14/01/2009 Lord's Kitchen 49

    Connectivity and Cardinality

    A many-to-many relationship, is when for one instance of entity

    A, there are zero, one, or many instances of entity B and for

    one instance of entity B there are zero, one, or many instances

    of entity A.

    An example is:employees can be assigned to no more than two projects at the

    same time; Project must have assigned at least three employees

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    50/132

    14/01/2009 Lord's Kitchen 50

    Direction

    Indicates the originating entity of a binary relationship. The entity

    from which a relationship originates is the parent entity; the entity

    where the relationship terminates is the child entity.

    Type

    The direction of a relationship is determined by its connectivity.

    Identifying and Non-identifying

    An identifying relationship is one in which one of the child entities is also

    dependent entity.

    A non-identifying relationship is one in which both entities are

    independent.

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    51/132

    14/01/2009 Lord's Kitchen 51

    ExistenceDenotes whether the existence of an entity instance is

    dependent

    upon the existence of another, related, entity instance.

    Defined as either mandatory or optional.

    Mandatory and optional relationship

    If an instance of an entity must always occur for an entity to beincluded in a

    relationship, then it is mandatory. If the instance of the entity is

    not required, it

    is optional.

    Example: Mandatory :Every project must be managed by a

    single department Optional : Employees may be assigned to work on

    projects

    E-R ModelingE-R Modeling

    d l

  • 8/6/2019 Database Fundamentals Presentation

    52/132

    14/01/2009 Lord's Kitchen 52

    E-R Notation

    No standard notation

    Original notation by Chen

    Common notations are: Bachman, crow's foot, and IDEFIX

    All styles represent entities as rectangular boxes and

    relationships as lines connecting boxes

    Each style uses a special set of symbols to represent the

    cardinality of a connection

    E-R ModelingE-R Modeling

    d li

  • 8/6/2019 Database Fundamentals Presentation

    53/132

    14/01/2009 Lord's Kitchen 53

    Entities

    Represented by labeled rectanglesThe label is the name of the entity

    Entity names should be singular nouns.

    Relationships

    Represented by a solid line connecting

    two entities.Name written above the line

    Relationship names should be verbs

    Employee

    Department

    Works for

    E-R ModelingE-R Modeling

    E R M d li

  • 8/6/2019 Database Fundamentals Presentation

    54/132

    14/01/2009 Lord's Kitchen 54

    Attributes

    Listed inside the entity rectangle

    Underlined

    Names should be singular nouns

    Cardinality

    Many is represented by a line ending in a crow's

    foot. If omitted, cardinality is one

    Existence

    Represented by placing a circle or a

    perpendicular bar on the line

    Mandatory existence is shown by the bar next to

    the entity for an instance that is required

    Optional existence is shown by placing a circle

    next to the entity that is optional

    EmployeeEmpID

    EmpName

    E-R ModelingE-R Modeling

    d lE R M d li A i

  • 8/6/2019 Database Fundamentals Presentation

    55/132

    14/01/2009 Lord's Kitchen 55

    How to create an E-R Model from Requirements ?Step 1: Identify Entities

    Entities are things people talk about, record information about

    and do work on by definition

    Any keyword (noun) is a candidate

    Identify generic object from reference to instances or

    occurrences

    Combine synonyms to represent a single entity

    An Example : Purchase Order - System Requirements

    A buyer creates a purchase order (PO) as and when the need arises. A PO is for a Specific vendor. A PO has one or more line items. A buyer cannot create a PO of

    Total value more than his approval limit. A PO can be sent to the vendor by mail,

    fax, EDI. A PO can be canceled before it is submitted. A PO can be linked to a

    sales order

    E-R Modeling - AssignmentE-R Modeling - Assignment

    R d liE R M d li

  • 8/6/2019 Database Fundamentals Presentation

    56/132

    14/01/2009 Lord's Kitchen 56

    Step 1: Identify EntitiesEntities

    Purchase Order (PO) Buyer? Vendor Line Items Sales Order

    Approval Limit?Buyercharacterizes a PO Approval Limit characterizes a Buyer

    What does it tell us?

    Approval Limit is not an entityBuyer is an entity

    Approval Limit is an attribute of the entity Buyer

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    57/132

    E R M d liE R M d li

  • 8/6/2019 Database Fundamentals Presentation

    58/132

    14/01/2009 Lord's Kitchen 58

    Step 2: Identify Relationships

    Grid Technique

    PO

    PO replaced by Buyer

    Buyer creates a is approver of

    Vendor

    Vendor suppliesagainst a

    - - Line

    Line belongs to a - created for

    item suppliedby

    -

    E-R ModelingE-R Modeling

  • 8/6/2019 Database Fundamentals Presentation

    59/132

    E R M d liE R M d li

  • 8/6/2019 Database Fundamentals Presentation

    60/132

    14/01/2009 Lord's Kitchen 60

    Step 3 : Identify Attributes

    An attribute is any detail that server to identify, classify, quantify or

    express the the state of an entity

    Ask the following question for each entity What information do you

    need to know or hold about ?

    Potential attributes are easily found by examining paper forms

    E-R ModelingE-R Modeling

    E R M d liE R M d li

  • 8/6/2019 Database Fundamentals Presentation

    61/132

    14/01/2009 Lord's Kitchen 61

    Step 3: Identify Attributes

    Purchase Order No __________Buyer _________ Vendor ___________Date Created ______

    No Item Quantity Value ___ ___________ ________________ ___ ___________ ________________

    ___ ___________ ________________

    Shipping AddressStreet _________City __________Zip _______ Total Value ______

    Example Purchase Order Form

    Purchase Order NoVendor Buyer Date Created

    Item? Address City State Zip Total Value?

    E-R ModelingE-R Modeling

    E R M d liE R M d li

  • 8/6/2019 Database Fundamentals Presentation

    62/132

    14/01/2009 Lord's Kitchen 62

    E-R Model of the Purchase Order Example

    PURCHASEORDER

    VENDOR

    BUYER

    creates

    created by

    supplies against

    created for a

    LINE

    has

    belongs to

    ITEM

    created for

    exists on

    E-R ModelingE-R Modeling

    E R M d liE R M d li g

  • 8/6/2019 Database Fundamentals Presentation

    63/132

    14/01/2009 Lord's Kitchen 63

    Major Modeling TechniquesPeter Chens original entity/relationship

    diagramsInformation EngineeringRichard Barkers notation, used by Oracle

    corporationIDEF1XObject Role ModelingUnified Modeling Language (UML)Extensible Markup Language (XML)

    E-R ModelingE-R Modeling

    E R M d liE R M d li g

  • 8/6/2019 Database Fundamentals Presentation

    64/132

    14/01/2009 Lord's Kitchen 64

    Major Modeling TechniquesData Modeling has sets of two audiences:

    User community - Uses the models to verify that the analysts

    understand their environment and their requirements.

    Systems designers - Use the business rules implied by the

    models as the basis for their design of computer systems.

    Different techniques are better for one audience or the

    other.

    All techniques are fundamentally the same

    Differences are mainly in syntactic or notational

    E-R ModelingE-R Modeling

    R l ti l M d lRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    65/132

    14/01/2009 Lord's Kitchen 65

    Relational ModelRelational Model

    Objective :

    To give an informal introduction to relational

    concepts especially as they

    relate to relational database design issues.

    What it is not ? This does not give a complete description of relational

    theory.

    R l ti l M d lRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    66/132

    14/01/2009 Lord's Kitchen 66

    Formally introduced by Dr. E. F. Codd in 1970

    Represents data in the form of two-dimension

    tables

    A relational database is a collection of two-dimensional tables

    Basic understanding of the model needed to

    design and use relational databases

    Relational ModelRelational Model

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    67/132

    14/01/2009 Lord's Kitchen 67

    Tables, Columns and RowsRelationships and KeysData IntegrityNormalizationWhat is a table?

    Represents some real-world person, place, thing, orevent

    Two-dimensional Columns Rows

    Cou rs e No . Co ur s e _Title C_Hr s .De pt. C

    CIS 120 Intro to CIS 4 Cis

    M KT 333 Intro to M k ting 3 M KTECO 473 Labor Econ. 3 ECO

    BA201 Intro to Stat. 5 ECO

    n r o o as e

    Relational ModelRelational Model

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    68/132

    14/01/2009 Lord's Kitchen 68

    Relational ModelRelational Model

    TableColumns represent a property of the person, place,thing or event that the table represents

    Rows represent an occurrence or instance of what thetable represents

    A data value is stored in the intersection of a row and

    columnEach named column has a domain, which is the set of

    values that may appear in that column

    Empid Name Level DOJ Manager

    101412 John M3 4/10/98 101667

    102235 Nancy M4 1/23/01 101412

    101398 Mike S1 8/15/95 101667

    101667 Jeff M2 6/2/96 100351

    103893 Cindy M3 7/17/95 101284

    101116 Rahul S2 2/20/00 101412102739 Scott C1 4/13/01 101667

    Employee

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    69/132

    14/01/2009 Lord's Kitchen 69

    Relational ModelRelational Model

    In this document Formal Terms Many Database Manuals

    Table Relation Table

    Column Attribute Field

    Row Tuple Record

    Table - Terminology

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    70/132

    14/01/2009 Lord's Kitchen 70

    Relational ModelRelational Model

    Salient features of a relational table

    Values are atomic (1NF) Column values are of the same kind (Domain)

    Each Row is unique (Primary Key)

    Sequence of columns is insignificant

    Sequence of rows is insignificant

    Each column must have a unique name

    Relationships and Keys

    Keys - Fundamental to the concept of relational databases

    Relationship - An association between two or more tables

    defined by means of keys

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    71/132

    14/01/2009 Lord's Kitchen 71

    Relational ModelRelational Model

    Primary Key

    Column or a set of columns that uniquely identify a row in a

    table

    Must be unique and must have a value

    Foreign Key

    Column or set of columns which references the primary key or

    a unique key of another table

    Rows in two tables are linked by matching the values of the

    foreign key in one table with the values of the primary key in

    another

    EMP_ID in table EMPLOYEE is the primary key

    DEPT_NO in table DEPARTMENT is the primary key

    DEPT_NO in table EMPLOYEE is a foreign key

    Examples

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    72/132

    14/01/2009 Lord's Kitchen 72

    Relational ModelRelational Model

    Data Integrity

    Ensures correct and consistent navigation and manipulation ofrelational tables

    Two types of integrity rules

    Entity integrity

    Referential integrity

    The entity integrity rule states that the value of the primary key

    can never be a null value

    The referential integrity rule states that if a relational table has a

    foreign key, then every value of the foreign key must either be null or

    match the values in the relational table in which that foreign key is a

    primary key

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    73/132

    14/01/2009 Lord's Kitchen 73

    Relational ModelRelational Model

    Data Manipulation

    Relational tables are equivalent to sets Operations that can be performed on sets can be

    performed on relational tables

    Relational Operations such as :

    Selection Projection Join

    Union

    Intersection

    Difference

    Product

    Division

    UNION

    INTERSECTION

    DIFFERENCE

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    74/132

    14/01/2009 Lord's Kitchen 74

    Relational ModelRelational Model

    Selection

    The select operator, sometimes called restrict to preventconfusion with the SQL SELECT command, retrieves subsets of rows

    from a relational table based on a value(s) in a column or columns

    A B C D E1 A 212 Y 2

    2 C 45 N 84

    3 B 8656 N 4

    4 D 324 N 56

    5 C 5656 Y 34

    6 A 445 N 4

    7 B 546 Y 55

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    75/132

    14/01/2009 Lord's Kitchen 75

    Relational ModelRelational Model

    Projection

    The project operator retrieves subsets of columns from a relationaltable removing duplicate rows from the result

    A B C D E

    1 A 212 Y 2

    2 C 45 N 84

    3 B 8656 N 4

    4 D 324 N 56

    5 C 5656 Y 34

    6 A 445 N 4

    7 B 546 Y 55

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    76/132

    14/01/2009 Lord's Kitchen 76

    Relational ModelRelational Model

    k x y1 A 2

    2 B 4

    3 C 6

    k x y

    1 A 2

    4 D 8

    5 E 10

    Table A

    Table B

    A TIMES B

    ak ax ay bk bx by

    1 A 2 1 A 2

    1 A 2 4 D 8

    1 A 2 5 E 10

    2 B 4 1 A 2

    2 B 4 4 D 8

    2 B 4 5 E 10

    3 C 6 1 A 2

    3 C 6 4 D 8

    3 C 6 5 E 10

    Product

    The product of two relational tables, also called the Cartesian Product, isthe concatenation of every row in one table with every row in the second.

    The product of table A (having m rows) and table B (having n rows) is the

    table C (having m x n rows). The product is denoted as A X B or A TIMES B

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    77/132

    14/01/2009 Lord's Kitchen 77

    Relational ModelRelational Model

    Join

    Combines the product, selection and projection operationsCombines (concatenates) data from one row of a table with rows from

    another or same tableCriteria involve a relationship among the columns in the join relational table

    If the join criterion is based on equality of column value, the result is called an equi join

    A natural join is an equi join with redundant columns removedJoins can also be done on criteria other than equality. Such joins are called non-equi joins

    k a b

    1 A 2

    2 B 43 C 6 k c

    1 aa

    3 bb

    5 cc

    k a b k c1 A 2 1 aa

    3 C 6 3 bb

    k a b c1 A 2 aa3 C 6 bb

    Table A

    Equi-JoinTable B

    Natural Join

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    78/132

    14/01/2009 Lord's Kitchen 78

    Relational ModelRelational Model

    Union

    The UNION operation of two tables is formed by appending rows fromone table to those of a second to produce a third. Duplicate rows are

    eliminated

    Tables in an UNION operation must have the same number of columns

    and corresponding columns must come from the same domain

    Table A

    Table B

    k x y

    1 A 2

    2 B 4

    3 C 6

    k x y1 A 2

    4 D 8

    5 E 10

    k x y

    1 A 2

    2 B 4

    3 C 6

    4 D 8

    5 E 10

    A Union B

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    79/132

    14/01/2009 Lord's Kitchen 79

    Relational ModelRelational Model

    The UNION operation of two tables is formed by appending rows from one table to

    those of a second to produce a third. Duplicate rows are eliminatedTables in an UNION operation must have the same number of columns and

    corresponding columns must come from the same domain

    Table A

    Table B

    k x y

    1 A 2

    2 B 4

    3 C 6

    k x y1 A 2

    4 D 8

    5 E 10

    k x y

    1 A 2

    2 B 4

    3 C 6

    4 D 8

    5 E 10

    A Union B

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    80/132

    14/01/2009 Lord's Kitchen 80

    Relational ModelRelational Model

    Intersection

    The intersection of two relational tables is a third table thatcontains common rows. Both tables must be union compatible. The

    notation for the intersection of A and B is A [intersection] B = C or A

    INTERSECT B

    k x y

    1 A 2

    2 B 4

    3 C 6

    k x y

    1 A 2

    4 D 8

    5 E 10

    k x y

    1 A 2

    Table A

    Table B

    A Intersect B

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    81/132

    14/01/2009 Lord's Kitchen 81

    Relational ModelRelational Model

    Difference

    The difference of two relational tables is a third that contains thoserows that occur in the first table but not in the second. The Difference

    operation requires that the tables be union compatible.

    The notation for difference is A MINUS B or A-B. As with arithmetic, the order of

    subtraction matters. That is, A - B is not the same as B - A.

    k x y

    1 A 2

    2 B 4

    3 C 6Table A

    Table B

    A MINUS B

    k x y

    1 A 2

    4 D 8

    5 E 10

    B MINUS A

    k x y

    2 B 4

    3 C 6

    k x y

    4 D 8

    5 E 10

    Relational ModelRelational Model

  • 8/6/2019 Database Fundamentals Presentation

    82/132

    14/01/2009 Lord's Kitchen 82

    Relational ModelRelational Model

    Table A Table B

    A DIV B

    Division

    The division operator results in columns values in one table forwhich there are other matching column values corresponding to every

    row in another table.

    k x y

    1 A 2

    1 B 4

    2 A 2

    3 B 4

    4 B 43 A 2

    x y

    A 2

    B 4

    k

    1

    3

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    83/132

    14/01/2009 Lord's Kitchen 83

    NormalizationNormalization

    Normalization theory is based on the concepts of normal forms. A

    relational table is said to be a particular normal form if it satisfieda certain set of constraints.

    We shall discuss four normal forms in this Module.

    The concept offunctional dependencyis the basis for the first three normal forms.

    A column Y of a relational table is said to be functionally dependentupon column X

    when values of column Y are uniquely identified by values of column X.

    What is Functional Dependency ?

    Full functional dependence applies to tables with composite keys. Column Y in relational

    table R is fully functional on X of R where X is a composite key if it is functionally

    dependent on X and not functionally dependent upon any subset of X.

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    84/132

    14/01/2009 Lord's Kitchen 84

    NormalizationNormalizationUn normalized

    Relation

    NormalizedRelation (1NF)

    2 NF

    3 NF

    Boyce/Codd NF

    Removerepeating groups

    Remove partialdependencies

    Remove transitivedependencies

    Remove remainingAnomalies resultingfrom FDs

    Remove multivalueddependencies

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    85/132

    14/01/2009 Lord's Kitchen 85

    NormalizationNormalization

    An Example : A company obtains parts from a number of suppliers. Each

    supplier is located in one city. A city can have more than one supplier located

    there and each city has a status code associated with it. Each supplier may

    provide many parts.

    The company creates a simple relational table to store this information:

    FIRST (s#, status, city, p#, qty)

    s# Supplier identification numberstatus Status code assigned to city

    City City where supplier is locatedp# Part number of part supplied

    Qty Qty of parts supplied to date

    Composite primary key is (s#, p#)

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    86/132

    14/01/2009 Lord's Kitchen 86

    NormalizationNormalization

    FIRST NORMAL FORM 1NFA relational table is said to be in the first normal form if all values of the columns

    are atomic. That is, they contain no repeating values.

    s# city status p# qty

    s1 London 20 p1 300

    s1 London 20 p2 100

    s1 London 20 p3 200

    s1 London 20 p4 100

    s2 Paris 10 p1 250

    s2 Paris 10 p3 100

    s3 Tokyo 30 p2 300

    s3 Tokyo 30 p4 200

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    87/132

    14/01/2009 Lord's Kitchen 87

    SECOND NORMAL FORM 2NF

    Table FIRST contains redundant data. Redundancy causes update

    anomalies.

    Update anomalies - problems that arise when information is inserted,

    deleted, or updated.

    INSERT. The fact that a certain supplier (s5) is located in aparticular city (Athens) cannot be added until they supplied a part.

    DELETE. If a row is deleted, then not only is the information about

    quantity and part lost but also information about the supplier.

    UPDATE. If supplier s1 moved from London to New York, then six

    rows would have to be updated with this new information.

    NormalizationNormalization

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    88/132

    14/01/2009 Lord's Kitchen 88

    A relational table is in second normal form 2NF if it is in 1NF and every non-key

    column is fully dependent upon the primary key. That is, every non-key column

    must be dependent upon the entire primary key.

    FIRST is in 1NF but not in 2NF because status and city are functionally

    dependent upon only on the column s# of the composite key (s#, p#).

    Steps for transforming a 1NF table to 2NF is:

    1.Identify any determinants other than the composite key, and the columns they

    determine.

    2.Create and name a new table for each determinant and the unique columns it

    determines.

    3.Move the determined columns from the original table to the new table.

    Determinate becomes the primary key of the new table.

    4.Delete the columns you just moved from the original table except for the

    determinate which will serve as a foreign key.

    NormalizationNormalization

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    89/132

    14/01/2009 Lord's Kitchen 89

    SECOND NORMAL FORM 2NF

    s# city status

    s1 London 20

    s2 Paris 10

    s3 Tokyo 30

    s# p# qty

    s1 p1 300

    s1 p2 100s1 p3 200

    s1 p4 100

    s2 p1 250

    s2 p3 100

    s3 p2 300

    s3 p4 200

    PARTS

    SECOND

    NormalizationNormalization

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    90/132

    14/01/2009 Lord's Kitchen 90

    SECOND NORMAL FORM 2NF

    Modification Anomalies Tables in 2NF but not in 3NF still contain modification

    anomalies:

    INSERT. The fact that a particular city has a certain

    status (Rome has a status of 50) cannot be inserted until

    there is a supplier in the city. DELETE. Deleting any row in SUPPLIER destroys the

    status information about the city as well as the association

    between supplier and city.

    NormalizationNormalization

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    91/132

    14/01/2009 Lord's Kitchen 91

    THIRD NORMAL FORM 2NF

    A relational table is in third normal form (3NF) if it is already in 2NF and every

    non-key column is non transitively dependent upon its primary key.

    In other words, all non-key attributes are functionally dependent onlyupon the primary key.

    s# city status

    s1 London 20

    s2 Paris 10

    s3 Tokyo 30

    s4 Paris 10

    SUPPLIERThe table supplier is in 2NF but not in

    3NF because it contains a transitivedependencySUPPLIER.s# > SUPPLIER.citySUPPLIER.city > SUPPLIER.statusSUPPLIER.s# > SUPPLIER.status

    NormalizationNormalization

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    92/132

    14/01/2009 Lord's Kitchen 92

    Steps for transforming a table into 3NF is:

    1.Identify any determinants, other the primary key, and the columns theydetermine.2.Create and name a new table for each determinant and the unique

    columns it determines.3.Move the determined columns from the original table to the new table. The

    determinant becomes the primary key of the new table.

    s# citys1 London

    s2 Pariss3 Tokyos4 Pariss5 London

    SUPPLIER

    city status

    London 20Paris 10Tokyo 30

    Rome 50

    CITY_STATUS

    The transformation ofSUPPLIER into 3NF

    NormalizationNormalization

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    93/132

    14/01/2009 Lord's Kitchen 93

    Advantages of 3rd Normal form :

    Eliminates redundant data which in turn saves space and reducesmanipulation anomalies.

    Example:

    INSERT: Facts about the status of a city, Rome has a status of 50, can be added

    even though there is not supplier in that city.

    DELETE: Information about supplier can be deleted without destroying

    information about a city.UPDATE: Changing the location of a supplier or the status of a city requires

    modifying only one row.

    s# citys1 London

    s2 Pariss3 Tokyos4 Pariss5 London

    SUPPLIER

    city status

    London 20Paris 10Tokyo 30

    Rome 50

    CITY_STATUS

    The transformation ofSUPPLIER into 3NF

    NormalizationNormalization

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    94/132

    14/01/2009 Lord's Kitchen 94

    Advanced Forms :: BOYCE CODD NORMAL FORM

    Many practitioners argue that placing entities in 3NF is generallysufficient because it is rare that entities that are in 3NF are not also in

    4NF and 5NF. The advanced forms of normalization are:

    Boyce-Codd Normal FormFourth Normal Form

    Fifth Normal FormBoyce-Codd normal form (BCNF) is a more rigorous version of the 3NF.

    BCNF is based on the concept of determinants. A determinant column is

    one on which some of the columns are fully functionally dependent.

    A relational table is in BCNF if and only if every determinant is a

    candidate key.

    NormalizationNormalization

  • 8/6/2019 Database Fundamentals Presentation

    95/132

    14/01/2009 Lord's Kitchen 95

    Database DesignDatabase Design

    This section presents and discusses How to translate the E-R (conceptual) model (diagram) to

    an RDBMS (logical) schema. Exercise on E-R Modeling and Database Design

    Some Guidelines - Entities: Create one table for each simple (not a sub-type or super-type)

    entity. Attributes: Map each attribute to a candidate column with a more

    precise format. Optional attributes become null columns Mandatory attributes become not null columns

    Unique Identifier: Convert the components of the unique identifier tothe primary key of the table.

  • 8/6/2019 Database Fundamentals Presentation

    96/132

    b

  • 8/6/2019 Database Fundamentals Presentation

    97/132

    14/01/2009 Lord's Kitchen 97

    Database DesignDatabase DesignA few comments

    There are more rules, treating exceptions, but these

    are good enough in most cases

    There may occur reasons to violate the rules.

    Always: use common sense and expect iterativedevelopment.

    Use CASE tools like ERWin wherever possible. Tools can

    automatically generate SQL table definitions from

    drawn E-R diagrams.

    b i A i

  • 8/6/2019 Database Fundamentals Presentation

    98/132

    14/01/2009 Lord's Kitchen 98

    Database Design:: AssignmentDatabase Design:: Assignment

    Develop an E-Rmodel and database

    schema for a systemto handle purchaseorders.

  • 8/6/2019 Database Fundamentals Presentation

    99/132

    14/01/2009 Lord's Kitchen 99

    Creating a DB environment : SummaryCreating a DB environment : Summary The first step in designing a database application is to understand

    what information the database needs to store and what integrityconstraints or business rules apply to the data.

    Data Model is to a Database what a Building plan or a blueprint is to

    a Building. It is the conceptual model of the Database.

    Given a relational schema we need to decide whether it is a good

    design or whether we need to decompose it into smaller relations.

    Normalization gives the guidance to such decomposition.

  • 8/6/2019 Database Fundamentals Presentation

    100/132

    14/01/2009 Lord's Kitchen 100

    4.0 Structured Query Language4.0 Structured Query Language

    Learning Objectives:At the end of this Topic you will be able to

    Write simple SQL queries

    Get familiar with the various relational operationssuch as SELECT,

    PROJECT and JOIN

    A d iA I d i

  • 8/6/2019 Database Fundamentals Presentation

    101/132

    14/01/2009 Lord's Kitchen 101

    An IntroductionAn Introduction

    SELECT column-listFROM table-names WHERE condition(s)

    Structured Query Language - (SQL) is the most widely

    used commercial relational database language. The SQLhas several parts :

    DML The Data Manipulation Language (DML)

    DDL The Data Definition Language (DDL)

    Embedded and dynamic SQL

    Security

    Transaction management

    Client-server execution and remote database access

  • 8/6/2019 Database Fundamentals Presentation

    102/132

    Lord's Kitchen

    Query ProcessingQuery ProcessingQuery Processing

    Query in a High Level Language (typically a 4 GL)Parsing : The parser converts a query, submitted by

    a database user and written in a high-levellanguage, into an algebraic operators expression.

    Optimization : It is the key Topic for queryprocessing design. It receives the expression andbuilds a good execution plan. The plan determinesthe order of execution of the operators and selectssuitable algorithms for implementation of theoperators.

    Code Generation for the Query : The planned codeis built with the aim of retrieving the result of thequery with high performance.

    Code execution by Database Processor : The

  • 8/6/2019 Database Fundamentals Presentation

    103/132

    14/01/2009 Lord's Kitchen 103

    SELECT column-listFROM table-namesWHERE condition(s)

    ConditionalSelection

    Query ProcessingQuery Processing

  • 8/6/2019 Database Fundamentals Presentation

    104/132

    14/01/2009 Lord's Kitchen 104

    The SQL Select Statement performs three Types of Operations

    SELECT column-listFROMtables-names

    WHEREcondition(s)

    1. Projection

    3. Selection

    2. Join

    Query ProcessingQuery Processing

  • 8/6/2019 Database Fundamentals Presentation

    105/132

    14/01/2009 Lord's Kitchen 105

    Course No. Course_Title C_Hrs. Dept. C

    CIS 120 Intro to CIS 4 Cis

    MKT 333 Intro to Mkting 3 MKT

    ECO 473 Labor Econ. 3 ECO

    BA201 Intro to Stat. 5 ECOCIS 345 Intro to Dbase 4 CIS

    Module

    SELECT Module_Title, C_Hrs FROM Module

    Course_Title C_Hrs.

    Intro to CIS 4

    Intro to Mkting 3

    Labor Econ. 3

    Intro to Stat. 5

    Result Table

    Performing ProjectionPerforming Projection

  • 8/6/2019 Database Fundamentals Presentation

    106/132

    14/01/2009 Lord's Kitchen 106

    Course No. Course T itle C. Hrs.Dep t. C

    CIS 120 Intro to CIS 4 Cis

    M KT 333 Intro to M kting 3 M KT

    ECO 473 Labor Econ. 3 ECOBA201 Intro to Stat. 5 ECO

    CIS 345 Intro to Dbase 4 CIS

    Module

    Course No. Course Title C. Hrs. Dept. C

    CIS 120 Intro to CIS 4 CisCIS 345 Intro to Dbase 4 CIS

    Result Table

    Performing a Selection OperationPerforming a Selection Operation

    SELECT * FROM Module WHERE C_Hrs = 4

    Performing both Projection andPerforming both Projection and

  • 8/6/2019 Database Fundamentals Presentation

    107/132

    14/01/2009 Lord's Kitchen 107

    Course_No Course_Title C_ Hrs. Dept_C

    CIS 120 Intro to CIS 4 CIS

    MKT 333 Intro to Mkting 3 MKT

    ECO 473 Labor Econ. 3 ECO

    BA201 Intro to Stat. 5 ECOCIS 345 Intro to Dbase 4 CIS

    SELECT Module_Title, C_Hrs FROM Module WHERE Dept_C =CIS

    Module

    Course_Title C_ Hrs.

    Intro to CIS 4Intro to Dbase 4

    Result Table

    Performing both Projection andg jSelectionSelection

    Performing both Projection andPerforming both Projection and

  • 8/6/2019 Database Fundamentals Presentation

    108/132

    14/01/2009 Lord's Kitchen 108

    Basic SELECT Statement WHERE Clause OperatorsBasic SELECT Statement WHERE Clause Operators

    =, , = IN (List) WHERE CODE IN (ABC, DEF, HIJ) - would return only rows

    with one of those 3 literal values for the codeattribute

    BETWEEN min_val AND max_val

    WHERE Qty_Ord BETWEEN 5 and 15 - would return rows where Qty_Ord is >= 5 and

  • 8/6/2019 Database Fundamentals Presentation

    109/132

    14/01/2009 Lord's Kitchen 109

    Joining TablesJoining Tables

    Joining TablesTo appropriately join tables, the tables must be

    related and we apply a where clause which equatesthe primary key column of the table on the one sideof the relationship with the parallel foreign keycolumn of the many side table. This type of join is called an Equi-join. Our example will join Modules and departments where

    dept code is the linking key column.

    The next series of slides takes you through a step bystep process of combining data rows from one tablewith data rows in another table.

    The first slide introduces the SQL Select statementthe shows the join operation and a picture of the

    J i i T blJ i i T bl

  • 8/6/2019 Database Fundamentals Presentation

    110/132

    14/01/2009 Lord's Kitchen 110

    Course_No Course_Title C_Hrs Dept_Code

    CIS 120 Intro to CIS 4 Cis

    MKT 333 Intro to Mkting 3 MKTECO 473 Labor Econ. 3 ECO

    BA201 Intro to Stat. 5 ECO

    CIS 345 Intro to Dbase 4 CIS

    Dept Code Dept name Office#

    MKT Marketing 244CIS Comp. Info. Sys. 302

    ECO Economics 244

    Module

    Department

    SELECT * FROM Module C, department DWHERE D.Dept_Code = C.Dept_Code

    SQL will compare every row of the1st table with the first row of the 2ndtable. Then it will compare all rows of

    the 1st with the second row of the second,and so on only rows where the condition

    is met are placed in the result table.

    Joining TablesJoining TablesJoining Two Tables - Select and Tables

    J i i T blJ i i T bl

  • 8/6/2019 Database Fundamentals Presentation

    111/132

    14/01/2009 Lord's Kitchen 111

    Course_No Course_Title C_Hrs Dept_Code

    CIS 120 Intro to CIS 4 CIS

    MKT 333 Intro to Mkting 3 MKT

    ECO 473 Labor Econ. 3 ECOBA201 Intro to Stat. 5 ECO

    n ro o ase

    Dept Code Dept name Office#

    MKT Marketing 244

    CIS Comp. Info. Sys. 302

    ECO Economics 244

    ModuleDepartment

    SELECT * FROM Module C, department D WHERE D.Dept_Code = C.Dept_Code

    Course_No Course_Title C_Hrs Dept_Code Dept_Name Office#

    RESULT TABLE

    No match so row notplaced in results

    Joining TablesJoining TablesJoining Two Tables - Row 1 Module to Row 1 Dept

  • 8/6/2019 Database Fundamentals Presentation

    112/132

    J i i T blJ i i g T bl

  • 8/6/2019 Database Fundamentals Presentation

    113/132

    14/01/2009 Lord's Kitchen 113

    Course _No Course _Title C_Hrs De pt_Code

    CIS 120 Intro to CIS 4 Cis

    MKT 333 Intro to M kting 3 MKT

    ECO 473 Labor Econ. 3 ECO

    BA201 Intro to Stat. 5 ECO

    ntro to aseDept Code Dept name Office#

    MKT Marketing 244

    CIS Comp. Info. Sys. 302

    ECO Economics 244

    Module

    Department

    SELECT * FROM Module C, department D WHERE D.Dept_Code = C.Dept_Code

    Course_No Course_Title C_Hrs Dept_Code Dept_Name Office#

    CIS 120 Intro to CIS 4 Cis Comp. Info S 302

    RESULT TABLE

    Joining Two Tables - Row 1 Module to Row 3 Dept

    Joining TablesJoining Tables

    5 0 Internal Management5 0 Internal Management

  • 8/6/2019 Database Fundamentals Presentation

    114/132

    14/01/2009 Lord's Kitchen 114

    5.0 Internal Management5.0 Internal Management

    Learning Objective After completing this topic you will be able to :

    Describe the various components of the computer systemthat provide data storage facilities to a DBMS

    Understand how DBMS communicates with the host systemOutline some of the database tuning factors

    Computer file management andComputer file management and

  • 8/6/2019 Database Fundamentals Presentation

    115/132

    14/01/2009 Lord's Kitchen 115

    DBMSDBMS Computer files are stored in external media such as disks and tapes.

    Direct access Sequential access

    Input output of data and memory management is managed by theOperating system File manager Disk manager

    DBMS

    File Request

    File Manager

    LogicalPage Req. Disk Manager

    PhysicalPage Access

    DBMS/Host inter-com

    IntercommunicationIntercommunication

  • 8/6/2019 Database Fundamentals Presentation

    116/132

    14/01/2009 Lord's Kitchen 116

    IntercommunicationIntercommunication

    DBMS/Host communication : A file is a collection of pages. A page is a unit of Input

    Output.

    The DBMS sends a file request to the file manager.

    The file manager has no idea where the requested page isphysically stored.

    The file manager in turn communicates with the disk

    manager.

    The file manager provides the database system with the

    given page.

    The database system converts the same into a logical form as

    understandable by the user.

    Tuning at the internal levelTuning at the internal level

  • 8/6/2019 Database Fundamentals Presentation

    117/132

    14/01/2009 Lord's Kitchen 117

    Tuning at the internal levelTuning at the internal level

    Indexes Database indexes are important means of speeding up access

    to set of records. Especially in a relational database. Index is very useful in existence tests.Once a index is created it is transparent to the user.

    HashingHashing is directly determining a page address for a given

    record without the overhead of creating indexes. The main problem associated with hashing are overflow &

    underflow.Clusters

    Physically storing related pages in the form of intra file

    subsets. Inter file clustering to store records from distributed

    databases in the same physical page.

    Internal Management : S mmarInternal Management : Summary

  • 8/6/2019 Database Fundamentals Presentation

    118/132

    14/01/2009 Lord's Kitchen 118

    Internal Management : SummaryInternal Management : Summary

    Database files are stored in logical page sets.The underlying physical files that store a database need not

    map to the logical representation of the DBMS.

    Indexes are useful means of speeding up data access in large

    databases . They incur overheads.

    Hashed functions speed up individual record access, however

    has overflow & underflow problems.

    Intra and inter file clustering of the physical records speed

    up certain operations at the cost of other types of data

    manipulations.

    6 0 Database Trends6 0 Database Trends

  • 8/6/2019 Database Fundamentals Presentation

    119/132

    14/01/2009 Lord's Kitchen 119

    6.0 Database Trends6.0 Database Trends

    Learning Objective At the end of this Topic you will be :

    Familiar with various terms like

    OLAP

    Data warehousing Data mining

    Aware of the business needs that require data to

    be analyzed in multiple dimensions

    Multidimensional Data AnalysisMultidimensional Data Analysis

  • 8/6/2019 Database Fundamentals Presentation

    120/132

    14/01/2009 Lord's Kitchen 120

    Multidimensional Data AnalysisMultidimensional Data AnalysisOn-line analytical processing (OLAP)

    Multidimensional data analysis

    Supports manipulation and analysis of large

    volumes of data from multiple

    dimensions/perspectives

    Types of databases

  • 8/6/2019 Database Fundamentals Presentation

    121/132

    Lord's Kitchen

    Major Types of DatabasesMajor Types of Databases

    c e n t r a d i s t r i b n e t w o

    D a t a

    Centralized databaseCentralized database

  • 8/6/2019 Database Fundamentals Presentation

    122/132

    14/01/2009 Lord's Kitchen 122

    Centralized databaseCentralized databaseUsed by single central processor or multiple processors in client/server network

    CPU DiskController

    PrinterController

    Tape driveController

    Memory Controller

    Memory

    disk printerTape Drive

    System bus

    Distributed databaseDistributed database

  • 8/6/2019 Database Fundamentals Presentation

    123/132

    14/01/2009 Lord's Kitchen 123

    Distributed databaseDistributed database

    Stored in more than one physical locationPartitioned database

    Duplicated database

    Multidimensional data model

  • 8/6/2019 Database Fundamentals Presentation

    124/132

    14/01/2009 Lord's Kitchen 124

    On-line analytical processing (OLAP)Multidimensional data analysis

    Supports manipulation and analysis of large volumes of

    data from multiple dimensions/perspectives

    Data warehouse

  • 8/6/2019 Database Fundamentals Presentation

    125/132

    14/01/2009 Lord's Kitchen 125

    Supports reporting and query tools

    Stores current and historical data Consolidates data for management analysis and decision making

    Data warehouse

  • 8/6/2019 Database Fundamentals Presentation

    126/132

    14/01/2009 Lord's Kitchen 126

    Data mart

    Subset of data warehouse

    Contains summarized or highly focused portion of data

    for a specified function or group of users

    Data miningTools for analyzing large pools of data

    Find hidden patterns and infer rules to predict trends

    Databases and the web

  • 8/6/2019 Database Fundamentals Presentation

    127/132

    14/01/2009 Lord's Kitchen 127

    Hypermedia database

    Organizes data as network of nodes

    Links nodes in pattern specified by user

    Supports text, graphic, sound, video and executable

    programs

    Databases and the web

  • 8/6/2019 Database Fundamentals Presentation

    128/132

    14/01/2009 Lord's Kitchen 128

    Database server

    Computer in a client/server environment runs a DBMS to process

    SQL statements and perform database management tasks

    Application server

    Software handling all application operations

    Database Trends : SummaryDatabase Trends : Summary

  • 8/6/2019 Database Fundamentals Presentation

    129/132

    14/01/2009 Lord's Kitchen 129

    Database Trends : SummaryDatabase Trends : Summary

    The database forms the backend for any kind ofapplication architecture be it a client server,

    distributed system such as the web etc.

    Users want to see data in as many dimensionspossible, therefore it is important to be aware

    of concepts regarding Data warehousing , Data

    mining and On-line analytical processing (OLAP)

  • 8/6/2019 Database Fundamentals Presentation

    130/132

    14/01/2009 Lord's Kitchen 130

    a a ase un amen a s: exa a ase un amen a s: exStepStep

  • 8/6/2019 Database Fundamentals Presentation

    131/132

    ResourceType

    Description Reference Topic or Topic

    Book Case*Method: Entity RelationshipModeling - Richard Barker

    Book Data & Databases Joe Celko

    Book An Introduction to Database Systems C. J. Date

    Book The Data Modeling Handbook -Reingruber and GregoryBook Data Modeling for Information

    Professionals Bob SchmidtBook Data Model Patterns David C. Hay,

    Richard Barker

  • 8/6/2019 Database Fundamentals Presentation

    132/132

    Congratulations!Congratulations!You have successfully completedYou have successfully completed

    DatabaseFundamentals