Relational Database Software
Microsoft Access 2000
Note before we begin:
Converting a database
You CAN convert Access 95, 97 directly to 2000
You CANNOT convert Access 2000 directly to 95 or 97
Save it down > Tools/Database
Utilities/Convert Database/to Prior Access Version
General Concepts
What is a Database and what is it used for ?
A database is an organized
collection of data related to a particular topic or purpose.
The primary function of a database is to enable the user to organize and retrieve information in a manner
defined by the user.
Access
Relational database software with a graphical user interface.
Access integrates easily with Excel
& Word.
Easy to get started with pre-made tables, forms, queries & reports.
Can use to create database applications by incorporating
A Flat-file database consists of a single database file or table
which contains all the
information about a topic. It
does not physically link or point to other files.
A Relational database consists of multiple tables linked together
Flat-File vs. Relational
Name Address ClassID ClassName Instructor Time Mary Wills 1010 1st St. CO150 Composition Matthews 3 MWF Jim Johnson 234 Maple CO150 Composition Matthews 3 MWF Mark Smith 111 W. 3rd CO150 Composition Matthews 3 MWF
STUDENT INFORMATION TABLE
SupplierID SupplierName Address Contact Phone
S450 New Orleans Delights
New Orleans, LA
Anne Rice 800-555-1111
Supplier Table Products Table
The Database window
Menus and toolbars
Command Center – all operations start here
Categories of objects on left
Objects and creation icons on right
Status bar
Access Database Objects
Tables
Forms
Reports
Queries
Macros
Modules
Tables
Tables are the heart of Access.
All data stored in tables. Fields (columns) and records (rows) intersect to form cells.
Each table should contain information about one subject only.
Each field contains a specific type of information such as text, number,
currency, dates, etc.
Tables ( cont .)
Two or more tables are linked together through fields they have in common.
This is done by defining relationships.
Access creates relationships between different tables, about different but related subjects
A table should contain data about 1 topic only, e.g., not students and
faculty in one.
Queries
Create a subset (dynaset) of data.
Means for obtaining data from 1 or more related tables.
Used to sort and/or select records according to your criteria.
Used as the basis for reports.
Action queries can be used to update, archive, delete, append
Forms
Used to view, edit, and enter data. You can also enter data directly into a table.
They can be customized for convenience.
Best for on-screen viewing.
Forms may be designed to simplify data entry and data editing.
Can use controls to make data entry
easier and more consistent such as drop-
Reports
Sorted and summarized data. They can be designed to show only the data you
want to show. Best for printed materials.
Used for printing data in an organized, professional looking manner.
Can add subtotals, groupings, etc. to reports.
Macros
Automatically carry out one or more tasks. Best for tasks that you
perform often.
Modules
A set of procedures stored as a unit to perform an action. Written in
Visual Basic.
Pages
A data access page for viewing on the Internet, or an intranet.
Table Design vs. Table datasheet view
Toggle in the upper right corner. Flips between the data itself (table) and the
underlying structure (design) of the data.
Datasheet allows you to enter data, sort and filter data, hide and freeze columns, etc.
Design allows you to create tables, add
fields, and set and modify field properties.
Navigating the datasheet
Navigation buttons in lower right hand corner – one record at a time, beginning, end, new record, or type the number in.
PgUp or PgDn for page at a time
CTRL + Home for beginning, CTRL + End for end
F5 moves you to record box, type record number, enter
Resizing rows and columns
Similar to Excel
Click and drag border
D-click right border for autofit
Sorting
Automatically sorted by primary key
(unique identifier assigned to every table)
Select sort column, hit ascending or descending sort button
Can select multiple adjacent columns – will sort left to right
Very simple – filters and queries for more flexibility
Selecting data in datasheet mode
Part of cell - Click and drag
Entire cell – Click left edge (+ mark)
Adjacent fields – Click left edge and drag
Column – Click top of column (black arrow)
Row – Click side of row (black arrow)
Multiple columns – Click and drag black arrow
Multiple rows – Click and drag black arrow
All – CTRL + A or upper left box
Rearranging, hiding, freezing
To move a column, select, then drag
To hide a column, select it, Format/Hide
For confidential information
Format/Unhide to restore
To freeze a column, select it, Format/Freeze
Will go to left side
To keep it in view as you scroll
Printing datasheets
Hide and/or size columns for best view
Change formats, fill colors
File/Page setup for orientation and columns
Landscape is often best orientation Preview before printing
Manipulating data
Adding records
►* for new record
Always add to bottom – Access will resort when table is closed
No need to save – when you leave record, Access will save
Records/Data entry for data entry mode
Current record only – less distracting
Editing records
Click inside field (pencil will appear on left)
Saves when you leave row or close table
Can only “Undo” last record, so BE CAREFUL
Within same record – hit escape to
Deleting data
Within a single field, select and hit Del
Select records or multiple records from left, hit Del
It will warn you once – no Undo, no exiting without saving changes
Large groups of deletes – use delete
Copying, moving data
Edit/Copy, Edit/Cut, Edit/Paste
CTRL + C, CTRL + X, CTRL + V
Use toolbar buttons
You must select the same number of fields to paste into that you copied from
CTRL + ; - current date (doesn’t always work)
Finding data
Edit/Find
Choice of column or table
Choice of all or part of text
Shift + F4 for future searches
Filtering Records
Filtering Data
By Selection
Simplest; cannot sort at the same time
Can also filter “excluding” selection
By Form
Can use ‘and’ ‘or’ statements; cannot sort at the same time
Advanced Filter
Use a filtering grid to enter expressions and
Filter by selection
Select data you wish to look for
Hit Filter by selection button
All records that match will appear
Multi-filter, by adding criteria
Remove filter button when finished
Filter by form
Best for simple multi-criteria
Data entry form will appear
Type in criteria, hit filter by form button
Remove filter button when finished
Advanced Filter/Sort
Records/Filter/Advancrd filter-Sort
Most versatile of three
Can sort and filter in one step
Only kind that can be saved (as a query)
File/Save as Query
Advanced Filter/Sort Operators
> greater than
>= greater than or equal to
< less than
<= less than or equal to
<> not equal to
* wildcard
Advanced Filter/Sort Operators (con’t)
Not - eliminates criteria from evaluation
Between – finds criteria within a range
Like – used with wildcard (*)
Null – no value
Examples of Advanced Filter/Sort Operators
=CA - value is equal to “CA”
>=T - value begin with letter T, through Z
Is not Null - there is some value
<>CA, Not CA - All values but “CA”
>=1/1/91 - Date is on or after 1/1/91
Like G* - Values that start with G
Not like *oak* - All words that don’t have
“oak” in them
Advanced Filter/Sort criteria
Records/Filter/Advanced Filter-Sort
Drag or D-click or pulldown fields that are involved
“Specify sort (ascending, descending, neither)
Specify criteria using operators, text, numbers
Multiple criteria – “and” vs.
“or”
If you are looking for an “and” relationship, place both criteria on same line
Vertical lines between boxes are “and”
relationships
If you are looking for an “or” relationship, place criteria on different lines
Horizontal lines below “criteria” are “or”
relationships
“Or” statements can be typed together in
Practice session
“X” to clear grid
A list of orders sent to Switzerland sorted by shipping date (18 records)
A list of orders shipped outside the USA in 1996 (123 records)
A list of orders with freight $50 or
over to Germany or Brazil sorted by
Database Design
Figuring out what you need
Determine the purpose of the database.
The subjects that need to be included and the facts you need about each subject.
Determine the tables you need. Divide information into separate subjects, and have a different table for each subject.
Determine the fields you need. Decide what information will be stored in each table. Break the information down to its
Figuring out what you need (con’t)
Determine which field will be the unique identifier (key field). If there isn’t one (i.e.
– SS#), Access will supply one. Names
are not unique, and addresses and phone numbers can change.
Determine the relationships. Decide how the tables relate to each other. Add fields and/or tables to help clarify these
Sample database design
You have a list of workshops, people who came, people who presented, how much they spent
You want expenses by person, by
workshop, by category, various sub-totals
You want lists of attendees by workshop, by location, by interests
You want to create mailing lists for future workshops, based on interests and/or
4 interrelated tables
Table of workshops
Table of attendees
Table of presenters
Table of presenter expenses
Workshop index
W# - key field
Name of workshop (subject/city)
Facility
Address 1
Address 2
City
State
Zip
Date of workshop
Attendee listings
A# - key field
W# - (pulldown menu of subject/city)
Prefix
FName
LName
Phone number
Address 1
Address 2
City State
Presenter listings
P# - key field
Prefix
FName
LName
Phone number
Address 1
Address 2
City
State
Zip
Presenter expenses
E# - key field
W# (pulldown menu of subject/city)
P# (pulldown menu of presenters)
Date
Travel expenses
Food expenses
Lodging expenses
Materials expenses
Creating the tables
Files/New/Database/Create to start from scratch
Table wizard will leads you through decisions
Design view toggles with datasheet view
Setting the primary key
This is step 1
Default ordering by this field
Access won’t allow duplicates
Helps define and create relationships between tables
Usually best to have Access assign one (SS#, pre-existing employee # are exceptions)
Hit the key icon
Set data type as “Autonumber”
Field properties – upper grid
Field Name – no spaces – or other applications can’t read it
Data type – number ONLY if you perform math functions (Zip Code, phone numbers best as text) – default is text
Lookup wizard to set up a pull down box (pre-existing or new list)
Description – will show in status bar – let others know what the field is for, how to
Field properties – lower grid
F6 toggles between upper and lower
Each field created in upper grid has a set of properties defined in lower grid
Field size
Maximum number of characters an entry could be
50 is default for text field
250 is maximum for a text field
64,000 is the maximum for memo field
Format
Displays numbers and text in a certain
format, usually numeric – dates, currency.
Different formats displayed for different data types (text has none listed)
Some text formatting: < is all lowercase,
> is all uppercase, @ will display “no data” when nothing is entered
Input mask
Inserts characters that aren’t saved in data, but help the imputer format data – phone numbers, Social
Security numbers, dates
Hit the “…“ button to see options
Caption
Specifies a label other than the field name
Spaces can be used here, as opposed to the field name
Default is field name
Default value
Automatically fills in a specific value – current date is most common
=Date() gives current date
CO for home state
Value can be changed after the fact
Validation rule
Limits data to certain restrictions
Use Expression Builder (…) or just type it in
Use same standard operators from advanced filters
>=50
=25 or=50 or=75
Validation text
Message displayed when data breaks violation rules
“Number must be greater than or equal to 50”
“Number must be in increments of 25”
Required, Allow Zero Length
These are similar
“Required” requires that data be entered
“Allow Zero Length” applies to text and memo only, allows a blank field to be accepted
Indexed
Speeds searches on frequently sorted or search fields
Slows data entry, requires more memory
Only use when needed
Key fields are always indexed
Relationships between
tables
Types of relationships
One to many – most common relationship
• Employee to Sales
• Each record in Sales matches only one record in Employee, but one employee had many sales
Many to many – strongly discouraged, unnecessary data redundancy
• Student to Classes
• Each record in one database matches multiple records in another
• Solved by creating and intermediary table with one-to- many relationships at each end
Types of relationships (con’t)
One to one – rare because it is two dimensional, can use Excel instead
• Business information to personal information
• Allows separation of databases, store personal information in a limited access format (password)
Viewing relationships
Tools/Relationships
Drag around boxes, size boxes, lines will move
Common fields are linked by lines
Key fields are in bold
Key fields are often, not always, the linking field
Forming and editing relationships
R-click on line to edit or delete relationship
Click and drag one field to same field in different table to form
relationship
One and many icons don’t show
Forming and editing relationships (con’t)
Click on line to edit properties
“Enforce referential integrity” will turn them on
“Cascade delete” will delete all records with references to that record – BE
CAREFUL
“Cascade update” is not as dangerous – will update all affected fields
Extra credit!
Can you find the table created to
link two many-to-many relationship tables together?
Queries
Two kinds of queries
Select queries
Allow you to select, view, and analyze data
Action queries
Allow you to modify data
4 kinds: Update, Delete, Append, Make table
Creating a query
Select the database
Queries/New
Design view
Select needed tables from the “show tables”
box
Close the box
Tables must be connected, or all
permutations will show, and your PC will crash
Select the fields
Drag or D-click or pull down needed fields to the field boxes
To add all fields, click asterisk or D- click the Table header
Specify sort order
Not required, but good to find an easy way to look through the data
Ascending or descending in selected field
More than one field selected, will sort left to right
You can sort with a hidden column to
Specify criteria
Limits results of the query
Use same expressions as advanced filter
Multiple criteria use “and,” “or”
Horizontal lines are “and”
Vertical lines are “or”
Expressions and calculated fields
Bring up the tables you are working from (Queries/New/Design view)
In Field grid, put field names in brackets
Join or calculate fields with expressions
R-click, choose build to build with
Expression and calculation examples
[FirstName]+” “+[Last name]
[City]+”, “+[State]+” “+[Zipcode]
[UnitPrice]*[Quantity]
[UnitPrice]*.25
Expr1 is default column name, type in your own to left of colon
Parameter Queries
For queries you run frequently, with different values
Design query normally, type prompt text between brackets
[Enter the last name], or [Enter the date]
When someone brings up the query,
Save your query
Use save button, or File/Save
Use default name or name it yourself
After save, it becomes part of the database, and will show when you hit the queries button in the
database window