Presentation on theme: "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."— Presentation transcript:
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
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
Here are the categories in the 3 tables. Go to Design View to put in the categories
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?"
Relationships Open the Relationships tab and put in the tables. Look where the Primary Keys are. The middle one doesn’t have one.
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
Make the tables have these Data Types: If you don’t do this just right, The relationships will not work Correctly later because you do Not have all the similar data Types to line up if you don’t.
Open the Relationships tab Arrange your tables so they are in this order:
More… Click This Grab the Tech ID primary key from The Techs table and drag it onto the Tech ID for the Computer Techs table
Next Relationship Move the Computer ID Primary Key Over to the Computer Techs table Which does not have the Primary Key.
Now the fun part! Under the Computers table And Techs table we get a drop-down for Computer Techs
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.
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?
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.
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
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.
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.
Our Report You should see something similar to this, depending on which information you included in your database:
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!