Sunteți pe pagina 1din 22

Database Management Systems

Introduction to Access

What is a database? The general definition of a database is that of being a collection of related data irrespective of the format of the data (i.e. written, electronic, audio, etc). The term database is however often used to mean a collection of related data stored in a computer readable format.

Examples of collection of related data are employee details, stock details, medical histories, library catalogues, etc.

Database Management Systems. When data is stored in a computer some software is needed to present that data to the users in a form with which we work. If we want to add to, edit or retrieve the data then the software must be able to translate our commands into a form the computer can use. This kind of software is called a Database Management System(DBMS). Examples of DBMSs include MS Access, Dbase, Oracle, etc.

Procedure for starting MS Access. Click on the START button. Select Programs Select Microsoft Access. Select Blank Database to create a new database Or Select Open an Existing Database to open an already designed database.

What is an Access database?

Access is a database management system and provides a means of storing and managing data or information. It allows you to relate data from several different sets or tables. Four main components of an Access database are:

Tables Queries Reports Screen forms

Tables Access stores data in tables that are organised by rows and columns. The basic requirement of having a database is that you at least have one table. The columns in the table represent specific details, for example employee name or number. The rows contain the collection of specific details and are known as records.

Queries A query is a question, queries that help users to retrieve a fraction or a subset of the data stored in a computer. For example:

Which employees are in the Finance department? Who are those who were employed before July 1988? Who are the unmarried employees? Etc

Queries are therefore used to select records from a database to answer such questions.

Forms. Screen forms are used to customise the way in which the data from records in tables or queries are displayed on the screen. Their main purpose is to provide a user-friendly interface for the entry of new records or for editing existing ones.

Reports. Reports are used to print information. This may be based on all the data (using a table) or it may be based on a selection of data (using a query). In addition to data from records, they may show summary information relating to the data in the records displayed like subtotals.

Macros

A macro is an automated procedure of action in a computer. It can also be called a mini program because it has short automated procedures, which consists of simple commands. For example, you can use a macro to instruct the computer to print specific reports at a given time.

Ms Access facilitates the incorporation of repetitive tasks into macros for simpler operations and saving time. Modules

Just like macros, modules enable one to automate work processes. They provide more control on the specific commands used. Unlike macros, Ms Access modules need one to have a good background in a programming language and preferably in Microsoft Visual Basic. Rarely do regular users use macros and modules in a simple database.

The Access window The Access window. This window is displayed when you first start MS Access as indicated in the diagram below

Database design

A database should be set up in such a way as to provide information to the person who originally stored the data and also provide information to other users who may not have been involved in the design. It is therefore important that the database designer puts into consideration the needs of the end-users. It is important to include all the relevant particulars at the level of designing and take care of their types, formats, sizes, etc. Database design is effected in tables. The way you design the tables therefore affects the entire database.

Records and fields A set of details about an individual member is known as a record. For each member there is a separate record in the table. Each record is composed of data about the member, such as name, address, date of appointment, etc. Each piece of data within a record is known as a field. Each piece of data within a record needs to be defined before data can be entered into the record.

Fields are given names to describe the kind of data they will eventually hold. The fieldnames can be considered to be the column headings in the table and each row in the table is a separate record. Field sizes and the type of data that they will contain must also be defined.

Choosing data types The first stage in building a database is to define the table, that is, to give the table a name and define the names of the fields that will be contained in each record in the table. The next stage is to define the type of data to be stored in each of the fields. Access needs to know what type of data you intend to enter. The data type that you choose determines the kind and range values that can be entered into it and the amount of storage space available in the field.

The following data types are available in Access

Text: Text and numbers.

By default Access will make a text field 50 alphanumeric


5

characters long. If you know the length of the longest piece of data to be entered into the

field then you can specify this as anything from 1 to 255 characters. Examples of text fields: Names, Addresses, Positions, Departments, Titles, etc.

Number:

Numerical data on which you intend to perform mathematical calculations,

except calculations involving money. Examples of number values: Number of items, number of people, etc.

