Upload
oliver-hoover
View
248
Download
0
Tags:
Embed Size (px)
Citation preview
CS&E 1111 AcIntro
Introduction to Database SystemsIntroduction to Database Systems
• Introduction to Database Concepts• Introduce Microsoft Access• Tables, Queries, Forms, Reports
etc• Creating a simple database table• Indexing
Objectives:
CS&E 1111 AcIntro
Data, Information, & DatabaseData, Information, & Database Data : A collection of numbers and text :
273448926 Information : Meaning derived from data
SSN # 273-44-8926 Database: A collection of related data stored in a
specific format to simplify retrieval. The phone book and dictionary are examples of databases.
John Smith’s SSN # 273-44-8926 DBMS – Database Management Systems are
programs that help in the storage and retrieval of information from databases. (Access, Oracle)
CS&E 1111 AcIntro
DBMS Vs. Spreadsheets DBMS Vs. Spreadsheets Store and retrieve
data Provide support for
data “organizing” and selecting
Can do simple calculations
Efficient data handling
Customers of VISA with balance > 1000
Store and analyze data
Provide support for complex calculations
Can do simple data organizing and selecting
Inefficient data handling
What was the net profit of VISA
CS&E 1111 AcIntro
Access DBMS
Objects
CS&E 1111 AcIntro
Tables - a list of data organized into fields and records
Queries - question structures to sort, filter and select specific information
Forms - structures for screen views of data Reports - structures for written output of data Program Modules - program code to perform
specific actions
Access DBMS “objects”:
CS&E 1111 AcIntro
A Database Management System
Data Tables
Reports
RelationshipsData Input:Onto TablesOnto FormsFrom files
OutputFiles
QueryResultsDBMS
Queries
Program Modules
CS&E 1111 AcIntro
An Inventory Database SystemAn Inventory Database System
Tables:
Reports & Queries
Forms:
Order Transactions
New Vendors & New Customers
NewProducts
Shipments
Program Modules
Program Modules
CurrentInventory
CustomerAccounts
VendorList
OrdersOrderDetails
CustomerInvoices
Daily ShipList
AccountsPayable
InventoryLow Message
Output File:
CS&E 1111 AcIntro
Data is stored in objects called Tables• Data on tables are listed in rows called records • A record consists of one or more ordered categories
called fields• Field types include Text. Number, Currency,
Date etc. Certain fields are required fields and must be filled
• Field Properties – format, validation rule, required, size, masks, defaults, ranges
A table is a listing of multiple records, all records in a table have the same fields
“Objects”: Tables
CS&E 1111 AcIntro
Primary KeyPrimary Key
A field, or combination of fields, which uniquely identifies a record in a database
CS&E 1111 AcIntro
Table Datasheet View: Bank CustomersTable Datasheet View: Bank Customers
Field RecordPrimaryKey
Customers: Tableacct# ssn lname fname address city state zipcode
456 123456789 Sommer Martín 5400 E. Broad ST Reynoldsburg OH 43213543 139555002 Suyama Michael 4110 Old Redmond Rd. Worthington OH 43201544 157745969 Lebihan Laurence 342 S. Drexel Bexley OH 43209999 123456789 Sommer Martín 5400 E. Broad ST Reynoldsburg OH 43213
1112 178301771 Berglund Christina 707 Oxford Rd. Columbus OH 432222456 201529842 Trujillo Ana 7 Houndstooth Rd. Marysville OH 420013064 227776183 Moos Hanna 29 King's Way Groveport OH 432873575 257436001 Citeaux Frédérique 3400 - 8th Avenue Suite 210 Columbus OH 432104456 290951508 Callahan Laura Coventry House Miner Rd. Dublin OH 432555323 328824082 Moreno Antonio 49 Gilbert St. Cleveland OH 40032
CS&E 1111 AcIntro
A Second Table - “Transactions” keeps track of all deposits and withdrawals
A Second Table - “Transactions” keeps track of all deposits and withdrawals
• What’s the Primary key on this table?Account# date transaction$
456 4/1/2012 $1,231.39544 4/1/2012 $3,366.82
2456 4/2/2012 $2,301.683064 4/2/2012 $5,087.664456 4/3/2012 $12,838.425323 4/3/2012 $167.805566 4/4/2012 $641.92456 4/9/2012 ($1,186.26)544 4/9/2012 ($3,243.43)
1112 4/11/2012 $159.664456 4/12/2012 ($12,367.91)
CS&E 1111 AcIntro
Walkthrough: Setting up a Table using Design View
CS&E 1111 AcIntro
Divide Tables into Inseparable Fields
Address as 1 field – 17 Main St. New York, New York 10002
Address as 4 fields Street Address - 17 Main St. City - New York State - New York Zip code – 10002
If you wanted to filter the table to get a list of only New York City residents how would this work with these two different Table structures
CS&E 1111 AcIntro
Defining Properties for each Field in a TableDefining Properties for each Field in a Table
For a person’s social security number use: What field type?
Text, Number - Short Integer, Number- Long Integer etc.
Should it be optional or required? Does the value need to be within certain
limits or from a predefined list? Is there a default value? Would an input mask be appropriate
CS&E 1111 AcIntro
Memory and Field SizeMemory and Field Size
Text: Up to 255 characters
Memo: Up to 65,535 characters
Numbers: Integer - 2 bytes - 16 bits Long Integer - 4 bytes - 32 bits (*) Byte (character) - 1 byte Single - 4 bytes - -precision 7 Double - 8 bytes - -precision 15
Why adjust the field size for Social security number?
CS&E 1111 AcIntro
How should you decide what information goes on which table?
How should you decide what information goes on which table?
If a fact appears in more than one record of a table, then this fact should probably be defined in another table. Example: Account number
Each fact change should change in only one place Example: Address
Calculations shouldn’t be part of the database Example: Current Balance
Select a Primary Key where applicable so you can relate your tables Example: Account number
CS&E 1111 AcIntro
Tools: Sorting and Filtering Tools: Sorting and Filtering
Sorting - allows the user to temporarily order the records by a specific field Ascending or Descending order Single or multiple sort fields
Filtering - allows the user to view only specific records that meet the criteria Filter by form or filter by selection Specify a single criteria or use Boolean and/or
for multiple criteria in multiple fields
CS&E 1111 AcIntro
Storing and Retrieving Records from TablesStoring and Retrieving Records from Tables
How are DBMS systems designed to efficiently handle data?
Data is stored on magnetic or optical disk in a linear fashion
To retrieve a specific record one would have to search them one at a time until the desired record is found.
To make data retrieval more efficient one can “index” a table based on a specific field.
Search routines could then be used on that field to more efficiently find the record
Example: Alphabetically sorting a dictionary and then analyzing the first letter of the criteria in the sorted list.
CS&E 1111 AcIntro
Linear Search on Un-indexed FieldLinear Search on Un-indexed Field
Find the name of student for ss#606147775
• Go to the first record to see if 178301771 matches 606147775. If no match then check the next record until a match is found.
• Here it must check 11 items before you find the correct one. On average it will have to check #entries/2
ssn lname fname606147775 Anders Maria178301771 Berglund Christina988544806 Buchanan Steven290951508 Callahan Laura257436001 Citeaux Frédérique874775203 Davolio Nancy419975418 Dodsworth Anne371616449 Fuller Andrew536370683 Hardy Thomas774094122 King Robert157745969 Lebihan Laurence474621100 Leverling Janet227776183 Moos Hanna328824082 Moreno Antonio684995818 Peacock Margaret123456789 Sommer Martín139555002 Suyama Michael201529842 Trujillo Ana
CS&E 1111 AcIntro
A Binary Search on an Indexed Field
1. First go to the middle record of the table and compare values to see if 606147775>328824082.
2. If it is greater, continue checking only from this midpoint to the end. Otherwise continue checking only from the beginning to the midpoint
3. Then go to the midpoint of this subsection. The process continues until a match is found
This table is sorted by SSN
Indexing can aid in querying efficiency using algorithms such as binary search (1/2,1/2 again) vs. a linear search (1 at time from top to bottom). A binary search cuts the processing time significantly for large databases
ssn lname fname123456789 Sommer Martín139555002 Suyama Michael157745969 Lebihan Laurence178301771 Berglund Christina201529842 Trujillo Ana227776183 Moos Hanna257436001 Citeaux Frédérique290951508 Callahan Laura328824082 Moreno Antonio371616449 Fuller Andrew419975418 Dodsworth Anne474621100 Leverling Janet536370683 Hardy Thomas606147775 Anders Maria684995818 Peacock Margaret774094122 King Robert874775203 Davolio Nancy988544806 Buchanan Steven
Find name of student for ss#606147775
CS&E 1111 AcIntro
Indexing vs. Sorting
Sorting your table & saving permanently changes the record order.. Use an index instead.
ssn lname fname123456789 Sommer Martín139555002 Suyama Michael157745969 Lebihan Laurence178301771 Berglund Christina201529842 Trujillo Ana227776183 Moos Hanna257436001 Citeaux Frédérique290951508 Callahan Laura328824082 Moreno Antonio371616449 Fuller Andrew419975418 Dodsworth Anne474621100 Leverling Janet536370683 Hardy Thomas606147775 Anders Maria684995818 Peacock Margaret774094122 King Robert874775203 Davolio Nancy988544806 Buchanan Steven
ssn#606147775 is associated with record 14
CS&E 1111 AcIntro
From Tables to a Relational DatabaseFrom Tables to a Relational Database We have carefully looked at tables in our database
how to set them up, define fields etc. The real advantages of a DBMS however are in their ability to relate information.
Thus far we have customer names on one list and transactions on a separate list. How do we match a customer’s name to specific transaction?
We need a way to relate these two tables to extract useful information. We can relate these two tables by matching the account numbers.
CS&E 1111 AcIntro
One to Many RelationshipOne to Many Relationship
Customers: Tableacct# ssn lname fname address city state zipcode
456 123456789 Sommer Martín 5400 E. Broad ST Reynoldsburg OH 43213543 139555002 Suyama Michael 4110 Old Redmond Rd. Worthington OH 43201544 157745969 Lebihan Laurence 342 S. Drexel Bexley OH 43209999 123456789 Sommer Martín 5400 E. Broad ST Reynoldsburg OH 43213
1112 178301771 Berglund Christina 707 Oxford Rd. Columbus OH 432222456 201529842 Trujillo Ana 7 Houndstooth Rd. Marysville OH 42001
Acct#/Account No. is the Foreign Key
Account# date transaction$456 4/1/1999 $1,231.39544 4/1/1999 $3,366.82
2456 4/2/1999 $2,301.683064 4/2/1999 $5,087.664456 4/3/1999 $12,838.425323 4/3/1999 $167.805566 4/4/1999 $641.92456 4/9/1999 ($1,186.26)544 4/9/1999 ($3,243.43)
1112 4/11/1999 $159.664456 4/12/1999 ($12,367.91)
CS&E 1111 AcIntro
A Foreign Key is a field that defines the relationship between 2 tables:
A Foreign Key is a field that defines the relationship between 2 tables:
A valid foreign key must have all of the properties listed below:
1. Must be a primary key (unique) in at least one of the tables
2. The field names on each table do not have to match as long as the information is the same. Fields with the same name does not necessarily mean they are the foreign key.
3. The related fields must be the same data type (number, text etc)
CS&E 1111 AcIntro
Walkthrough: Establishing relationshipsWalkthrough: Establishing relationships
Foreign Key: acct#/Account#
Primary Key on Accounts table: acct#
CS&E 1111 AcIntro
Once Relationships are established you can gather information from one or more tables to answer questions like:
Once Relationships are established you can gather information from one or more tables to answer questions like:
Create a list of account numbers and owner names and total transactions
What are the total deposits made by accounts starting with 5?
What is the total balance of all accounts held by Jane Doe ?
These requests are known as Queries
CS&E 1111 AcIntro
To extract information from the Database use a Query which is a “question” or “request”
The query is not the data that results but a set of instructions specifying how specific records or combinations of records should be extracted - it lets the user:
prepare lists, sort, filter choose records to met specific criteria do calculations on the data Summarize data by a specific grouping match up the data to related information
“Objects”: Queries
CS&E 1111 AcIntro
Walkthrough: A Simple Query Walkthrough: A Simple Query
Design:
Create a query to list the first name, last name and transaction amount for each transaction
We will spend the next 1-2 weeks learning, in greater detail, how to use the query tool.
Dynaset Result:
CS&E 1111 AcIntro
Walkthrough: Setting up a formWalkthrough: Setting up a form
A form is not data that results but a set of instructions specifying a screen view format of the data. These forms are designed to simplify data display, inputting and editing.
“Objects”: Forms
CS&E 1111 AcIntro
The type of text formatting Report & Page headers, footers, titles Which data fields (from tables, queries
and/or calculations) to be used Sorts, Filters, Groupings of fields
Walkthrough: Setting up an AutoReport
A report is not the data that results but a set of instructions specifying the format of written output. Reports allow users to vary :
“Objects”: Reports
CS&E 1111 AcIntro
Sample
Report:
Transactions
by Customer
CS&E 1111 AcIntro
Programmed instructions updating tables/queries from inputs
customer address account balance
retrieving data from other sources performing tasks if a certain criterion is met
monthly bank statement balance > 20000
send letter offering estate planning service
“Objects”: Macros &Modules
This course will not cover the Macros & Modules - we can refer you to more Advanced books on Access & Visual Basic
CS&E 1111 AcIntro
A Review of Database TheoryA Review of Database Theory
Information is stored in objects known as tables consisting of records or related information categorized into fields. A field that uniquely identifies a table is known as a
primary key field Tables can be related to each other using valid
foreign key fields. Queries, Reports, Forms are objects which can
be created using the data on tables to dynamically extract/display information in a specified format.