Introduction to Databases with more than one table

advertisement
Year 9 Information Technology
Introduction to Databases with more than one Table
(Or Making your Friends Database more useful!)
Flat file versus Relational
A flat file is a database that only has one table. For example; your Friends database is currently a flat file. Databases
that consist of more than one table that are linked are called Relational Databases.
The advantage of this is that it reduces the need to keep the same data in different places when it is used for different
purposes. For example; in a library system, information is kept about books. That is one table. Information about library
members would be kept in another table. When a book is loaned out, information from these two tables is linked to a
third table that records the loan.
Task
In this exercise you’ll develop your Friends database further by adding a table to kept records of your DVD collection
and adding a further table to record the loaning of these to friends.
The instructions below assume that you are already familiar with some of the aspects of Filemaker as a result of doing
the creating a Friends database task. Please check with your teacher if you unsure.
Adding to the Friends table so that it can be linked to other tables
1.
In you’re YourNameFriends database open up the Friends table. Add another field called Friend ID. Make this
field the Key:
 Highlight the Friend ID field.
 Click Options.
 Click the Validation tab.
 Select the Unique value check box.
2.
Enter Browse mode and add the Friend ID field to both the Friends Form and Friends List layouts.
3.
Enter data into the Friend ID field for each record. S
Suggestion: Make the field an abbreviation of the person’s name.
e.g. Fred Bloggs = BlogF, being the first 4 letters of his surname and his first name initial.
Creating a new table for your DVDs
4.
Create a new table in your YourNameFriends database.
 In the Manage Database window click the Table tab.
 Type DVDs in the Table Name text box.
 Click Create.
5.
Create the fields for the DVDs table.
 Click the Fields tab.
 Select the DVDs table from the Table drop-down list
Each record in this table will be about a DVD in your collection. Suggested fields:
DVD ID (this could also be an abbreviation of the title)
DVD Title
Genre (e.g. Comedy, Action, Musical, Animation, etc.)
Rating (e.g. G, PG, M, MA etc.)
Running Time
Year of Release
You may like to add a few more fields of your own
Make the DVD ID the Key. You should use value lists for fields such as Genre and Rating. Choose appropriate
field types for the other fields.
6.
Create records for the DVDs in your collection.
Use the data that you should have already collected (around 10 records is fine)
7.
Rename the DVDs Layout
 Rename this layout to be DVDs Form.
10/02/16 Document1


8.
Place a heading of the same name in the Header of the Layout
Create Footer with your name displayed in it.
Create a DVD List layout
You should be able to view the complete list of your DVDs in this layout. Each record must be on a
single line.
Place a heading of the same name in the header and your name in a footer.
Creating a Loans Table
9.
Create another new table. This will be the Loans table. Add the following fields.
DVD ID –
Friend ID – add a value list to this field that looks up the list of Friend ID in the Friends table.
Date Borrowed
Due Date – this is a Calculation field (Date Borrowed +7)
Date Returned
10.
Add a value list to the DVD ID field in this table that looks up the list of DVD ID in the DVDs table.
 Highlight the DVD ID field (Still in Manage Database Window and Fields tab)
 Click on the Options button.
 Click on the Validation tab in the Options window that now appears.
 Select under the Require heading Member of a value list and then Manage Value lists from the
drop-down box alongside.
 Click on New.
 Enter DVD ID into the Value List Name box.
 Select Use Values from field
 Select the DVDs table from the drop-down
list at top of left column.
 Highlight the DVD ID field in the left column
 Select the DVDs table at top of right column
 Highlight DVD Title in the right column
11.
Add a value list to the Friend ID field that looks up the list of Friend ID in the Friends table.
Follow the same procedure as in the previous step.
Linking the tables (or creating relationships)
12.
Create a relationship between Friend ID in the Loans table and Friend ID in the Names table.
 Click the Relationships tab in the Manage Database window
 You should see boxes representing the 3 tables you have created
 Click and drag the Friend ID field in the Loans table across to the same field in the Friends table.
 Double click on the box in the middle of the line that now joins the 2 tables together.
 Select the boxes as shown here.

13.
Click OK.
Create another relationship between DVD ID in the Loans table and DVD ID in the DVDs table.
 Follow the same process as in the previous step.
Create records in your Loans Table
15.
Rename the layout that has been created as Loans Form. Add a header and footer.
16.
Create a new Loans List layout. Add a header and footer.
14.
Attach drop-down lists to the Friend ID and DVD ID fields in each of the Loans table layouts.
10/02/16 Document1
15.
Add fields from the Friends table to the Loans Layouts.
This will enable you to see your friend’s full name displayed alongside the loan.
 Enter Layout mode.
 Go to the Loans Form
 Click on the Field tool and drag onto the layout.
 Select the First Name field from the Friends table.
 Click OK
 Do the same to display the Surname field
16.
Follow the same process as in the previous step to display the DVD Title in the Loans Layout
17.
Create records in your Loans table (15-20 max). Choose the data carefully. There should be a range of dates
borrowed, but some borrowed on the same day. There should be some DVDs that have been borrowed, returned
and borrowed again, and some that have yet to be returned.
Note: You should now notice that as you select a Friends ID or the DVD ID to Record a loan the friends name
and DVD title automatically appear.
Performing Queries (Finding information)
Create the queries listed below. In creating each query, create a suitable layout which include in the current date and
your name. Create scripts so that each query can be run automatically. Print out each query as a report.
18.
A list of all Loans, showing the DVD title, Person’s Full Name, date borrowed, date due, and whether returned
or not. Sort by the date borrowed.
19.
A list of all the DVDs that have not been returned showing the title, person’s name, person’s phone number and
due date. Sort by the person’s name and then the date borrowed.
Making Scripts: Your teacher will show you how to create a script. Generally you perform the Find and the
Sort first then follow the steps:
 From the Scripts menu select ScriptMaker
 Click New
 Name the Script
 Insert script steps as required. These will depend on what you want to do. Four basic things to
remember
 What records do I want to find?
 What layout do I want to go to?
 How do I want to sort the records?
 Which mode do I want to display the result in?
10/02/16 Document1
Download