Auto Number:

These are sequential whole numbers automatically inserted by

Access. You do not need to type the number as it is automatically generated in increments of 1. These numbers cannot be edited and if you later delete a record that number is lost. This data type is used to primarily give uniqueness to each record. Examples: Membership number or a property identification number. Date/Time: Dates and times. A variety of display formats is available, or you can

create your own. Examples: Date of appointment, date of birth, date of delivery, etc.

Currency:

Money. Define a field as currency whenever you expect to enter money

data. Decimals place may be rounded off and a fixed number of decimal places may be specified.

Yes/No:

Yes/No, True/False or On/Off. Examples Smoker/Non-smoker,

Citizen/Non-citizen, etc

Memo:

Lengthy text and number. A memo field can contain up to 64,000

characters. For example, comments about a record, remarks about a students performance, etc. Creating a database.

1. 2. 3.

Click on the Start button Move the cursor to Programs Move to Microsoft Access and click once.

Microsoft Access starts up and presents a dialog box prompting you with options of opening an existing database, database templates and blank database. 4. 5. 6. Select Blank Database Access prompts you to save the database with the File New Database dialog box. In the Filename text-box type the database name UMI Staff Loans database and click on Create.

A blank database called UMI Staff Loans database complete with tables, Queries, Forms, Reports, Macros and Modules is opened in a database window. CREATING A DATABASE TABLE IN MS ACCESS Assuming the UMI staff loans database is already created. 1. Click on the Tables tab and then click on the New button to create a new table. Ms Access displays a New Table dialog box with various options of creating the table. 2. Select design view and click on the OK button. A blank data table structure is displayed with two blank rows. 3. Enter the field names and data types as indicated in the figure above of the data table structure, in their respective columns. To enter data types, click in the data types cell, this will reveal a drop down list box. Click on this box to select the required data type for that field. 4. Enter the field Size or Format specifications located on the General tab located below the table structure. Note that when a field is empty information on the General tab is not visible. But it is displayed immediately you click in the data type column. (Use this in number 4 above for each field). 5. 6. When complete, click on File and select Save As to save the table structure. In the Save As dialog box displayed, select within the current database as option and in the New Name text box type Staff loans and click on the OK button. Ms Access might prompt you with a no new primary key dialog. You may click the Yes button to automatically create one or ignore.

7.

8.

Click on File and select Close to complete the table structure design. A new table is complete and ready for data entry.

CREATING FORMS IN MS ACCESS In order to be able to enter records properly in a table, a form is designed which will assist in entering data properly in the table. To create a form follow the steps below: (assume the above data table) 1. 2. 3. 4. Click on create Choose More Forms From the options given select Form Wizard Click on the >> (double arrow) button to move all the fields in the Available Fields box to the Selected Fields box. Click on the Next button to proceed. At this stage the form wizard asks you to select the type of layout that you like for the form. 6. Click on Columnar layout and click on the Next button to continue. The Form Wizard now displays a list of various styles for you to make a choice. 7. Select the style and click on the Next button to continue. Finally the Form Wizard requests for an appropriate title for your form. 8. For the title type in Staff Loan Entry form and click on the Finish button. A new standard form will be displayed with details of the first record if there was any entered. The form is now complete and can be used for data entry.

5.

OR
1. 2. 3. 4. 5. 6. Click on create Choose Form The form opens in design view Close the design view by clicking on X You will be prompted to save, you click on yes Name it staff loans entry form
8

Exercise 1. Uganda Management Institute is interested in computerising all information related to staff loans so as to improve on the management of such information.

1. You are required to design a suitable database to manage this information, Name the Database - UMI STAFF LOAN DATABASE. 2. Create a new table using Design View; name the table - Staff Loans, Use the following fieldnames, data types and description shown in the table below to guide you in creating the table : Note: Select the ID fieldname as a Primary Key

Field names ID Surname Other name Sex Job Title Marital Status Phone Date of Recruit Amount Experience

