You are on page 1of 54

Microsoft Access – Overview,

Table and Query Object

Computing Fundamentals 1
Outline
1 Introduction to MS Access

2 Getting started

3 Using the navigation pane effectively

4 Data entry

5 Database design

6 Table object: creating databases and tables

7 Query object

MSc. Ngô Cao Định MS Access – Overview, table & query 2


Introduction to MS Access
 Part of the Microsoft Office Suite
 The database management system
 It is used primarily for:
 Storing huge amount of data
 Organizing data to optimize storage
 Updating data reliably
 Retrieving data efficiently
 Administrating data strictly
 Provide professional tools to create, modify,
retrieve and optimize data efficiently

MSc. Ngô Cao Định MS Access – Overview, table & query 3


Access vs Excel
 Excel
 Don’t offer guarantee on data integrity
 Using worksheet to handle all data
 Suitable for monthly data
 Access
 Data is managed strictly
 Multiple related tables
 Data is defined clearly
 Large amount of data

MSc. Ngô Cao Định MS Access – Overview, table & query 4


MS Access interface
Quick Access Toolbar Title bar Ribbon

MSc. Ngô Cao Định MS Access – Overview, table & query 5


Database
 A database is an organized collection of
data
 Relational databases are made up of a set
of tables
 They may relate to other tables based on
the organized structure
 In Access, a database is store in only one
file
 *.mdb
 *.accdb

MSc. Ngô Cao Định MS Access – Overview, table & query 6


Database objects in Access
 Four commonly used objects
 Table
 Form
 Query
 Report
 Two less commonly used objects
 Macro
 Module

MSc. Ngô Cao Định MS Access – Overview, table & query 7


Navigation Pane
 List all objects in an Access database
 For launching a task on a database object
Navigation
Table group expanded
Pane Setting
to show all objects

Right click displays Click to collapse


popup menu listing all Tables group
tasks of an objects

Click to expand
Queries list

MSc. Ngô Cao Định MS Access – Overview, table & query 8


Database design
 There are 6 basic steps to design a
database:
1. Specify all requirements for the database
2. Determine what entities/tables will be
included
3. Determine what attributes/fields will be
included
4. Identify unique fields (primary keys)
5. Establish relationships between tables
6. Refine the design (eliminate redundant data)
MSc. Ngô Cao Định MS Access – Overview, table & query 9
Design for now and for the future
 Organizations evolve over time
 Anticipate future needs of the organization

MSc. Ngô Cao Định MS Access – Overview, table & query 10


Creating database in Access
1. Click New command
in File tab
2. Select Blank
Database
3. Navigate to the
selected folder
4. Enter database file
name
5. Click Create button

MSc. Ngô Cao Định MS Access – Overview, table & query 11


Creating database in Access

MSc. Ngô Cao Định MS Access – Overview, table & query 12


Table
 The foundation of every database
 Containing data of an entity
 Organizing data into columns and rows
 Each row or record present information of
an instance of that entity
 Each column contains information in one
field of all instances of that entity

MSc. Ngô Cao Định MS Access – Overview, table & query 13


Table
 A table has two parts:
 Table structure: defines how to organize data
of an entity such as: column, data type, size,

 Data: is a collection of records containing
information of all instances of the entity

MSc. Ngô Cao Định MS Access – Overview, table & query 14


Table views
 A table can be opened in two different
views:
 Datasheet View  Design View

MSc. Ngô Cao Định MS Access – Overview, table & query 15


Creating a table
Create tab

Click on Table
Design button

List all Select


fields suitable
data type
for field
MSc. Ngô Cao Định MS Access – Overview, table & query 16
Data types

Data types Description


Short text Stores alphanumeric data
Long text Stores lengthy text
Number Contains values that can be used in calculations
Date/Time Holds dates or times
Currency Contains monetary values
A special data type used to assign the next
AutoNumber
consecutive number each time you add a record
Assumes one of two value Yes/No, True/False,
Yes/No
On/Off (also known as Boolean)

MSc. Ngô Cao Định MS Access – Overview, table & query 17


Data types

Data types Description


