Hodder Advanced Databases

Embed Size (px)

Citation preview

  • 8/4/2019 Hodder Advanced Databases

    1/21

    A Level Computing for AQA Teachers Resource CD-ROM

    41CHAPTER:

    Advanced database

    concepts

  • 8/4/2019 Hodder Advanced Databases

    2/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Syllabus

    Explain the purpose of a database management system

    (DBMS), query languages and data dictionaries.

    Describe the advantages of different users having different

    views of the data in a database.

    Discuss different approaches to database security. Recognisethat the individual user of a database may be prevented from

    accessing particular elements of the information.

    Explain the role of the database administrator.

    Explain what is meant by data warehousing and data mining,

    using examples from supermarkets and insurance companies.

  • 8/4/2019 Hodder Advanced Databases

    3/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    SQL

    SQL is a language used to extract data from relational

    databases.

    It is available in various versions and embedded into database

    applications, such as Microsoft Access.

    It performs the same function as a QBE, in that it searches andsorts data.

    When you create a QBE, Access writes the SQL automatically.

    SQL is written in lines of code (like a programming language) to

    extract and sort data from several entities within a relational

    database.

  • 8/4/2019 Hodder Advanced Databases

    4/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    SQL statements

    A typical SQL statement might look like this:

    SELECT CustomerName, Address

    FROM Customer

    WHERE CustomerName = John SmithORDER BY CustomerName DESC

    This statement will extract the customer name and address from

    the Customerentity of all customers called John Smith sorting

    the results in descending order based on the customer name.

  • 8/4/2019 Hodder Advanced Databases

    5/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    SQL commands

    SELECT identifies the attributes that you want to extract. These

    can be from one or more tables.

    FROMindicates the table or tables that the data is to be

    extracted from.

    WHERE is the condition that must be met. These can be complex(using AND/OR) or you may not have any conditions at all.

    ORDER BY indicates the sort order of the extracted data. The

    default is ascending so DESC is added to make it descending.

  • 8/4/2019 Hodder Advanced Databases

    6/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Further examples

    SELECT *

    FROM Customer

    WHERE CustomerName = "John Smith" or "Mary Jones"

    will extract all attributes (because the wildcard * is used) fromthe customer entity where the name is either John Smith or

    Mary Brown.

    SELECT *

    FROM VIDEO

    WHERE VideoPrice BETWEEN 2 AND 2.50

    will extract all attributes from the video table where the price of

    the video is between 2 and 2.50.

  • 8/4/2019 Hodder Advanced Databases

    7/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Querying more than one entity

    A more useful query would be to extract the names and

    addresses of all customers with an overdue video, along with

    the name of the video and the date it was taken out.

    These customers can then be contacted to remind them to bring

    it back. For example, the extracted data could be used togenerate a report or mail merged with a reminder letter.

    This process will involve querying all three entities.

  • 8/4/2019 Hodder Advanced Databases

    8/21

  • 8/4/2019 Hodder Advanced Databases

    9/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    The data to be queried: VIDEO

    VideoID VideoName Genre AgeClassification Price

    1000 Titanic Drama 12 2.00

    1001 Matrix Sci-fi 15 2.50

    1002 Training Day Action 18 3.00

    1003 Star Wars Sci-fi 12 2.00

    1004 Pearl Harbour Action 15 2.50

  • 8/4/2019 Hodder Advanced Databases

    10/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    The data to be queried: RENTAL

    RentalID DateHired CustomerID VideoHired OverdueYN

    0001 19/03/03 2000 1000 Y

    0002 19/03/03 2000 1001 Y

    0003 19/03/03 2000 1001 N

    0004 19/03/03 2001 1002 Y

    0005 19/03/03 2001 1003 N

    0006 19/03/03 2002 1004 N

  • 8/4/2019 Hodder Advanced Databases

    11/21

  • 8/4/2019 Hodder Advanced Databases

    12/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Results of the query

    The query would extract the following data:

    CustomerName Address DateHired VideoID VideoName Price

    John Smith 1 High Street 19/03/03 1000 Titanic 2.00

    John Smith 1 High Street 19/03/03 1001 Matrix 2.50Mary Jones 14 Acacia Avenue 19/03/03 1002 Training Day 3.00

    Now work through the SQL question sheet

  • 8/4/2019 Hodder Advanced Databases

    13/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Database management system (DBMS)

    A DBMS is a program that controls:

    the data that is kept on the database

    how it is stored

    where it is stored

    who has access to it.

    Many databases (particularly in large organisations) are

    accessed by many different users for different purposes.

    This can cause problems as different users may alter the data.

    Different users may also need different programs to manipulatethe data.

    If the data changes they have to adjust their programs, which is

    known as unproductive maintenance.

  • 8/4/2019 Hodder Advanced Databases

    14/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    The DBMS layer

    THE DBMS acts as a layer of

    software between all the users

    and the database.

    The following diagram shows

    the concept for a typical

    business.

    All the departments can access

    the data without having direct

    access to the database.

  • 8/4/2019 Hodder Advanced Databases

    15/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Data dictionary

    The DBMS records the structure of the database.

    It records the attributes, data types, validation used and the

    relationship between entities.

    Any changes to the data structure are recorded in the data

    dictionary.

    Any requests to access the data are directed via the data

    dictionary. The DBMS then presents the appropriate table.

    The data dictionary does not store the data itself. It records the

    structure of the data.

    This leads to the concept ofprogram-data independence. Thedata and the programs that are used to access it are not directly

    linked.

  • 8/4/2019 Hodder Advanced Databases

    16/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Controlling the data

    The DBMS controls what data each user is allowed to see.

    For example:

    The finance department may have access to details on

    wages, whereas the training department may have access to

    employment history.

    It also controls what they are allowed to do with the data.

    For example:

    Some departments may be able to see the data, while others

    will have access rights to amend it.

  • 8/4/2019 Hodder Advanced Databases

    17/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Database schema

    There are three views of the database:

    external schema: the way in which the users see the database.

    The complexities of the data are hidden from the user so this

    view is the front-end

    conceptual or logical schema: describes the structurerelationships and the entities and attributes

    internal schema: describes how the data will be stored

    physically and how it will be accessed and updated.

  • 8/4/2019 Hodder Advanced Databases

    18/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Data integrity on a shared database

    Where users are sharing data there is a danger that they could

    attempt to alter data at the same time.

    Multiple users can view data simultaneously but not edit it.

    The DBMS could give access rights to the first user who opens

    a record and read-only rights to any subsequent user.

    This means that the record is locked until the first user has

    finished editing it.

  • 8/4/2019 Hodder Advanced Databases

    19/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Database servers

    In a network, a dedicated server may hold the database.

    Access to the database therefore is via this server and all

    changes made to the database are made on the copy stored on

    the server.

    On a traditional network, the server would store the databaseand send it to the workstation when a user requested it.

    The integrity of the data is maintained with a database server as

    there is only ever one copy.

  • 8/4/2019 Hodder Advanced Databases

    20/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Database administrator

    The database administratoris the person responsible for

    maintaining the database, including...

    designing the database

    keeping users informed of changes

    maintenance of the data dictionary for the database

    implementing database security measures

    allocating passwords

    providing training to users

    ensuring adequate backup procedures.

  • 8/4/2019 Hodder Advanced Databases

    21/21

    A Level Computing for AQA Teachers Resource CD-ROM

    2005 Bob Reeves, Dave Fogg/Hodder Murray

    Home work

    Research and write a at least 1 paragraph on the following

    subjects:

    Data warehousing

    Data mining

    using examples from supermarkets and insurance companies.

    Prepare for end of sub-unit test