Data Type Text (4) Text (10) Text (10) Text (6) Text (12) Text (9) Text (11) Date/Time (short date) Currency with 0 decimal places Number

Description Please enter Staff Identification Number

Please enter day, months and then year

3. Create a form called Staff Loan Entry form and use it to enter the records in the table below:

UMI STAFF LOAN DATABASE.


ID E025 E035 E045 E078 E090 E105 E111 E115 E116 E117 E118 E119 E120 E125 E133 E134 E135 E152 E156 E234 Surname Kasule Lutta Ahairwe Mukasa Muhwezi Nattabi Muhoozi Namboze Tushabe Nakawesi Rusegere Kawala Okot Okumu Mugira Mugume Achola Akello Alia Mugisha Other name Robert Francis Justine Juliet Jolly Susan James Anne Maria Zanabu Metusera Aisha Gabriel Patrick Zadock Francis Betty Rose George Ziribaberi Sex Male Male Female Female Female Female Male Female Female Female Male Female Male Male Male Male Female Female Male Male Job Title Secretary Technician Programmer Consultant Consultant Consultant Secretary Cleaner Programmer Consultant Secretary Accountant Consultant Consultant Secretary Manager Analyst Accountant Consultant Consultant Marital Status Married Single Single Widowed Divorced Widowed Married Married Single Widowed Married Divorced Married Single Married Single Divorced Divorced Divorced Married
10

Phone 041-259581 041-250974 077-500122 041-259722 077-596286 041-259581 041-250974 077-401060 077-500122 041-259722 041-250974 041-259581 075-659530 041-250974 041-259722 077-402165 041-259722 041-259581 075-650320 075-659530

Date of Recruit 9/8/2001 5/4/1999 9/6/1999 8/5/2001 1/1/2001 9/6/1998 8/7/1999 5/2/2002 9/8/2001 5/4/1999 9/6/1999 8/5/2001 1/1/2001 9/6/1998 8/7/1999 5/2/2002 9/4/1997 5/3/1998 12/12/1999 3/1/19999

Amount 450,000 358,000 752,000 186,000 412,000 600,000 250,000 658,000 365,000 454,000 580,000 248,000 185,000 550,000 450,000 150,000 655,000 450,000 195,000 580,000

Experience 3 5 6 1 2 5 4 7 8 3 6 5 4 2 4 2 3 5 4 6

4.

Create a query displaying only ID, Name, Sex and Amount to filter out only Female employees. Save it as Female Staff loans.

5.

Create a another query displaying only ID, Name, Sex and Amount to filter out only Male employees. Save it as Male Staff loans

6.

Create another query displaying all the fields to display employees with staff loans greater than 400,000

7.

Create a report grouping the records by Job Title using the Staff Loans table, Name it Staff Loans Report by Job Title.

CREATING QUERIES IN MS -ACCESS USAGE: Database programs in general are used to enter huge amounts of information. Once the information has been entered, however, the program must have the capacity to narrow listings down based on criteria that you, the user, provide. Access refers to the process of questioning, selecting and manipulating data as Querying. For example, if you have a table consisting of thousands of company employees you may at some point want to view only those employees working in a given department. The Query would then consist of Access pulling out all records where the department is equal to the one you specify. It is also possible to have Access select only specific fields to view. Using the example above, perhaps your table consists of fifteen fields but you are only interested in seeing the employee names and phone number. You can instruct Access to list only those two fields for all records meeting the department criteria. You must create New queries and then select any/all tables and field(s) you wish included in your query listing. You will then use the Query Form to set your criteria. There are several methods to create a new query depending on your experience level. If you already know how to create a query and are familiar with the various parts of a query, you can go directly to a new design view and begin formulating it. If you need a little help putting together the query, you can access one of the built-in wizards. The database window provides a wizard for a

11

simple query. If you click on the button, Access provides wizards for more advanced queries.

To perform a simple query, follow the steps outlined below: 1. 2. 3. Click on create Choose query wizard Click on the Queries icon. The database window will display any existing queries as well as options for creating new queries. Click on box: to access the following dialog

