Sei sulla pagina 1di 21

A Level Computing for AQA Teachers Resource CD-ROM

CHAPTER: Advanced database concepts

41

A Level Computing for AQA Teachers Resource CD-ROM

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. Recognise that 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.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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 and sorts 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.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

SQL statements
 A typical SQL statement might look like this:
SELECT CustomerName, Address FROM Customer WHERE CustomerName = John Smith ORDER BY CustomerName DESC

 This statement will extract the customer name and address from the Customer entity of all customers called John Smith sorting the results in descending order based on the customer name.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

SQL commands
 SELECT identifies the attributes that you want to extract. These can be from one or more tables.  FROM indicates 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.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

Further examples
SELECT * FROM Customer WHERE CustomerName = "John Smith" or "Mary Jones"

 will extract all attributes (because the wildcard * is used) from the 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.
2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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 to generate a report or mail merged with a reminder letter.  This process will involve querying all three entities.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

The data to be queried: CUSTOMER


CustomerID 2000 2001 2002 CustomerName John Smith Mary Jones John Smith Address 1 High Street 14 Acacia Avenue 23 Maple Drive PhoneNumber 01555 354354 01555 564333 01555 653535 DateOfBirth 30/03/67 23/04/78 23/08/72

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

The data to be queried: VIDEO


VideoID 1000 1001 1002 1003 1004 VideoName Titanic Matrix Training Day Star Wars Pearl Harbour Genre Drama Sci-fi Action Sci-fi Action AgeClassification 12 15 18 12 15 Price 2.00 2.50 3.00 2.00 2.50

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

The data to be queried: RENTAL


RentalID 0001 0002 0003 0004 0005 0006 DateHired 19/03/03 19/03/03 19/03/03 19/03/03 19/03/03 19/03/03 CustomerID 2000 2000 2000 2001 2001 2002 VideoHired 1000 1001 1001 1002 1003 1004 OverdueYN Y Y N Y N N

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

Running the query


SELECT Customer.CustomerName, Customer Address, Rental.DateHired, Rental.VideoHired, Video.VideoName, Video.Price FROM Customer, Rental, Video WHERE Rental.Overdue Y/N = "Y" ORDER BY Customer.CustomerName

 Note the convention Customer.CustomerName to extract the attributes. The entity name is also given in this case as there are several entities being queried.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

Results of the query


 The query would extract the following data:
CustomerName John Smith John Smith Mary Jones Address 1 High Street 1 High Street DateHired 19/03/03 19/03/03 VideoID 1000 1001 1002 VideoName Titanic Matrix Training Day Price 2.00 2.50 3.00

14 Acacia Avenue 19/03/03

Now work through the SQL question sheet

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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 manipulate the data.  If the data changes they have to adjust their programs, which is known as unproductive maintenance.
2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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 of program-data independence. The data and the programs that are used to access it are not directly linked.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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 structure relationships and the entities and attributes  internal schema: describes how the data will be stored physically and how it will be accessed and updated.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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 database and 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.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

Database administrator
 The database administrator is 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.

2005 Bob Reeves, Dave Fogg/Hodder Murray

A Level Computing for AQA Teachers Resource CD-ROM

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

2005 Bob Reeves, Dave Fogg/Hodder Murray

Potrebbero piacerti anche