0% found this document useful (0 votes)
14 views47 pages

Exploring Microsoft Office 2013: Tables and Queries in Relational Databases

The document discusses creating and working with tables and queries in Microsoft Access. It provides step-by-step instructions for setting up table relationships, creating single-table and multi-table queries, performing calculations, and filtering query results. Screenshots of the Access interface are included.

Uploaded by

OOI JIA YEE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views47 pages

Exploring Microsoft Office 2013: Tables and Queries in Relational Databases

The document discusses creating and working with tables and queries in Microsoft Access. It provides step-by-step instructions for setting up table relationships, creating single-table and multi-table queries, performing calculations, and filtering query results. Screenshots of the Access interface are included.

Uploaded by

OOI JIA YEE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 47

EXPLORING MICROSOFT OFFICE 2013

VOLUME 1
by Mary Anne Poatsy, Keith
Mulbery, Lynn Hogan, Amy
Rutledge, Cyndi Krebs, Eric
Cameron, Rebecca Lawson

Chapter 2
Tables and Queries in
Relational Databases

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 1


OBJECTIVES

• Establish table relationships


• Create a single-table query
• Create a multitable query

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 2


TABLE DESIGN
• Good database design begins with the tables.
• Tables provide the framework for all of the
activities you perform in a database.
• Systematic approach
• List all of the tables needed
• List all of the fields needed

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 3


INCLUDE NECESSARY DATA

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 4


LINK TABLES USING COMMON FIELDS

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 5


PRIMARY AND FOREIGN KEYS

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 6


ESTABLISHING TABLE RELATIONSHIPS

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 7


REFERENTIAL INTEGRITY

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 8


CASCADE OPTIONS

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 9


RELATIONSHIP TYPES

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 10


CREATING ACCESS RELATIONSHIPS
1. Open SMSlab01.accdb
2. Go to ‘Database Tools’ tab and Click
‘Relationships’
3. Add all three tables on the Relationship
screen

11
CREATING ACCESS RELATIONSHIPS

12
CREATING ACCESS RELATIONSHIPS

4. Arrange the tables to link the PRIMARY KEYS to the FOREIGN


KEYS. (Primary key = a unique identifier of a record in a table.
Foreign key = referencing key to link two tables. The primary key
in one table will be the foreign key in another table in order to
link them)

5. Click on Institution Code from tblInstitution and drag it to


Institution Code in tblContact. When the ‘Edit Relationships’ box
appear, check to see the correct fields are being linked and that
‘Enforce Referential Integrity’ and ‘Cascade Update Related
Fields’ are selected before clicking the CREATE button.

13
CREATING ACCESS RELATIONSHIPS

• Do the same for Institution Code in tblOrder.

14
CREATING ACCESS RELATIONSHIPS

15
CREATING A SINGLE-TABLE QUERY
QUERY WIZARD
1.Click the CREATE tab.
2.Click Query Wizard in the Queries group.
3.The New Query wizard starts, select Simple
Query Wizard then click OK
4. Simple Query Wizard dialog box appears. In
the box labelled Tables/Queries select Table:
tblContact from the drop down menu.
5. Enter qryQuery01 as the name for the query

16
QRYQUERY01

17
QRYQUERY01

18
CREATING A SINGLE-TABLE QUERY QUERY
DESIGN

1.Click the CREATE tab.


2.Click Query Design in the Queries group.
3.Select the table you need in your query from the Show Table dialog
box.
4.Click Add to add the table to the top section of the query design and
close the Show Table dialog box.
5.Drag the fields needed from the table to the query design grid
(alternatively double-click the field names) then add criteria and
sorting options.
6.Click Run in the Results group to show the results in Datasheet View

19
QUERY DESIGN VIEW

20
QUERY DATASHEET VIEW

21
SINGLE TABLE QUERY
1. Create a single table query using query
design that display all contact information of
“Ali Baba”.
2. Save your query as qryQuery02.

22
QRYQUERY02

23
QRYQUERY03A

1. Calculate the total number of students (sum)


