Documente Academic
Documente Profesional
Documente Cultură
Notes on : DATABASE Design Guidelines and Concepts Using MS Access From the author.
These notes [free of charge] have been placed on the Internet to assist anyone wishing to use Microsoft Access at the introductory and intermediate level. They have, however, been specifically prepared for students taking I.S. (Information Systems MGCR-331, a first year course at McGill University in the Faculty of Management as well as at the Centre for Continuing Education, as well as for a number of practical, hands on, courses on Access. The notes specifically refer to Access, version 2000. However for those with an earlier version, such as the Office 97, Version 7 and 2, these notes should be just as applicable. It is assumed when a newer version of Access is introduced, these notes will be just as applicable. The notes are continually being updated with improvements and or corrections. If you find that you wish to contribute to the content with suggestions for improvements and or corrections, please contact the author below. Again, your comments and suggestions are most welcome! Date Created: Author: E-mail address: February 1996 Date last modified: May 29, 2006 Leo Kerklaan - McGill University - Montreal - PQ - Canada leo.kerklaan@McGill.CA
No part of this work may be reproduced or used in any form or by any means - graphic, electronic, or mechanical, including photocopying, recording, taping, or information storage and retrieval systems without the written permission of the author unless the above is performed exclusively for use in our I.S. courses at McGill or those seminars and courses given by the author.
Notes such as these are under constant review, as such, they may contain any number of spelling errors and or other minor grammatical problems. Your understanding is appreciated. Please bring any corrections and or suggestions to my attention! Thank you!
Page
10/18/2013
Table of content
Table of content : Notes on : Database Concepts and Access Chapter Topic Page No.
1 2 Introduction to database concepts Tables and Database Creating a new database and table Opening an existing database and table Table structure and properties Create, Delete and Change a Primary Key Viewing the contents of a table Printing the content of a table Relationships in Access Establish a relationship Modify, delete and remove a relationship View and print a relationship Short cut keys Querying a table Bringing up the query screen and types of queries Creating a simple, single table query Sorting the data to be displayed Creating a complex query (and / or, IN, between, Like) Calculated field Group by query (includes WHERE clause) Update query User prompt - parameter query Crosstab query Reports Overview Report layouts supported by the Wizard Understanding report layout Creating a report with the Wizard Sample Preview Print Preview Print and printer setup Saving a report Text box controls - Bound and unbound Moving, sizing, copying, and deleting fields Adding new fields to a report Adding text to a report Sorting and grouping in a report Other interesting things you can do in a report Forms
Page 2 10/18/2013
3 5 5 5 6 8 8 10 11 12 13 13 13 15 15 16 17 17 19 20 22 23 24 26 26 26 26 27 29 29 29 30 30 30 31 31 31 32 33
Table of content
Background, how to create, table lookup and multi table Expressions, and Functions
33 to 37 38
Page
10/18/2013
Additional Example: A given employee may use a single personal computer or none at all. Said another way, a given personal computer is used by only one employee and always the same employee (at least as far as the database is concerned). The relationship is 1:1.
Employee
1 One-to-Many
USES
1
Personal Computer
One record in the primary key table may have any number of matching foreign key records. Note: There need not be a matching foreign key record. E.g. an employee may have any number of skills, each identified and stored in an employee skills table (e.g. Lotus, Excel, Access, Pascal etc.). As such, many employees can hold a given skill.
Additional example: A given employee, may use one or more personal computers or the employee may not use any at all. Alternatively, no employee or only one employee can use a given personal computer. The relationship is 1:M.
Employee
USES
Personal Computer
1 M Many-to-Many Two tables are linked, however, neither column represents a primary key. Note: This does not work very well in Access. Note: There need not be matching value records between tables. Page 4 10/18/2013
0Chapter 1 - Database Design and Guidelines 1 e.g. A given player may participate in many games and each game has many players. Additional example: A given employee can use no computer or any number of computers or: No employees or any number of employees can use a given computer. The relationship is M:M.
Employee
M
USES
M
Personal Computer
In addition to assigning primary and foreign keys, each field in the database needs to be defined in terms of a field name, field description, data type (e.g. numeric, text etc.) and properties. The properties for a field may include a variety of things such as rules about the value, the formatting and other display characteristics and indexing.
Page
10/18/2013
0Chapter 1 - Database Design and Guidelines 1 Additionally for a design to be successful, one must also determine how the database will be used and by whom by considering the following. Establish the types of updates and transactions that create and modify the data keeping referential integrity in mind. Determine which fields should have indexes. Suggestion: Always index key fields and those fields that are sorted. Decide on who can access and or modify the data and if required set up a security matrix. Document your design process. Establish backup procedures and off site storage. Develop a contingency plan that will cover any potential disaster.
Data modeling.
Tools are available for designing and then automatically creating the structure of a relational database. Often these use graphic techniques to assist with the E-R diagrams (Entity Relationship). As the theory behind a relational database is founded in a branch of mathematics called set theory. This was expanded upon to include relational algebra. There is a formal process called Normalization that helps determine which data attributes are grouped into tables, which in turn make up a database. The key here is to: Eliminate duplicate tables in tables. Accommodate future changes in tables Minimize the impact on user applications when the database structure is changed. The scope of this and other technical topics is beyond these notes. A good relational database design book should prove invaluable in this area. It should be software independent.
Page
10/18/2013
Creating and Opening, Viewing, Updating and Printing a Table Using MS Access
Loading Access.
From the screen below, either create a new blank Access database or open an existing database file.
Used to open an existing database container. Select the file from the list below or if none is selected turn, on the next panel, select the drive, folder and database file that has to be opened.
Note: You may also use the File Open or File new command to accomplish the same. Access needs the drive, folder and database name to continue. See below.
Use these icons to speed up the location selection! Database name. Note: The default is db? And the extension is always mdb
Once you have selected the drive, folder and database name, click on Create icon.
Page
10/18/2013
yThe following screen is presented. The Objects area indicates you are active in Tables section. To go elsewhere click on the required Object name such as Queries. As this was a new database, no existing tbales, queries, Reports and Forms will appear. Each item will have to be created. From this panel you would normally Create a new table design Modify an existing table design Open an existing table and display its content.
Page
10/18/2013
Two additional, rather complex but very powerful data types are possible. They are: Hyperlink (The following was copied from Access help Function key F1). Text or combinations of text and numbers stored as text and used as a hyperlink address. A hyperlink address can have up to three parts: text to display the text that appears in a field or control. address the path to a file (UNC path) or page (URL). subaddress a location within the file or page. screentip the text displayed as a tooltip. The easiest way to insert a hyperlink address in a field or control is to click Hyperlink on the Insert menu. For more information, see Type a hyperlink address in Form view or Datasheet view. Each part of the three parts of a Hyperlink data type can contain up to 2048 characters
Lookup wizard (The following was copied from Access) Lookup Wizard Creates a field that allows you to choose a value from another table or from a list of values by using a list box or combo box. Clicking this option starts the Lookup Wizard, which creates a Lookup field. After you complete the wizard, Microsoft Access sets the data type based on the values selected in the wizard. The same size as the primary key field used to perform the lookup, typically 4 bytes
Field Description. This is an optional field that can be up to 255 characters long. Use this to document your table structure. Field Size. Assigns maximum field length, but is only used for Text and Number fields. However you really only need to concern yourself with length for Text fields. For number fields: If a whole number like social insurance number, use Long Integer. For a value that has decimal places use Double. For more information turn to Data types and Field sizes under Access help. Page 9 10/18/2013
Chapter 2 - Using a Database and Tables Format. Enables you to specify how the data is to be displayed and or printed e.g. Currency - 2 decimal places, Short or Long Date format. Input Mask. Specifies how the data is be entered over a mask. Examples: (000)-000-0000. A letter or digit entry required. C any character or space, but nothing else. Caption. Label that will be used as column heading in a query and or report instead of the field name. Default value. Access will automatically insert whatever is specified. e.g. todays date (=Date()). Validation Rule. Data must meet the limitations as per specified rules. e.g. Value must not be less than $6.00. More examples follow. Validation Text. The message that will be displayed if validation rule is violated. Required. If yes then user must enter a value, i.e. field cannot be left blank. Allow zero length. If allowed, text with no length e.g. is permitted. Indexed. Maintains an index on all the values of this field to speed up searches and links. A good rule of thumb as to whether or not to assign an index is: It must be assigned to all primary key and linked fields in a relationship. If one does frequent searches and or sorts on this field. Note: If you index a field, you will be prompted as to whether or not duplicate keys are allowed. If no duplicate values are permitted then the field can be assigned a primary key. Additional field property notes. Acceptable data entry formats are: 5/14/94, 5/14/1994, May 14, 1994, May 4, 1994, May 14. Note: 5/14/00 is assumed to be May 14, 2000. Time is entered as 16:00:00 or 16:00. All dates and times can be formatted (displayed) with a number of short and long date and time formats. Validation rules examples: <> 0 ; 10 OR 900 ; Like Montr??? ; <= #12/31/96# etc.. Null Values. If you do not type a value, Access stores a Null value in the field. Note: To seek out a null value in a criteria simply specify Null in the criteria cell of the query. See example in the Query chapter.
Chapter 2 - Using a Database and Tables Add a New Record. Use the >* icon to add a new record to the table. You can also use menu Records - Go To New. Delete a Record. There are numerous ways of deleting a record. Note: The record is not physically deleted, but flagged as having been deleted. The methods to delete are: First select the entire record (click leftmost column). Use the Cut icon From the menu select Edit - Delete Hit the Del key Using the right mouse button, select Cut. Maximize and minimize the size of your view display. Use bottom at the top right of the screen. Find or Replace information. To find a record use the binoculars icon which presents the Find dialog (see below) and complete the required information. This presents one record at a time. Note: The same thing can also use the Edit - Find to do the same. To Replace data, use the or Edit - Replace menu and follow the instructions. This can replace a single data field or all matching values in the table. Note: This can also be done in an Update Query (See Query chapter). Sort your table. Use the sort icons to rearrange the display order based on the column that you have selected. There is an icon to sort in ascending order (A:Z) and one for descending order (Z:A). To sort on multiple columns do the following. Under the Records menu, you will find a Quick Sort option. Complete the dialog to let you to sort on multiple columns. Note: The underlying order (physical order) of your table is not changed with a sort. The sort only changes the order of how the data is displayed. Filter the table to only show selected records. Use the Edit/Filter icon. This will bring up a query dialog. This dialog is completed similarly to what is explained in the query sections of these notes. Size the column width on the view datasheet. Position the mouse pointer on the heading row , on the right side of the desired column. Hold the left mouse button to expand or reduce the width. Let go when done. When you close the view you will prompted to save this display format for future use. Misc. options. Explore the Format menu to hide, freeze and apply font and height to the view. Under the records option, you can prevent the user from changing the information in the table. Select Records -Allow editing. Move a column to a new locations on the datasheet view. This cannot be done here. To do this you must create a query and within the QBE dialog, move the columns around. See explanations in the query window.
Page
11
10/18/2013
Sort icons Replace dialog would let you find and replace all or some of the data.
Page
12
10/18/2013
Click on the Relationship button or from the main menu select Edit - Relationship. From the Add Table dialog, Add each of the tables (be sure not to duplicate any tables). Click the Close button on the Add Table dialog.
See Add Table Dialog below. This dialog is super imposed (this was manually placed this way for your benefit) on a relationship diagram (with 1 table address thus far). These two picture in turn are combined with the Database window. Table option. Add Table Dialog under the Relationship dialog.
Page
13
10/18/2013
Page
14
10/18/2013
Page
15
10/18/2013
0Chapter 3 - Relationships in Access 1 Sample output from a relationship diagram print out. Use File - Print definition.
Page
16
10/18/2013
Page
17
10/18/2013