Contains an object created by another
OLE object
application
Stores a Web address (URL) or the path to a
Hyperlink
folder or file
Used to store multiple images, spreadsheet
Attachment files, Word documents, and other type of
supported files
The results of an expression that references
Calculated
one or more existing fields
Creates a field that enables you to choose a
Lookup Wizard
value from another table

MSc. Ngô Cao Định MS Access – Overview, table & query 18


Field properties

Properties Description
Determines the maximum characters of a text
Field size
field or the domain of a number field
Caption Sets a label more readable than a field name
Sets a value that is automatically entered in this
Default value
field for new record

MSc. Ngô Cao Định MS Access – Overview, table & query 19


Field property of Number field
Decimal
Type Domain
precision
Byte 0 to 255 (no fractions) None
Decimal –10^28–1 through 10^28–1 28
Integer –32,768 to 32,767 (no fractions) None
–2,147,483,648 to 2,147,483,647 (no
Long Integer fractions) None
Single –3.402823E38 through 3.402823E38 7
–1.79769313486231E308 through
Double 1.79769313486231E308 15
Replication ID Globally unique identifier (GUID) N/A

MSc. Ngô Cao Định MS Access – Overview, table & query 20


Setup primary key

MSc. Ngô Cao Định MS Access – Overview, table & query 21


Establishing Table Relationships

MSc. Ngô Cao Định MS Access – Overview, table & query 22


Referential integrity
 Protects integrity of data
 Prevents accidental deletion of data
 Improves data accuracy

MSc. Ngô Cao Định MS Access – Overview, table & query 23


Referential Integrity

MSc. Ngô Cao Định MS Access – Overview, table & query 24


Cascade Options

MSc. Ngô Cao Định MS Access – Overview, table & query 25


Relationship types
 There are three types of table relationship:
 One to one (1-1)
 One to many (1-n)
 Many to many (n-n)

MSc. Ngô Cao Định MS Access – Overview, table & query 26


One-to-One Relationship
 A student belongs to only one Program
 An employee has one computer assign

MSc. Ngô Cao Định MS Access – Overview, table & query 27


One-to-Many Relationship
 A Program could have many students
enrolled
 A department could have many employees

MSc. Ngô Cao Định MS Access – Overview, table & query 28


Many-to-Many Relationship
 A student could take many course and a
course could have many students
 An author could have many books and a
book could have many author
 A music album could have many
artists/performers and an artist/performer
could have many albums

MSc. Ngô Cao Định MS Access – Overview, table & query 29


Query
 A query is a request for information from a
database or for action on a database
 Using query to:
 Retrieve data
 Calculate
 Summarize
 Update data

MSc. Ngô Cao Định MS Access – Overview, table & query 30


Query examples
 List all products of Beverages category
 List all orders have freight greater than
200$
 List all employees have birthday in this
month
 Calculate amount for each order
 Delete all products no longer imported
 Append categories from another table
 Count how many males and how many
females there are in the company
MSc. Ngô Cao Định MS Access – Overview, table & query 31
Query types
 There are two major query types:
Major query types Use
Select To retrieve data from a table or make
calculations.
Action Add, change, or delete data. Each task
has a specific type of action query

MSc. Ngô Cao Định MS Access – Overview, table & query 32


Query types in Access
 Select query
 Parameter query
 Totals query
 Crosstab query
 Make table query
 Append query
 Update query
 Delete query

MSc. Ngô Cao Định MS Access – Overview, table & query 33


Select query
 Review data from only certain fields in a
table
 Review data from multiple tables
simultaneously
 See the data based on certain criteria

MSc. Ngô Cao Định MS Access – Overview, table & query 34


Creating a single-table query
 Can be created two ways:
 Query Design tool
 Simple Query Wizard

MSc. Ngô Cao Định MS Access – Overview, table & query 35


Query Design View
Click run to view
the results

Products table in design view

Query design grid (QBE grid)

MSc. Ngô Cao Định MS Access – Overview, table & query 36


Parts of Query Design View
 Field Row
 Table Row
 Sort Row
 Show Row
 Criteria Row

MSc. Ngô Cao Định MS Access – Overview, table & query 37


