CSE1IS Information Systems
Tutorial - Week 7
Sorting, Querying & Modifying Database Tables

La Trobe University, Bendigo campus Department of Computer Science

		and Computer Engineering
 

Run MS-Access, select Open from the File menu, find the directory you saved the studrec database in and load it into Access.

Note: you may be able load directly from the list of most recently accessed databases which is displayed at the bottom of the file menu.

Sorting records in a database table

To sort the records in a database table on a single field

Exercise:
Sort the Student table by tute_no (descending)
Sort the Student table by stud_surname (ascending)

To sort records on more than one field you can create and apply a filter/sort. For example


Using Queries

A database query is powerful feature that allows the developer to design specific views of the data stored in the system. These views (queries) may restrict fields that are displayed, may sort records in a particular way, may restrict which records are seen and might contain data from more than one table. Queries can be saved and activated whenever required, and can form the basis for screens and reports.

Building queries is very similar to the creation of a filter/sort introduced in the previous section.

  1. Construct a query, StudentTutListQRY, based on the Student table that lists all students alphabetically into tutorial groups. The steps to construct this table are:
  2. Construct a query, FullTutorialListQRY, which lists all students in alphabetical order and shows their tutorial groups and tutorial times. This query is based on both tables.
  3. Construct queries (StudentTut2ListQRY, StudentTut3ListQRY and StudentTut4ListQRY) to provide tutorial listings for each tutorial group.
  4. Construct a query which lists all students in stud_id order which shows the student's id number, surname, givenname and tutor number. Call this FullTutorialList2QRY.

Modifying the Tables

It may be that changes need to be made to the table structures after they have been defined. eg. adding a new field, deleting an existing field, changing the datatype of a field, etc.

Warning:
All decisions about the structure of the tables (fields, datatypes, key identifiers, relationships etc) should be made before the tables are specified and certainly before any data is entered or the relationships specified. If you make changes to key fields and validation rules these may not be reflected in some of the already created objects such as screens, reports and exsiting relationships.

This is why we insist that you design before you implement!

In the following exercise you will add a new field, gender, to the Student table, add a validation rule and some validation text to provide feedback during data entry.

To test this, open the Student datasheet and enter either 1 (for male) and 2 (for female) for each record. See what happens if you enter a number other than 1 or 2.


In this next exercise you will use a list box to choose available tute_rooms for the tutorials.

To test this, open the Tutorial datasheet and then place the cursor in any of the tute_room data entry fields. ie. Use the scroll option to now change the tute_room with ease without typing them in from scratch!!


Valid XHTML 1.0 Transitional