for each educational sector.

2. Save your query as qryQuery03A.

24
QRYQUERY03A

25
QRYQUERY03B
1. Create a select query titled qryQuery03B,
based on the tblOrder table, which will list all
the fields in the orders table.

2. Experiment by using the criteria =CD-ROM in


the Order Type field to select all the book orders
or all the CD-ROM orders. Save your query.

26
QRYQUERY03B

27
QRYQUERY03C
1. Modify the query to show the totals VALUE
for each ORDER TYPE only using the
‘Group by’ and ‘Total’ functions. Sort the
results in DESCENDING order based on its
total VALUE. Your query and dynaset should
look like the ones below. Save your query as
qryQuery03C.

28
QRYQUERY03C

29
QRYQUERY03D
1. Find the average number of books ordered.

2. Save the query as qryQuery03D.

30
QRYQUERY03D

31
QRYQUERY3E
1. Find the order for books with the lowest
value. Save the query as qryQuery3E.

2. You will need to include a criterion under


criteria that displays only orders for books.

32
QRYQUERY3E

33
QRYQUERY03F
1. Add the tblInstitution table, then add the fields
Sector and Enrolment Size.
2. Click on the Total button on the toolbar. A
total row appears in the QBE grid.
3. In the Sector field choose Group By from the
total menu. In the Enrolment Size field choose
Avg (average) from the total menu. Save as
qryQuery03F.

34
QRYQUERY03F

35
MULTITABLE QUERIES
• Contains two or more tables
• Uses related tables
• Similar to creating single-table query

36
MULTITABLE QUERIES
1. In the Show Table window click on tblOrder, then click on add to add
the table to the query. Do the same for tblInstitution, then click on Close.
2. A query design window appears. Add the following fields by double
clicking on the field name.
• - tblOrder.Order Number (i.e. the order number field from the tblOrder
table)
• - tblOrder.Institution Code
• - tblInstitution.Institution Code
• - tblInstitution.Institution Name
• - tblInstitution.Enrollment Size
3. In the Criteria row for Enrolment Size column, type >5000, sorted in
ascending order. Save as qryQuery04A.

37
QRYQUERY04A

38
QRYQUERY04B
1. Create a query titled qryQuery04B that finds
the largest number of books ordered by a single
institution. This means we want to know what is
the largest number of books that a particular
institution has ordered if any.
2. Include Institution Code, Institution Name and
Book Quantity from tblOrder and tblInstitution
in your query as shown below.

39
QRYQUERY04B

40
QRYQUERY04C
1. Create qryQuery04C that is based on tblOrder
and tblInstitution.
2. Select Institution Code, Institution Name, Order
No and CD Renewal as the fields for the query.
3. We’d like to find all the CD orders with renewal
dates before 01-Jan-2012. Include this criteria ( <
1/1/2012 ) in the criteria for CD Renewal.

41
QRYQUERY04C

42
QRYQUERY04D
1. Create a query that retrieves records from
tblContact, tblInstitution and tblOrder to obtain
the Contact Name from College or University
Institutions with TOTAL order values higher
than 50,000.

2. Save the query as qryQuery4D.

43
QRYQUERY04D

44
QRYQUERY04E
1. Now, we’d like to create a query that does some basic
calculation for us. Assuming that the sales team at SMS
gets a 20% commission for every order they get from
institutions. We’d therefore like to know how much
commission they receive for each order made.
2. Add two tables tblInstitution and tblOrder to
qryQuery4E. Select Order No, Institution Code,
Institution Name and Value.
3. Create a new field called ‘Commission’. This is the title
that will be displayed for the field.
4. Next, enter the expression for the field: [tblOrder.Value]
* 0.2 45
QRYQUERY04E

46
COPYRIGHT

All rights reserved. No part of this publication may be reproduced, stored in a retrieval
system, or transmitted, in any form or by any means, electronic, mechanical,
photocopying, recording, or otherwise, without the prior written permission of the
publisher. Printed in the United States of America.

Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. 47

You might also like