Select the query type and click . For most of your standard queries, you will select Simple Query Wizard.

Access will display a list of tables and available fields, as shown in the diagram below:

12

Select the table name to work with from the pulldown list located in the upper left corner (which is the section labeled Tables/Queries).

Your next step is to select the fields to be included in the query. Choose fields that should be used for searching purposes (e.g., looking for last names) as well as any fields whose data should be displayed once records have been located. Highlight each field you want to include in the query (from the Available Fields section) and click on . The fields will be placed on the right side of the dialog box (within the section labeled Selected Fields). Click on table. to add all fields from the selected

If you decide to remove a field, select the field (from the Selected Fields section) and then click on . The field will be removed. to remove all fields.

Click on

13

NOTE:

If you want to display fields from more than one table, you will need to choose the fields from one table at a time.

Once the table(s)/fields are selected, choose

. If fields contain numeric data, Access displays this screen:

Use this screen to decide whether the records of the table should be totaled. Use Detail to show each record in a standard tabular list. Use Summary to total, average or count the records. Click on to select calculation options. Keep in mind not all fields (e.g., Cust ID) are appropriate for calculations.

14

Check the option(s) to be calculated. Use Min to display the smallest value and Max to display the largest value within a field. When done, choose . When you return to the

previous screen, click on to continue. Access will now display the final wizard screen, as shown below:

Enter a name for the query in the space provided.

Select whether you wish to Open the query or Modify the query design by selecting the appropriate radio button. If you would like to have Access display help on working with queries, check the box at the bottom of this screen.

When done, click on . Access creates the query (based on your selections) and displays the results.

15

MODIFYING A QUERY Although the wizard can be useful for creating the basic design of a simple query, the query contains no selection criteria and simply displays a list of the entire table. You will need to modify the query design to include the criteria for selecting specific records. If you are viewing the database query, click on From the database window, click on the button. Access will display all of the fields for the selected table in the top portion of the screen but none of the actual data will be seen, as illustrated in the diagram below: .

The top half of the query window contains a list of available tables and their associated fields. The bottom half of the query window lists each field that has been included in the query in a columnar format. If you need to add a field to the query, simply drag the field name (from the top half of the window) to a blank column (in the bottom half of the window). The asterisk (*) can be used to indicate that all fields of a table should be included in the query.

16

The following sections are shown in the bottom half of the screen: Field Used to enter the field name you wish to query. To add a field, click in this section and choose from the pull-down list. You can also drag the field name using the mouse from the table list. To create a query that contains all of the fields, double-click on the title bar of the table. This highlights all fields, which you can then drag to this section. Access will place each field in a separate column. The asterisk (*) includes all current and future fields in the query. Use this to ensure you always have all the latest fields when the query is run. Table If there is more than one table, use this section to specify the table from which the field will be derived. Use this to sort in ascending or descending order. Check this box to actually show the data of the field in the final list. Fields can be used for criteria but do not have to be shown in the resulting dynaset. This is where you actually type in what you are searching for. Be sure to place your criteria in the column of the field that would contain the data. If you are looking for more than one item within the same column, place your criteria on multiple lines.

Sort

Show

Criteria

Or

ADDING CRITERIA Once you have added the fields to view/search, your next step is to specify what condition(s) must be met for records to be displayed. Move to the field where the condition is to be set and enter the criteria. The following operators may be used during a query:
17

= Must be exactly equal to < Must be less than > Must be greater than >= Greater than or equal to <= Must be less than or equal to Example: If you were searching for those employees making more than $40,000.00 you would move to the salary field and enter the following condition: >40000

Once you have entered all your criteria: Click on this button to actually process the query.

The results of the query are stored in a record set. A record set looks similar to a table, but is not a real database table. However, any changes you make to the data in a recordset affect the actual tables from which the records were selected.

Record sets can be saved and/or printed the same way as tables. If you need to make a change to the query, click on the button to return to the query design and change your criteria.

18