Query Datasheet View

MSc. Ngô Cao Định MS Access – Overview, table & query 38


Query criteria
 Use criteria to find specific information
from your database
 Use comparison operators or logical
operators to specify criteria

MSc. Ngô Cao Định MS Access – Overview, table & query 39


Comparison operators
Operator Purpose Example
< Returns True if the first value is less than Value1 < Value2
the second value.
<= Returns True if the first value is less than Value1 <= Value2
or equal to the second value.
> Returns True if the first value is greater Value1 > Value2
than the second value.
>= Returns True if the first value is greater Value1 >= Value2
than or equal to the second value.
= Returns True if the first value is equal to Value1 = Value2
the second value.
<> Returns True if the first value is not equal Value1 <> Value2
to the second value.
MSc. Ngô Cao Định MS Access – Overview, table & query 40
Arithmetic operators
Operator Purpose Example
+ Sum two numbers. [Subtotal]+[SalesTax]
- Find the difference between two numbers or [Price]-[Discount]
indicate the negative value of a number.

* Multiply two numbers. [Quantity]*[Price]


/ Divide the first number by the second number. [Total]/[ItemCount]

\ Round both numbers to integers, divide the [Registered]\[Rooms]


first number by the second number, and then
truncate the result to an integer.

Mod Divide the first number by the second number, [Registered] Mod [Rooms]
and then return only the remainder.

^ Raise a number to the power of an exponent. Number ^ Exponent

MSc. Ngô Cao Định MS Access – Overview, table & query 41


Logical operators
Operator Purpose Example
And Returns True when Expr1 and Expr1 And Expr2
Expr2 are true.
Or Returns True when either Expr1 Expr1 Or Expr2
or Expr2 is true.
Not Returns True when Expr is not Not Expr
true.

MSc. Ngô Cao Định MS Access – Overview, table & query 42


Special operators
Operator Purpose Example
Is Null or Is Not Null Determines whether a Is Not Null
value is Null or Not
Null.
Like "pattern" Matches string values Like "instruct*"
by using the wildcard
operators ? and *.
Between val1 And Determines whether a Between 1 And 10
val2 numeric or date value - OR -
is found within a Between #07-01-07#
range. And #12-31-07#
In(val1,val2...) Determines whether a In ("A","B","AB", "O")
value is found within - OR -
MSc. Ngô Cao Định Access – Overview, table & query
aMSset of values. In (1,5,7,9) 43
Concatenation operators

Operator Purpose Example


& Combines two strings to string1 & string2
form one string.

+ Combines two strings to string1 + string2


form one string. If one value
is Null, the entire expression
evaluates to Null.

MSc. Ngô Cao Định MS Access – Overview, table & query 44


Query sort order
 Determines the order of records
 Sort order can be specified
 Determined from left to right

MSc. Ngô Cao Định MS Access – Overview, table & query 45


Multi-table Queries
 Contains two or more tables
 Uses related tables
 Similar to creating single-table query

MSc. Ngô Cao Định MS Access – Overview, table & query 46


Create a parameter query
 Frequently run variations of a particular
query

MSc. Ngô Cao Định MS Access – Overview, table & query 47


Create a totals query
 Allows you to group and summarize data

MSc. Ngô Cao Định MS Access – Overview, table & query 48


Make calculations based on data
 Example: ([Quantity]*[Unit Price])-
([Quantity]*[Unit Price]*[Discount])

MSc. Ngô Cao Định MS Access – Overview, table & query 49


Create a crosstab query
 Calculate subtotals aggregating by a field

MSc. Ngô Cao Định MS Access – Overview, table & query 50


Create a make table query
 Create a new table from data that is stored
in other tables

MSc. Ngô Cao Định MS Access – Overview, table & query 51


Create an append query
 Retrieve data from one or more tables and
add that data to another table

MSc. Ngô Cao Định MS Access – Overview, table & query 52


Create an update query
 modify the data in your tables

MSc. Ngô Cao Định MS Access – Overview, table & query 53


Create a delete query
 Delete data from your tables

MSc. Ngô Cao Định MS Access – Overview, table & query 54

You might also like