inf2070 database 2

28
INF2070 Database 2

Upload: fynn

Post on 10-Feb-2016

35 views

Category:

Documents


0 download

DESCRIPTION

INF2070 Database 2. What Will You Do?. Using skills learned in the last Database module, you will yet again make more tables This time we are going to learn about Queries, which give us the ability to look up things We will also learn more about Relationships - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: INF2070 Database 2

INF2070Database 2

Page 2: INF2070 Database 2

What Will You Do?

• Using skills learned in the last Database module, you will yet again make more tables

• This time we are going to learn about Queries, which give us the ability to look up things

• We will also learn more about Relationships• We will also learn how to create Reports that

display the data we want to see

Page 3: INF2070 Database 2

First Steps• Open up Access and click on Blank Database• We are going to create 3 tables. Use the steps

shown below:

• Call the tables Computers, Computer Techs, and Techs

Page 4: INF2070 Database 2

Here are the categories in the 3 tables. Go to Design View to put in the categories

Page 5: INF2070 Database 2

Next….Relationships• Don’t put anything in the tables yet!

• You have a many-to-many relationship when a single record in one table can relate to many records in another, and

a single record in that second table can also relate to many records in the first. For example, say your company has

several types of computers and several technicians, with each technician certified to work on some, but not all, of

the computers. Each technician can be related to more than one computer, and in turn, each computer can be

related to more than one technician.

• To track who can work on a given machine, you create a many-to-many relationship by adding the primary keys

from both sides of the relationship to a third table, called a junction or link table. The picture shows a typical

junction table, and you can see that its structure is relatively simple — a pair of primary key fields and some

related information.

• Now your data can answer questions such as, "Which computers did a given technician work on last month?"

Page 6: INF2070 Database 2

Relationships• Open the Relationships tab and put in the

tables.• Look where the Primary Keys are. The middle

one doesn’t have one.

Page 7: INF2070 Database 2

Primary Keys

• If you forget how to get the primary keys, do this: Click where you want it to go, then click the primary key button

Page 8: INF2070 Database 2

Make the tables have these Data Types:

If you don’t do this just right,The relationships will not workCorrectly later because you do Not have all the similar data Types to line up if you don’t.

Page 9: INF2070 Database 2

Open the Relationships tab

• Arrange your tables so they are in this order:

Page 10: INF2070 Database 2

More…

Click This

Grab the Tech ID primary key fromThe Techs table and drag it onto the Tech ID for the Computer Techs table

Page 11: INF2070 Database 2

Next Relationship

Move the Computer ID Primary KeyOver to the Computer Techs tableWhich does not have the Primary Key.

Page 12: INF2070 Database 2

You should have this:

Page 13: INF2070 Database 2

Now the fun part!

• Under the Computers table And Techs table we get a drop-down for Computer Techs

Page 14: INF2070 Database 2

Entries

• Create 10 entries for each of the tables. All of the data has to be the same

• I know its boring• But it is important for later!• Make up fake names and numbers to make it go

faster. Make sure you use a variety of makes, like Sony, HP, Dell, Toshiba, Acer, etc.

• For the serial numbers, they should be in the thousands, ranging from the number 1000 up to 8000.

Page 15: INF2070 Database 2

Queries

• Do you have questions that you want to answer with your data?

• For example:• Who worked on which computer?• Which computer needed work?• What computer had the most value?• Which computer was the last one repaired?

Page 16: INF2070 Database 2

Queries• Queries can answer those questions by assembling stored data from

your database, or by performing calculations with the data to provide further information.

• To answer questions, queries retrieve, filter, sort, and assemble data on command. Another important power of queries is to combine the data from several tables into a single view.

• When a query finds data and shows it to you, it can also process that data according to your instructions. A query can perform calculations using the data: What is the sales total minus shipping costs?

• A query can also remove data: Delete names of members who have not paid dues for 24 months. You should use caution when executing queries that change data, and consider backing up your data first.

Page 17: INF2070 Database 2

First, Go Here:

Page 18: INF2070 Database 2

Add a Query for The First Table

Page 19: INF2070 Database 2

Down Below!

• So what we want to do is to select the Table and the fields that we want to use from the drop-down menu. Use the fields listed below to make it look like this:

Page 20: INF2070 Database 2

Look Here

• In this case, we want to be able to look up a serial number under ‘Model’ that will show us which computer serial numbers that we made up are over 500. Just type > 500 right there.

Page 21: INF2070 Database 2

Next

• We want to look up any manufacturer that uses the letter S as the first part of their name. For example, Sony. We put what you see below in the table for Manufacturer.

Page 22: INF2070 Database 2

Under DataSheet view

• It tells me which computer starts with an S and is over 5000.

Page 23: INF2070 Database 2

Hit Save

• To save the table

Page 24: INF2070 Database 2

Now we want to see our table

Use an existing query as the record source of a form or report• In Design view, set the Record Source property to an existing query that you want to

use.• Open the form or report in Design view.• If the property sheet is not already open, press F4 to open it.• In the property sheet, on the Data tab, click the Record Source property box

Page 25: INF2070 Database 2

Next

• Do one of the following:• Start typing the name of the query that you

want to use.• Access automatically fills in the name of the

object as you type.• - or -• Click the arrow and then select the query that

you want to use.

Page 26: INF2070 Database 2

• Create a query as the record source of a form or report• In Design view, use the Build button (…) in the Record Source property

box to create a new query to use as the record source.• Open the form or report in Design view.• If the property sheet is not already open, press F4 to open it.• In the property sheet, on the Data tab, click the Record Source property

box.• Click .

Page 27: INF2070 Database 2

Our Report

• You should see something similar to this, depending on which information you included in your database:

Page 28: INF2070 Database 2

Save your Report!

• On the right-hand side of your screen, where all the tables and stuff are, right click on your report and see if you can print it!