CREATING REPORTS IN MS ACCESS

In Ms Access, reports present data for viewing or printing in a meaningful way. The data is arranged according to the user requirements. To create a report, assuming that the UMI staff loan database procedure below: is open follow the

1. 2. 3.

Click on create Click on the Reports wizard. Click on the Table/Query drop down list box and select Staff Loans Table if not yet selected. A list of fields will be displayed in the Available Fields list box.

4.

Click on the >> (Select All) button to transfer all fields in the Available Fields list box to the Selected Fields list box. Click on the first field label No in the Selected Fields list box and click on the < (Remove one) button to remove this field back to the Available Fields list box, and click on the Next button. The No field is removed because it will have little meaning in our report. The Report Wizard will now prompt you to specify any grouping levels. Since we do not want any grouping level click on the Next button to continue. The Report Wizard will now prompt you to specify the fields you want to appear sorted on.

5.

6.

7.

In the First field Sort text box, click on the drop down list box and select the Names field label. This is because we want the names to appear in alphabetical order. Click on the Next button to continue. The report Wizard now displays a list of various report layouts you can choose from.

8.

From the List Select Tabular or Columnar layout and click on the Next button to continue. The report Wizard now displays a lists of various report Styles you can choose from.

9.

Select the Corporate style or any of your choice by clicking on it and then click on the Next button to continue.
19

The report Wizard now displays a text box and prompts you to specify any desired title for the Report.

10.

In the text box type in Staff Loans Report and click on the Finish button to continue. The report Wizard starts creating a report according to the specified details. After setting up the report it displays it and terminates. You can scroll through the report, zoom in and out to admire the design

11.

PRINTING REPORTS If your computer is connected to a printer you can print out a hard copy of the report as follows. 1. Click on the File menu and select the Print command to display the print dialog box. In the Print dialog box click on the OK button to begin printing.

2.

20

SORTING THE DATA

USAGE:

As you work with your data, you may find that the records are not in any particular order. As a result, reading or finding a specific record may be difficult, especially if you have hundreds or thousands of records. Access has an easy way of rearranging/sorting data so that you can print/view the records in the order needed. Before you sort, click anywhere in the field you wish to sort. For example, if you want to sort alphabetically by last names, make sure your cursor is somewhere in that field. Once you have selected the field on which to sort, click on one of the following buttons: Click on this button to sort the records in ascending (alphabetical/lowest to highest) sequence. Click on this button to sort the records in descending (reverse-alphabetical/highest to lowest) sequence.

NOTE:

You can also sort a column by clicking the [RIGHT] mouse button within the column to be sorted and choosing your sort method from the pop-up menu.

SORTING ON MULTIPLE FIELDS To sort on more than one field at a time, you must select all the fields (columns) on which to sort by. Access will sort by the leftmost column first, then by the other selected fields in order from left to right. You may need to move the columns around to get them in the order needed. For example, to sort employees by last name and then by first names, you will need to rearrange the columns so that the first name column comes after the last name column.

21

FILTERING RECORDS

USAGE:

Since a table can be quite large, there may be times when you need to extract records based on specific conditions. Asking Access to list a specific group of records is called filtering. After you create a filter, the program hides all the records that do not match your filter criteria. Although you can use simple filters, you can also use the filter to create more complex sorting options. There are two simple filters that can be used immediately, the selection filter and the form filter.

THE SELECTION FILTER Use this feature to list only those records that match the text you currently have selected. Follow the steps outlined below:

Select the field or part of the field that represents the data you want to display. For example, you could select a city and only those rows containing that city would be displayed. Once you have selected the field or data you wish to work with, click on this button to display only the rows that match the data you selected. Click on this button to remove the filter and display all records again. If you click on this button a second time, the last filter is repeated.

NOTE:

Every time you use this feature, the new selection is added to the previous filter criteria. It is designed to be able to easily select sub-sets, but can also cause a filter not to work at all. Be sure to clear the previous filter before using a new set of criteria.

22

S-ar putea să vă placă și