Chap 1 Intro to Db

download Chap 1 Intro to Db

of 39

Transcript of Chap 1 Intro to Db

  • 8/13/2019 Chap 1 Intro to Db

    1/39

    1

    MIST811: Week 3 1

    Week 3: Introduction to Databases

    The database is the underlying

    framework of the information system.

    Relational Database Management

    Systems (DBMSs) is the predominant

    system for business applications at

    present.

    MIST811: Week 3 2

    3.1 Introduction

    A database is a collection of related data.

    The Database Management System (DBMS) is thesoftware that manages and controls access to thedatabase.

    A database application is a program that interactswith the database at some point of its execution.

    The database system is a collection of applicationprograms that interact with the database along withthe DBMS and the database itself.

    More accurate definitions will be provided later.

  • 8/13/2019 Chap 1 Intro to Db

    2/39

    2

    MIST811: Week 3 3

    Examples

    Purchases from a supermarket

    Bar code reader to scan each purchase.

    Bar code reader is linked to an application program thatuses the bar code to find out the price of the item from aproduct database.

    This program reduces the number of such items in stockand displays the price on the cash register.

    If the reorder level falls below a specified threshold, thedatabase system may automatically place an order toobtain more stocks of that item.

    MIST811: Week 3 4

    Examples ctd

    Purchases using your credit card

    Assistant normally checks you have sufficient credit left tomake the purchase. This can be done on the telephone ormay be done automatically by a card reader linked to acomputer system.

    There is a database somewhere that contains informationabout the purchases you have made on your credit card.

    To check your credit there is a database applicationprogram that uses your credit card number to check thatthe price of the goods you wish to buy together with thesum of the purchases you have already made this billingperiod is within your credit limit.

  • 8/13/2019 Chap 1 Intro to Db

    3/39

    3

    MIST811: Week 3 5

    Credit card example ctd

    After confirmation of the purchase the details of

    the purchase are added to this database.

    The application program also accesses the

    database to check that the credit card is not on a

    list of stolen credit cards before authorising the

    purchase.

    There are other application programs to send outmonthly statements to each credit card holder

    and to credit accounts when payment is received.

    MIST811: Week 3 6

    Examples ctd

    Booking a holiday using a travel agency

    When you make enquiries about a holiday, the travel agentmay access several databases containing holiday andflight details.

    When you book the holiday, the database system has tomake all the necessary booking arrangements.

    The system has to ensure that two different agents do notbook the same holiday or overbook the seats on a flight.

    The travel agent may have another, usually separate,database for invoicing.

  • 8/13/2019 Chap 1 Intro to Db

    4/39

  • 8/13/2019 Chap 1 Intro to Db

    5/39

    5

    MIST811: Week 3 9

    When does the manual f iling system

    break down?

    The manual filing system breaks downwhen we have to cross-reference orprocess information in the files.

    Example:A typical real estate agentsoffice might have a separate file for

    each property for sale or rent, eachpotential buyer and renter, and eachmember of staff.

    MIST811: Week 3 10

    Real Estate Example ctd

    How easy would it be to answer these questions using this set up?

    What three-bedroom properties do you have for sale with a gardenand garage?

    What flats do you have for rent within three kilometres of the citycentre?

    What is the average rent for a two-bedroom flat? What is the total annual salary bill for staff?

    How does last months turnover compare with the projected figurefor this month?

    What is the expected monthly turnover for next financial year?

  • 8/13/2019 Chap 1 Intro to Db

    6/39

    6

    MIST811: Week 3 11

    Real Estate Example ctd

    The file-based system was developed in

    response to the needs of industry for more

    efficient data access. A decentralised approach

    was taken, where each department, with the

    assistance of Data Processing (DP) staff,

    stored and controlled its own data.

    We will illustrate this using the DreamHomeexample which will be outlined on the following

    slides.

    MIST811: Week 3 12

    DreamHome Example

    The Sales Department is responsible

    for selling and renting property.

    The form that landlord has to fill outbefore property is marketed for rent is

    given on next slide.

    This gives details of rental property as

    well as owner (landlord) details.

  • 8/13/2019 Chap 1 Intro to Db

    7/39

    7

    MIST811: Week 3 13

    Figure 3.1

    Sales Department

    forms:

    (a) Property for

    Rent Details form

    MIST811: Week 3 14

    DreamHome Example ctd

    - Sales Department

    also handles

    enquiries from

    clients (renters)

    Figure 3.1 ctd

    (b) Client Details

    form.

  • 8/13/2019 Chap 1 Intro to Db

    8/39

    8

    MIST811: Week 3 15

    DreamHome Example ctd

    With assistance of Data Processing (DP)

    Department, Sales Department creates an

    information system to handle renting the

    property

    This consists of three files containing property, owner,

    and client details (see next slide)

    For simplicity details relating to staff members, branchoffices and business owners are omitted.

    MIST811: Week 3 16

    Figure 3.2 Sales files used

    PropertyForRent

    PrivateOwner

  • 8/13/2019 Chap 1 Intro to Db

    9/39

    9

    MIST811: Week 3 17

    Figure 3.2 Sales files used ctd

    PrivateOwner

    Client

    MIST811: Week 3 18

    DreamHome Example ctd

    Contracts Department is responsible for

    rental agreements.

    Whenever a client agrees to rent a

    property a form is filled out by one of the

    Sales staff (see next slide) which is

    passed to the Contracts Department which

    allocates a lease number and completes

    the payment and rental period details.

  • 8/13/2019 Chap 1 Intro to Db

    10/39

    10

    MIST811: Week 3 19

    Figure 3.3

    Lease

    Details

    form

    used by

    Contracts

    Dept.

    MIST811: Week 3 20

    DreamHome Example ctd

    With assistance from the Data Processing

    (DP) Department the Contracts

    Department creates an information system

    to handle lease agreements. This consists of three files containing lease,

    property, and client details (see next slide)

    The data is similar to that held by the Sales

    Department.

  • 8/13/2019 Chap 1 Intro to Db

    11/39

    11

    MIST811: Week 3 21

    Figure 3.4

    Lease file

    PropertyForRent file

    MIST811: Week 3 22

    Figure 3.4 ctd

    Client file

    Lease file

  • 8/13/2019 Chap 1 Intro to Db

    12/39

    12

    MIST811: Week 3 23

    DreamHome Example ctd

    Figure 3.5 illustrates the situation.

    Each department accesses their own filesthrough applications programs written speciallyfor them.

    Each set of application programs handles dataentry, file maintenance, and the generation of afixed set of specific reports.

    The physical structure and storage of the datafiles and records are defined in the applicationcode.

    MIST811: Week 3 24

    Figure 3.5 File-based processing

    Sales Files

    PropertForRent (propertyNo, street, city, postcode, type, rooms,rent, ownerNo)

    PrivateOwner(ownerNo, fName, lName, address, telNo)

    Client (clientNo, fName, lName, address, telNo, prefType,maxRent)

  • 8/13/2019 Chap 1 Intro to Db

    13/39

    13

    MIST811: Week 3 25

    Figure 3.5 ctd

    Contract Files

    Lease (leaseNo, propertyNo, clientNo, rent, paymentMethod,deposit, paid, rentStart, rentFinish, duration)

    PropertyForRent (propertyNo, street, city, postcode, rent)

    Client (clientNo, fName, lName, address, telNo)

    MIST811: Week 3 26

    DreamHome Example ctd

    There is a significant amount of

    duplication of data in the two

    departments.

    This duplication of data is generally

    true of file-based systems.

  • 8/13/2019 Chap 1 Intro to Db

    14/39

    14

    MIST811: Week 3 27

    Terminology used in file-based

    systems

    A file is simply a collection of records,

    which contain logically related data.

    Each record contains a logically

    connected set of one or more fields,

    where each field represents some

    characteristics of the real-world objectthat is being modelled.

    MIST811: Week 3 28

    3.2.2 Limitations of the File-Based

    Approach

    Separation and isolation of data

    It is more difficult to access data that

    should be available when the data isisolated in separate files.

    The difficulty is compounded if we

    required data from more than two files.

  • 8/13/2019 Chap 1 Intro to Db

    15/39

    15

    MIST811: Week 3 29

    Limitations of file-based systems ctd

    Duplication of data

    Uncontrolled duplication of data is undesirable

    It is wasteful. It costs time and money to enterthe data more than once.

    It takes up additional storage space which hascosts attached. Often duplication can be avoided

    by sharing files. Duplication can lead to loss of data integrity; the

    data is no longer consistent.

    MIST811: Week 3 30

    Limitations of file-based systems ctd

    Data dependence

    The physical structure and storage of

    the data files and records are definedin the application code. Making

    changes to an existing structure is

    difficult.

  • 8/13/2019 Chap 1 Intro to Db

    16/39

  • 8/13/2019 Chap 1 Intro to Db

    17/39

    17

    MIST811: Week 3 33

    Limitations of file-based systems ctd

    In other organisations there was aproliferation of files and applicationprograms.

    Eventually the DP Department with its currentresources could not handle all the work.

    The pressure put on DP staff resulted inprograms that were inadequate or inefficient inmeeting the demand of the users, had limiteddocumentation, and maintenance that wasdifficult.

    MIST811: Week 3 34

    Limitations of file-based systems ctd

    Certain types of data functionality were

    often sacrificed:

    no prevision for security or integrity,

    In the event of hardware or software failure

    recovery was limited or non-existent,

    no provision for shared access, access to

    files was restricted to one user at a time.

  • 8/13/2019 Chap 1 Intro to Db

    18/39

    18

    MIST811: Week 3 35

    3.3 Database Approach

    The limitations of the file-based approach

    can be attributed to two factors:

    1. The definition of the data is embedded in the

    applications program, rather than being stored

    separately and independently;

    2. There is no control over the access and

    manipulation of data beyond that imposed bythe applications programs.

    MIST811: Week 3 36

    The database

    The database and the Database ManagementSystem (DBMS) were developed to overcome theselimitations.

    DEFN: The database is a shared collection of

    logically related data, and a description of this data,designed to meet the information needs of anorganisation.

    The database is a single, possibly large, repositoryof data that can be used simultaneously by manydepartments and users, All data items are integratedwith a minimum amount of duplication.

  • 8/13/2019 Chap 1 Intro to Db

    19/39

    19

    MIST811: Week 3 37

    The database ctd

    The database is a shared corporate resource.

    The database holds not only the organisationsoperational data but also a description of the data.For this reason, a database is also defined as a self-describing collection of integrated records. Thedescription of the data is known as the systemcatalog (or data dictionary or metadata the`data about the data). It is the self-describing natureof a database that provides program-dataindependence.

    MIST811: Week 3 38

    The database ctd

    The database approach separates the structure ofthe data from the application programs and stores itin the database. If the new data structures areadded or existing structures are modified then the

    application programs are unaffected, provided theydo not directly depend upon what has beenmodified.

    If we add a new field or record or create a new file, existingapplications are unaffected.

    If we remove a field from a file that an application programuses, then that application program is affected by thischange and must be modified accordingly.

  • 8/13/2019 Chap 1 Intro to Db

    20/39

    20

    MIST811: Week 3 39

    Some more definitions

    An entity is a distinct object (a person,place, thing, concept, or event) in theorganisation that is to represented in thedatabase.

    An attribute is a property that describessome aspect of the object that we wish to

    record. A relationship is an association between

    entities.

    MIST811: Week 3 40

    DreamHome Case Study

    Figure 3.6 Example Entity Relationship (ER) Diagram for

    part of the DreamHome

  • 8/13/2019 Chap 1 Intro to Db

    21/39

    21

    MIST811: Week 3 41

    DreamHome Case Study ctd

    Figure 3.6 consists of:

    Six entities (rectangles): Branch, Staff,PropertyForRent, Client, PrivateOwner, andLease;

    Seven relationships (the names adjacent to thelines): Has, Offers, Oversees, Views, Owns,LeasedBy, and Holds;

    Six attributes, one for each entity: branchNo,staffNo, propertyNo, clientNo, ownerNo, andleaseNo.

    MIST811: Week 3 42

    DreamHome Case Study ctd

    The database represents the entities,

    the attributes, and the logical

    relationships between the entities.

    That is, the database holds data that islogically related.

  • 8/13/2019 Chap 1 Intro to Db

    22/39

    22

    MIST811: Week 3 43

    3.3.2 The Database Management

    System (DBMS)

    DEFN: The Database ManagementSystem (DBMS) is a software systemthat enables users to define, create,maintain, and control access to thedatabase.

    The DBMS is the software thatinteracts with the users applicationprograms and the database.

    MIST811: Week 3 44

    DBMS ctd

    A DBMS usually provides the followingfacilities

    It allows users to define the database,usually through a Data DefinitionLanguage (DDL). The DDL allowsusers to specify the data types andstructures and the constraints on thedata to be stored in the database.

  • 8/13/2019 Chap 1 Intro to Db

    23/39

    23

    MIST811: Week 3 45

    DBMS ctd

    It allows users to insert, update, delete, and

    retrieve data from the database, usually

    through a Data Manipulation Language(DML). Having a central repository for all

    data and data descriptions allows the DML

    to provide a general inquiry facility to this

    data, called a query language. The mostcommon query language is the Structured

    Query Language (SQL).

    MIST811: Week 3 46

    DBMS ctd

    It provides access to the database. Itmay provide

    A security system which preventsunauthorized users accessing thedatabase;

    An integrity system which maintainsconsistency of stored data;

  • 8/13/2019 Chap 1 Intro to Db

    24/39

    24

    MIST811: Week 3 47

    DBMS ctd

    A concurrency system which allows

    shared access to the database;

    A recovery system which restores the

    database to a previous consistent state

    following a hardware or software failure;

    A user-accessible catalogue whichcontains descriptions of the data in the

    database.

    MIST811: Week 3 48

    DBMS ctd

    DEFN: TheApplication Program is a computerprogram that interacts with the database byissuing an appropriate request (typically an SQLstatement) to the DBMS.

    Users interact with the database through anumber of application programs that are usedto create and maintain the database and togenerate information. The application programsmay be written in some programming languageor in some higher-level fourth-generationlanguage.

  • 8/13/2019 Chap 1 Intro to Db

    25/39

    25

    MIST811: Week 3 49

    Figure 3.7

    Pearson Education Limited 1995, 2005

    MIST811: Week 3 50

    Views

    DEFN:A view is some subset of the database. Itallows users to see the data the way they want tosee it.

    Benefits of views:

    Provide a level of security. Can exclude data thatsome users should not see.

    Provide a mechanism to customize theappearance of the database,

    Can present a consistent, unchanging picture ofthe structure of the database even if theunderlying database is changed.

  • 8/13/2019 Chap 1 Intro to Db

    26/39

    26

    MIST811: Week 3 51

    3.3.4 Components of the DBMS

    Environment

    There are five major components:

    hardware, software, data,

    procedures, and people.

    MIST811: Week 3 52

    Hardware

    Needed for DBMS and the applications to run on.

    Can range from a single personal computer, to a singlemainframe, to a network of computers.

    Depends on the organizations requirements and the DBMSused.

    A DBMS requires a minimum amount of main memory anddisk space to run, but this minimum may not give acceptableperformance.

    The frontend is the part of the DBMS that interfaces with theuser. This is called client-serverarchitecture: the backend isthe server and the frontends are the clients.

  • 8/13/2019 Chap 1 Intro to Db

    27/39

    27

    MIST811: Week 3 53

    Software

    Made up of DBMS software and the

    application programs, together with

    operating system, including network

    software if the DBMS is being used over a

    network.

    Application programs may be written using

    a fourth-generation language like SQL

    embedded in a third generation language.

    MIST811: Week 3 54

    Data

    From the end-users point of view data is themost important component of the DBMSenvironment.

    Data is the bridge between the machinecomponents and human components.

    The database contains both the operational dataand the metadata (data about data).

    The structure of the database is called theschema.

  • 8/13/2019 Chap 1 Intro to Db

    28/39

    28

    MIST811: Week 3 55

    Data ctd

    Figure 3.7 on earlier slide is a schemaconsisting of four files (or tables):PropertyForRent, PrivateOwner, Client, Lease.

    PropertyForRent table has 8 fields or attributes:propertyNo, street, city, postcode, type (the propertytype), rooms (the number of rooms), rent (the monthlyrent), ownerNo.

    ownerNo attribute models the relationship betweenPropertyForRent and PrivateOwner (the owner Ownsthe property for rent), see Figure 3.6.

    MIST811: Week 3 56

    Procedures

    Procedures are instructions and rules that governthe design and use of the database.

    Documented procedures on how to run the systemare required by the users of the system and the staff

    that manage the database. Procedures may consist of instructions on how to:

    log on to the DBMS;

    use a particular DBMS facility or application program;

    start and stop the DBMS;

    change the structure of a table.

  • 8/13/2019 Chap 1 Intro to Db

    29/39

  • 8/13/2019 Chap 1 Intro to Db

    30/39

  • 8/13/2019 Chap 1 Intro to Db

    31/39

  • 8/13/2019 Chap 1 Intro to Db

    32/39

    32

    MIST811: Week 3 63

    3.4 History of Database Management

    Systems

    First-generation (mid 1960s)

    Hierarchical model (e.g. Information ManagementSystem) and network model by IDS (Integrated DataStore).

    Second-generation

    Relational model proposed by E.F. Codd in 1970. SQL isthe standard language for for relational DBMSs.

    Third-generation Object-Oriented

    Object-Relational

    MIST811: Week 3 64

    3.5.1 Advantages of DBMSs

    Control of data redundancy

    Data consistency

    More information from the same amount of data

    Sharing of data

    Improved data integrity

    Improved security

    Enforcement of standards

    Economy of scale

  • 8/13/2019 Chap 1 Intro to Db

    33/39

    33

    MIST811: Week 3 65

    3.5.1 Advantages of DBMSs ctd

    Balance of conflicting requirements

    Improved data accessibility andresponsiveness

    Increased productivity

    Improved maintenance through dataindependence

    Increased concurrency

    Improved backup and recovery services

    MIST811: Week 3 66

    3.5.2 Disadvantages of DBMSs

    Complexity

    Size

    Cost of DBMSs Additional hardware costs

    Cost of conversion

    Performance

    High impact of failure

  • 8/13/2019 Chap 1 Intro to Db

    34/39

    34

    MIST811: Week 3 67

    3.6 The Relational Model

    The Relational Database Management System(RDBMS) is the dominant data-processing softwareused today.

    This software is the second generation of DBMSs and isbased on the relational model of E.F. Codd (1970).

    Codd was trained as a mathematician. Set theory andpredicate logic mainly underpin his model.

    In the relational model, all data is logically structured

    within relations (tables). Each relation has a name and is made up of named

    attributes (columns) of data.

    Each tuple (row) contains one value per attribute.

    MIST811: Week 3 68

    3.6.1 Terminology

    Relation:A relation is a table with columns and rows.

    At tr ibute: An attribute is a named column of a relation.

    Domain:A domain is the set of allowable values for one ormore attributes.

    Tuple:A tuple is a row of a relation.

    Degree: The degree of a relation is the number ofattributes it contains.

    Cardinality: The cardinality of a relation is the number oftuples it contains.

    Relational database:A collection of normalized* relationswith distinct relation names.

    *(More on this in a later lecture.)

  • 8/13/2019 Chap 1 Intro to Db

    35/39

    35

    MIST811: Week 3 69

    Alternative terminology

    FieldColumnAttribute

    RecordRowTuple

    FileTableRelation

    Alternative 2Alternat ive 1Formal terms

    MIST811: Week 3 70

    3.6.2 Relational Keys

    Superkey:An attribute, or set of attributes, that

    uniquely identifies a tuple within a relation.

    Candidate key:A superkey such that no proper

    subset is a superkey within the relation.Primary key: The candidate key that is selected to

    identify tuples uniquely within the relation.

    Foreign key:An attribute, or set of attributes,

    within one relation that matches the candidate

    key of some (possibly the same) relation.

  • 8/13/2019 Chap 1 Intro to Db

    36/39

    36

    MIST811: Week 3 71

    Representing Relational Database

    Schemas

    The common convention is to give the name ofthe relation followed by the attribute names inparenthesis. The primary key is usuallyunderlined.

    (Q2 of the tutorial exercises provides anexample.)

    The conceptual model, or conceptual schema, is

    the set of all such schemas for the database.(Q2 of the tutorial exercises provides anexample.)

    MIST811: Week 3 72

    Integrity Constraints

    Null: Represents a value for an attribute that iscurrently unknown or is not applicable for thistuple.

    Base relation:A named relation corresponding to

    an entity in the conceptual schema, whosetuples are physically stored in the database.

    Entity Integrity: In a base relation, no attribute ofthe primary key can be null.

    Referential Integrity: If a foreign key exists in arelation, either the foreign key value must matcha candidate key value of some tuple in its homerelation or the foreign key must be wholly null.

  • 8/13/2019 Chap 1 Intro to Db

    37/39

    37

    MIST811: Week 3 73

    3.6.3 Views

    View: The dynamic result of one or more relationaloperations operating on the base relations to produceanother relation. A view is a virtual relation that does notnecessarily exist in the database but can be producedupon request by a particular user, at the time of request.

    Views provide a powerful and flexible securitymechanism by hiding parts of the database from certainusers.

    Views permit users to access data in a way that iscustomised to their needs.

    Views can simplify complex operations on the baserelations.

    MIST811: Week 3 74

    Tutorial Exercises for Week 3

    The Wellmeadows Hospital CaseStudy is from DATABASE SYSTEMS

    A Practical Approach to Design,

    Implementation, and Management.,Thomas Connolly & Carolyn Begg(2005), pp. 1260-1267,AddisonWesley.

    This will be handed out in the lecture.

  • 8/13/2019 Chap 1 Intro to Db

    38/39

    38

    MIST811: Week 3 75

    Tutorial Exercises Week 3 ctd

    1. Study the Wellmeadows Hospital Case Studyhand out.

    a) How would a file based approach beimplemented?

    b) In what ways would a DBMS help thisorganisation?

    c) What data can you identify that needs to berepresented in the database?

    d) What relationships exist between the data items?

    MIST811: Week 3 76

    Tutorial Exercises Week 3 ctd

    2. The following tables form part of a database held in a relationalDBMS:

    Hotel (hotelNo, hotelName, city)

    Room (roomNo, hotelNo, type, price)

    Booking (hotelNo, guestNo, dateFrom, dateTo, roomNo)

    Guest (guestNo, guestName, guestAddress)

    where

    Hotel contains hotel details and hotelNo is the primary key;

    Room contains room details for each hotel and (roomNo,hotelNo)forms the primary key;

    Booking contains details of bookings and(hotelNo,guestNo,dateFrom) forms the primary key;

    Guest contains guest details and guestNo is the primary key.

  • 8/13/2019 Chap 1 Intro to Db

    39/39

    MIST811: Week 3 77

    Tutorial Exercises Week 3 ctd

    a) Identify the foreign keys in this schema. Explainhow the entity and referential integrity rules applyto these relations.

    b) Produce some sample tables for these relationsthat observe the relational integrity rules. Suggestsome general constraints that would beappropriate for this schema.

    HOMEWORK: Submit answers to 1a) 1b), 1c), 1d),2a), 2b) to ERIC by 6pm Monday 17 March2008.

    MIST811: Week 3 78

    Readings

    Chapter 1: An Overview of DatabaseManagement inAn Introduction to DatabaseSystems (8th edition), Addison-Wesley, 2004by C. J. Date. (QA76.9.D3 D3659 2004)

    Chapter 1: Introduction to Databases inDATABASE SYSTEMS A Practical Approachto Design, Implementation, and Management(FOURTH EDITION), Addison Wesley, 2005 byThomas Connolly and Carolyn Begg.(QA76.9.D26 C66 2005)