Learning Outcomes
Students should be able to:
Learning Outcomes
Students should be able to:
• create and modify a structure for a relational database (two tables);
• understand and use the following data types appropriately: − text; − numeric; − date/time; and − Boolean;
• understand the need for primary keys and foreign keys;
• use primary keys and foreign keys;
• understand and create the following relationships between tables:
− one to one;
and − one to many;
• add, amend and delete records;
• understand the need for and perform the following validation on fields:
− range check;
− presence check;
and − type check;
• create and modify data capture forms;
• create SELECT queries to search a database with a single criterion and with multiple criteria; and
• create and modify database reports from a table or a query: − using grouping and sorting; − inserting images appropriately; and − producing a professional database report.
Questions:
Why do businesses store customer information?
How is the information stored?
What type of information might a business store about it’s customers?
A database is a (large) collection of data items and links between them, structured in a way that allows it to be accessed by a number of different application programs. The term is also used loosely to describe any collection of data. In the past these may have been paper based but nowadays most will be computerised.
Databases are very widely used and many of us will have interacted with one – without necessarily being aware of it. If you have entered your personal details into a social networking site, they have almost certainly been stored in a database; if you have browsed an online retail site, product details will almost certainly have been retrieved from a database.
Here are some other contexts in which a database might be used:
• Your school might have a database that contains data about pupils, attendance, subjects and assessment marks;
• An employer might have a database that contains data about employees, job titles and salaries;
• The organisers of the Olympic Games might have a database that contains data about athletes, events and medals.
• Businesses might have databases about their customers, staff and suppliers.
The most common way to structure a database is as a collection of interrelated tables. This kind of database is known as a relational database.
A table is the name for each group of similar data with rows for each instance of an entity and columns for each attribute. We use a different table for each object in our database and then we link them together.
An entity is is simply an object that we hold data about and an attribute is a piece of information about that entity.
For example in a database about cars, the enity is car, the attributes would be the data we hold about the car, for example brand, model, colour, number of doors, miles on clock. An instance of an object would be the details for one particular car, for example Vauxhall, Insignia, Black, 4, 40,000.
There are a range of datatypes available to us when creating our database. This allows us to store data in the most suitable way.
Number- Allows us to store numerical values
Text- Allows us to store text information (Short/Long)
Yes/No- Allows us to store information with a check box to indicate yes/no
Date/Time- Allows us to store information about dates and times.
Currency- Allows us to store information relating to monetary values
Look-Up Wizard- Allows us to provide a pre-defined list of options, often used for title e.g. Mr/Mrs etc...
A Record is the basic unit of data stored in a data file. It is a collection of data items, which may be of different data types, all relating to the individual or object that the record describes and is treated as a unit for processing. In our previous example it would be all of the information about the car. A record is made up of many fields.
A field is one single piece of information about an object. It is another word for attribute as explained previously.
A primary key is a field that uniquely identifies an individual record in a table. For example if we have a table containing information about students, what information might we collect? Can any of these fields be used to uniquely identify each record? In some cases we will have to create an additional field such as candidate number to uniquely identify each record.
When the primary key from one table appears as a field in a second table, it is known as a Foreign Key of the second table.
Questions:
What is a database?
What is a record?
What is a field?
What is the purpose of the primary key?
Explain 2 datatypes.
We use entity relationship diagrams to show how different tables in our database are related.
Create an Entity-Relationship Diagram for the car rental database you have been working on.
To create a relationship we move the primary key from one table to another, where it is known as a foreign key. This piece of data can be used to retrieve all of the other information about an object if necessary.
There are three different types of relationships possible between objects.
1)One to One- A husband can have one wife, a wife can have one husband.
2)One to many- A football team can have many players, a player can play for one team.
3)Many to many- A subject can have many students, a student can have many subjects.
A query is a question used to retrieve selected information from a database.
For example we might want to ask the following questions in relation to our car database
Find all of the Ferraris.
Find all black cars.
Find all cars with less than 5000 miles.
Special computer languages, called query languages, are used to specify queries in a form that can be processed by a computer. A special piece of software called a query processor analyses the query and computes the answer.
= will find all matches of this numerical value
> will find all numerical values above this value
<will find all numerical values below this value
We can create queries on one or more fields by adding additional query criteria. We can also use or within a query to return any record with either value. For example everyone called "Sam" or "Fred" or everyone from "Sion" or "Omagh".
We can perform a query on a date. If we want to find someone born on an exact date we type in the full date 1/7/1999. To find everyone born in a particular month we would enter */7/* and similarly to find everyone born in a particular year we would use */*/1998. The * means this part of the date will be ignored when the query is running.
When querying a "Yes/No" Field we simply enter "yes" of "no"
A report is the presentation of selected data from a database.
Query results are not very presentable particularly when printed. We use a report to make the query results more visually appealing.
Once we have created a table we can also create a form to aid data entry. This improves the visual appearence of the screen and also will decrease the likelihood of data entry errors.
A macro is a small program to perform a repetitive task and which can be created and stored for later use by a user. This can cut down the amount of time the user spends clicking on options on a menu and assign all of those selections to one simple button. These can be used to print out pages or even link to other pages/documents.
This is a check made to ensure that data being entered to a database is valid, this will help keep our information accurate. We can check the data in a number of ways including...
Presence Check: This checks that some data has actually been entered into a field. If no data is entered the user will be given a message explaining that certain data is missing.
Range Check: This checks that a numeric value is entered which is in a certain range. For example we could use it to check the age entered by a user is under 110. We could also use it to check all users are over 18.
Type Check: This checks that the data entered is a certain type for example if we ask the user for their date of birth and they enter "bananna" the sime will not accept the data and ask the user to enter it again.
Length Check: This checks the length of a piece of text. For example, to ensure a post code is 7 characters long.
Create a set of 5 questions which can be skill based or theory based. Record the answers. Partner up and test each other. Switch partners 3 times.
A Mail Merge allows us to use the details from a database query and populate a letter or other document twith the relevant information. The guide below shows the main steps involved. There are also some examples on the past paper page.
You are going to create a database for a video/dvd rental shop.
Task 1- Create a table named "Customers" which has at least 8 fields about the customers of the business. Ensure appropriate data types are set for each field. When the table is created add in the records of 10 customers. Practice editing and deleting records.
Task 2- Create a form to allow easier data entry in the future.
Task 3- Create 5 queries on the customer table.
Task 4- Create a report for each query. Practice sorting and grouping reports in different ways.
Task 5 - Create another table in the same database called Movies. Add 5 suitable fields and 10 records.
Task 6- Create a form for the movies table to allow easier data entry in the future.
Task 7-Create 5 queries on the movie table.
Task 8- Create a report for each query. Practice sorting and grouping reports in different ways.
Task 9- Create a table called Rentals. This should store the date of the rental, the number of nights the rental was for and a Yes/No for Video returned. You must also add the primary key from your other two tables and create relationships.
Task 10- Print out a report showing the relationships between the tables.
Task 11- Add appropriate validation to your database.