introduction to access isys 363. access objects tables –open a table: double click the table name...

34
Introduction to Access ISYS 363

Upload: hugo-carter

Post on 19-Jan-2018

221 views

Category:

Documents


0 download

DESCRIPTION

Creating a New Database MS Office button/New –Blank database –New database name and location

TRANSCRIPT

Page 1: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Introduction to Access

ISYS 363

Page 2: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Access Objects• Tables

– Open a table:• Double click the table name

– Home/View:• Datasheet view• Design view

• Queries• Forms• Reports• Pages

Page 3: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Creating a New Database

• MS Office button/New– Blank database– New database name and location

Page 4: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Creating a Table• Create/Table Design:

– Field name– Field data type

• Create table by using table templates– Create/Table Templates/select template

• Create a primary key– Never let Access to create a primary key for

you.• Enter data

Page 5: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Create a new Query• Create/Query design/Show table

– Select fields– Add criteria

• Sorting• Total and subtotal

– Query design tools/Total– A Total row is added to the design view– Select function from the total row’s dropdown

list

Page 6: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Creating a New Form

• Using Form Wizard– Create/More Forms/Form Wizard

Page 7: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Querying Database

ISYS 363

Page 8: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Basic Query Language Operations

• Selection• Projection• Join• Aggregates: Max, Min, Sum, Avg, Count

– Totals and SubTotals– GroupBy

• Calculated fields

Page 9: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Selection

• Selection operation retrieves records that satisfy user’s criteria.

Page 10: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Projection

• Projection operation defines a vertical subset of a table and retrieves only the specified fields.

Page 11: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Join

• The two tables must have common attributes:– Key and foreign key.

• Combines two tables to form a new table where records of the two tables are combined if the common attributes have the same value.

Page 12: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Join ExampleFaculty File:

FID FnameF1 ChaoF2 SmithF5 Boxer

Student File:SID Sname FIDS1 Peter F1S2 Paul F2S3 Smith F1

Faculty Join Student =

Page 13: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Join ExampleStudent File:

SID Sname FIDS1 Peter

F1S2 Paul

F2S3 Smith

F1

StudentCourse File:SIDCIDS1ISYS263

S1Acct101S3ISYS363S2ISYS263S2Fin350S2Acct101

Course File:CID Cname

UnitsISYS263 IS Intro 3ISYS363 MIS Intro

3Acct101 accounting

3Fin350 Finance Intro

3

(Student Join StudentCourse) Join Course

Page 14: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Aggregate Functions

• Max, Min, Sum, Count, Avg• View/Totals

• Ex. Student: SID,Sname, GPA, Sex, Major– How many students in this University?– What is the overall average GPA?

Page 15: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Aggregates by Group

– How many students in each major?– Compare male students and female students

average GPA.

Page 16: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Examples• Customer: CID, Cname, City, Rating• Orders: OID, Odate, SalesPerson, CID• Queries:

– Find customers live in San Francisco.– Produce a customer report that shows CID, Cname,

and Rating.– Number of customers in each city

• City, NumbeOfCustomers– Produce a report that shows the number of orders for

each customer:• CID, Cname, TotalNumberOfOrders

Page 17: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

University Database

Page 18: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

ERD Notations

Student Account

Faculty Course

Has1 1

EnrollM MAdvise

M

1

TeachMM

SID Sname Major SID Balance

FID Fname CID CnameUnitsPhone

Grade

Page 19: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Examples• Q1: Display students’ ID, name and account

balance who owe university more than $2000.

• Q2: Display student’s ID, name and total units.

• Q3: Find students taking at least 9 units and display their ID, Name and total units.

• Q4: Display CID, Cname, SID, Sname• Q5: Display CID, Cname, number of

students in each course.• Q6: Display faculty’s name and phone if the

faculty advises at least three students.

Page 20: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Order Processing Database Examples

• Order Processing Database:– Customer, Orders, OrderDetail, Product– MIS report– Total amount for each order– Criteria applied to subtotal

Page 21: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Calculated Fields

• Rename a field:– NewName:OldName

• Define a calculated field:– Tax:salary*.15– Age:Year(Now()) – Year(DOB)– IIF function

Page 22: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Criteria

• >, >=, <, <=, =, <>• Range: BETWEEN 1/1/03 AND 12/31/03• Wildcard:

– ? – match any one character• “K?NG”

– * - Match any number of characters• “C*”

Page 23: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Complex Condition

• University admission rules: Applicants will be admitted if meet one of the following rules:– 1. Income >= 100,000– 2. GPA > 2.5 AND SAT > 900

• An applicant’s Income is 150,000, GPA is 2.9 and SAT is 800. Admitted?– Income >= 100,000 OR GPA > 2.5 AND SAT >900

• How to evaluate this complex condition?

Page 24: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

• Scholarship: Business students with GPA at least 3.2 and major in Accounting or CIS qualified to apply:– 1. GPA >= 3.2– 2. Major in Accounting OR CIS

• Is a CIS student with GPA = 2.0 qualified?– GPA >= 3.2 AND Major = “Acct” OR Major = “CIS”

• Is this complex condition correct?

Page 25: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

NOTSet 1: Young: Age < 30

Set 2: Rich: Income >= 100,000

Young Rich

Page 26: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Order of Evaluation

• 1. ()• 2. Not• 3. AND• 4. OR

Page 27: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Examples• SAT = 800, Income 60,000, GPA 3.0, admitted?

– (SAT > 900 OR Income >= 50,000) AND Not GPA < 2.5

• A=2, B=3

(A=3 OR NOT (B < A)) AND B=A+1

Page 28: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Access Complex condition

• Rating = “A” OR Rating = “B”• Cname = “Chao” OR Cname = “Smith”• Rating = “A” OR Rating = “B” AND City=“SF”• (Rating = “A” OR Rating = “B”) AND City=“SF”

Page 29: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Excel’s IF with Complex Condition• Rules to calculate employee bonus are:

– If JobCode = 1 AND Salary < 5000 Bonus = 10% * Salary

– Otherwise: Bonus = 8% * Salary

• Rules to calculate employee bonus are:– If JobCode = 1 AND Salary < 5000 OR Sex = “F”

Bonus = 10% * Salary– Otherwise: Bonus = 8% * Salary

Page 30: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Sorting

• One field sorting• Two fields sorting

Page 31: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Other Queries

• Update query:– Query tools/Design/Query type/Update

• Delete query• Parameter query• CrossTab query

– Crosstab row

Page 32: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Forms

• Form wizard• Main/Sub Form

– Based on two tables with 1:M– Based on a query created from two tables

with 1:M• Pivot Table form

– AutoCal

Page 33: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Access Tools for Import/Export

• Import from Excel:– The first row of Excel’s list should contain field

names– External Data/Import/Excel

• Export to Excel:– External Data/Export/Excel

Page 34: Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms

Open Database Connectivity (ODBC)

• Provide a standard to retrieve data from a database.

• It manages one or more "database drivers“ that enables the communication between database and applications.

• To access a database, we use ODBC facilities to define a ODBC data source name for the database.