Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Database

AS 91892 4 credits

Project 1 –
Creating a
Database

By J Murfitt
AS 91892 Database 4 credits

Project 1 – Creating a Database


Project 1 – Creating a Database
Database

Learning Intentions (Project Overview)


In this project you will learn:
• How to create a database from scratch.
• Learn how to organize your data for a flatfile database, and about selecting the correct data type
(text, number).
• Find out that you don’t need to include a field if you can calculate it.
• Look at merit requirements for organizing and naming things.
• Learn that phone numbers are stored as text.

This project should take you about 1 class to complete.

Quick Summary
Here is a quick summary of the tasks in this project. If you know what to do, just get on with it.
Otherwise, you will need to read the instructions on the following pages.

• Determine the data type (date, number, text, yes/no) for each piece of data you will store. (pg 2)
• Determine the size of each text field. (pg 3)
• List up all the fields and show their data type and size (design the structure of your database). (pg 4)
• You can calculate someones age using their birthdate, so you can leave out the age field (excellence). (pg 4)
• Create a new database and save it with an appropriate file name. (pg 5)
• Give the blank table an appropriate name (put “tbl” in front of the table name and don’t use spaces). (pg 6)
• Find out what AutoNumber data type are for. (pg 6)
• Set up the last name field as text with a maximum size of 20. (pg 7)
• Avoid using spaces in field names. (pg 7)
• Find out why you don’t leave a text field at 255 characters long (Merit). (pg 8)
• Short text vs Long text (pg 8)
• Set up the “Firstname” (max 20 characters) and “RichScale” (max 2 characters) fields and data types. (pg 9)
• Set up the “Birthdate” field and set it to display as a “medium date” (Excellence). (pg 9)
• Set up the “Height” field as a “byte” so it can store heights between 0cm and 255cm. (pg 10)
• Look at the difference between byte and single numbers (merit). (pg 10)
• Understand what a byte, integer, and long integer represent (Merit). (pg 10)
• Set up the “Gender” field with a field size of 1. (pg 11)
• Find out why a phone number is text, not a number. (pg 11)
• Set up the “MobilePhoneNumber” field and set it as text, 11 characters long (Merit). (pg 11)
• Set up “NetWorth” field with a “currency” data type (Merit). (pg 12)
• Set the “NetWorth” field to have no decimals places (Excellence). (pg 12)
• Set up “TaxEvader” field with a “Yes/No” data type. (pg 12)
• Set up “NetWorth” field with a “currency” data type (Merit). (pg 12)
• Set up “SourceOfWealth” field with size of 30. (pg 12)
• Summary of how to organise your information for merit, and present data effectively for excellence.
(pg 13)

By J Murfitt Page 1 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Scenario
Read this

1. The US President has vowed to catch and detain all known millionaires.
Track –
Fast

US President Millionaire

2. The FBI keep records of millionaires on paper, but are finding they
need to upgrade their system to a computerized database. They
have asked you to help them set up their database.
a. They need a system to keep track of each millionaire (see below
for details of what data they will store).
b. They need to have queries that lets them find certain millionaires
based on certain criteria.
c. They need a form to let them easily add, modify or delete
millionaires from the database.
d. They need a report to list up all millionaire information, but they
need the report divided into rich and filthy rich millionaries.

Data Types
If you know how to do the task(s) below go to the next heading (page 3), otherwise read the instructions below.
▪ Determine the data type (date, number, text, yes/no) for each piece of data you will store.

3. For an Achieved you need to “design the structure of the data”. So, here is a sample
paper record that the FBI used.

FBI Millionaire File Rich Scale


Last Name Trump A1 A2 A3
Fast Track –Do this

First Name James


B1 B2 B3
Rich Scale A1
C1 C2 C3
Birthdate 14th June 1946
D1 D2 D3
Age 72
E1 E2 E3
Height 190 cm
F1 F2 F3
Gender M
G1 G2 G3
Mobile Phone 027-111-2222
H1 H2 H3
Net Worth $3,100,000,000
Tax Evader Yes
Source of Wealth Hotels

4. Look at the data above and try to determine the data type of each field. Your choices are:
Date Number Text Yes/No

By J Murfitt Page 2 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

5. Here are the answers showing what each fields data type is. We will talk about why phone is “text”
rather than a “number” later on, but how many did you get right?

FBI Millionaire File


Last Name Trump Text
First Name James Text
Rich Scale A1 Text
Birthdate 14th June 1946 Date
Age 72 Number
Height 190 cm Number
Gender M Text
Mobile Phone 027-111-2222 Text
Net Worth $3,100,000,000 Number
Tax Evader Yes Yes/No
Source of Welath Hotels Text

Estimate the Size of Text Fields


If you know how to do the task(s) below go to the next heading (page 4), otherwise read the instructions below.
▪ Determine the size of each text field.
Fast Track –

6. Using the table above, estimate the maximum size of each piece of text data.
Do this

So how long do we expect someones last name to be? There is no exact answer for this, but 20
might be a good place to start. But what is the chance we will have someone with a lastname longer
than that? We could go for 50 just to make sure, but every extra character we add will cost us
money. If you have to store every persons last name, and you have 1,000,000 names all 20 characters
each, that is approximately 20 million characters that need to be stored. If you set each lastname to
be a maximum of 50 characters, you now need 50 million characters to store. In the event that the
storage device you use isn’t big enough to have 50 millions characters (this is just an example), then
you would have to buy another storage device.

So we will say each last name will be a maximum of 20 characters long (but we could change that
later if we wanted to). Mobiles are 10 characters, but could be 11.

FBI Millionaire File


Last Name Trump Text (20 char)
First Name James Text (20 char)
Rich Scale A1 Text (2 char)
Birthdate 14th June 1946 Date
Age 72 Number
Height 190 cm Number
Gender M Text (1 char)
Mobile Phone 027-111-2222 Text (11 char)
Net Worth $3,100,000,000 Number
Tax Evader Yes Yes/No
Source of Welath Hotels Text (30 char)

By J Murfitt Page 3 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Design the Structure of the Data


If you know how to do the task(s) below go to the next heading (page 4), otherwise read the instructions below.
▪ List up all the fields and show their data type and size (design the structure of your database).

7. For an Achieved you need to “design the structure of the data”.


Here is our plan for our data structure so far.
Note that we haven’t discussed format yet. We will look at that as we work through the next pages.
Fast Track –Read this

Field Name Data Type Size Format


Lastname Text 20
Firstname Text 20
RichScale Text 2
Birthdate Date dd-mmm-yyyy
Age Don’t require this field as we can calculate it
Height Number 1 decimal place
Gender Text 1
Mobile Phone Text 11
Net Worth Number Use $, use commas, 0 decimal places (when you talk
about billions of dollars, who cares about the cents)
TaxEvader Yes/No
Source of Wealth Text 30

8. For now we will leave our “design the structure of the data” at this level. Later on we will talk about
dividing the data up into different tables (normalization).

Fields that You can Calculate


If you know how to do the task(s) below go to the next heading (page 5), otherwise read the instructions below.
▪ You can calculate someones age using their birthdate, so you can leave out the age field (excellence).

9. Note that I have not included the AGE field. There are a couple of reasons for that.
a. If you enter in someones age as “15” into the database, in 2 years time their age will stillbe “15”
even though they are not that age.
Fast Track –Read this

b. If they are “15” in the database now, next month when they have their birthday the database will
still say they are “15”.

10. A better solution is to just record the persons birthdate. The computer knows what the current date
is, so it is easy to calculate a persons age if you know todays date and their birthdate.

11. For excellence you need to present the data effectively, which means to only include
relevant fields in a logical order. In other words, you don’t need the age field.

If you can calculate a value, you don’t need to


create a field to store it in.

By J Murfitt Page 4 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Create a Database from Scratch


If you know how to do the task(s) below go to the next heading (page 6), otherwise read the instructions below.
▪ Create a new database and save it with an appropriate file name.
Track –
Do this

12. Open Microsoft Access (the purple/pink icon with the key).
Fast

As a side note, you should now know why these worksheets all have a “purple/pink” theme!

13. Access is different to other programs because you need to save your work before you start, as
opposed to saving it after. Look at the right hand side and you should see a place to type in a file
name, and also select the folder to save it.

Click on the folder icon and chose the folder to


Fast Track – Do

save this database into.


this

Then change the filename to “Project 1”.

14. For a merit you need to organize things logically. This means you need to
a. Save your work in a well named folder.
b. Save your database with a logical file name.

15. Click on the “Create” button.

16. Incidentally, you can also just double click on the “Blank Database”
icon, but this will create a database with a generic name like
“Database1” into your home folder.

17. You should now have a blank table in


view.

By J Murfitt Page 5 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Setting up a Table
If you know how to do the task(s) below go to the next heading (page 6), otherwise read the instructions below.
▪ Give the blank table an appropriate name (put “tbl” in front of the table name and don’t use spaces).

18. Just as a reminder, a table is where you store all the information. For a student database, the table
would hold information about students. For a millionaire database the table will hold information
about our millionaries.

19. The first thing we need to do is tell the database what kind of fields will be required in this
database. Design view gives us more options, so click on the design view icon.
Fast Track –Do this

20. Give your table a name that starts with tbl


(for table), followed by a name that
describes the kind of information to store tblMillionaire
in the table. Since we are storing criminal
information, type in a name like
“tblMillionaires”.

21. Remember that organizing things logically is required for merit, so using correct
naming is something that can help you gain a merit.
a. This includes adding “tbl” before the name of the table.
b. You should also not use spaces in table names, which is another merit concept.

22. You should now see the


following blank table.

23. We will talk about what the ID


field is later on, but for now
just leave it as is.

Theory –AutoNumbers
If you know how to do the task(s) below go to the next heading (page 7), otherwise read the instructions below.
▪ Find out what AutoNumber data type are for.

24. Sometimes the “ID” field will be automatically added to a table.

25. The ID field is of type “AutoNumber”. When you have a few tables that are connected to each other,
you will need to use a uniqu number to identify records from another table. The “Autonumber” data
type automatically assigns a unique number to each record in the table. For now we don’t need to
use it, so you can either just leave the ID field as it is, or you can delete it if you want.

By J Murfitt Page 6 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Setup the Lastname Field, Data Type and Field Size


If you know how to do the task(s) below go to the next heading (page 8), otherwise read the instructions below.
▪ Set up the last name field as text with a maximum size of 20.
▪ Avoid using spaces in field names.

26. Let’s set up our millionaries “last name”, which will hold text. Note that if you don’t see the
same thing as shown below, click on the “Design View” button .
Track –
Do this

27. First, type in the field name, which is


Fast

“Lastname”. Note that you should


not use spaces, and should limit the
characters you use to just letters and
numbers (and underscore _ ). You Step 1 Step 2
will find that you can use spaces, but
they will cause you problems later on
so it is best to get into the habit of not Step 3
using spaces in field names.
Fast Track –Do this

28. Next, press TAB to get to the next column (its faster than using the mouse.
select the type of data this field will be. Text is selected by default, so we will leave it as is.

29. Finally, we need to tell the database how many characters the longest lastnamecould be. You have
to guess a little here, but a field size of 20 should be big enough. You can change this to make it
larger later on.

30. Also note thatwe don’t use spaces when naming a field. In reality you can actually
add spaces, but this will cause problems later on as the database can sometimes think
a field called “student grades” is actually two fields, one called “student” and the
other called “grades”. To avoid this problem later on, it is easier to not use spaces in
the name of the field. Not using spaces in a fieldname is something aimed towards
merit.

By J Murfitt Page 7 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Theory – Text field lengths


If you know how to do the task(s) below go to the next heading (page 8), otherwise read the instructions below.
▪ Find out why you don’t leave a text field at 255 characters long (Merit).

32. Let’s say you set the length of “Lastname” to 255 characters. This tells the database to set aside 255
characters for each last name, regardless of how long the name actually is. As a result, when you
have 1000 people in your database, you are using 255,000 characters (255 x 1000).

33. If however, you set the maximum length to 20 characters, you would use 20,000 characters (20 x
1000). The end result is that your database won’t take up as much room on the disk (20,000 is 8% of
255,000, which is a huge savings in disk space)

34. So, when setting text length, look at your original data and estimate what the longest possible text
could be. If you make it too small, then some names won’t be able to be entered into the system. If
you make it too long, you end up wasting disk space.

35. The good news is that you can change this setting after the table has been created.

36. So for merit you need to structure and organize your data, so you would need to set up
your text fields using an appropriate field size length. This would mean you would
change the default text length of 255 to an appropriate number.

Theory – Selecting the Right Data Type


If you know how to do the task(s) below go to the next heading (page 9), otherwise read the instructions below.
▪ Short text vs Long text (Merit)

37. When you select text you have some options.

For merit, you will need to select the correct data type from the dropdown list.

38. Short text can hold up to 255 characters.


Long text can hold up to 63,999 characters.

At this level we will only ever need to use short text.

By J Murfitt Page 8 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Setup the Firstname, RichScale Fields and Data Types


If you know how to do the task(s) below go to the next heading (page 9), otherwise read the instructions below.
▪ Set up the “Firstname” (max 20 characters) and “RichScale” (max 2 characters) fields and data types.

39. Set up the other fields as shown here.


Fast Track –Do

Firstname, Text, 20 characters


this

RichScales, Text, 2 characters

40. Remember to set the size of the text field as well.

Setup the Birthdate Field


If you know how to do the task(s) below go to the next heading (page 10), otherwise read the instructions below.
▪ Set up the “Birthdate” field and set it to display as a “medium date” (Excellence).

41. We want to know how old each


millionaire is. As explained
previously in step 9 we don’t want
to have a field for “Age”, but
instead we just need to store their
“birthdate”.

42. Add a birthdate field and set it as


Fast Track –Do this

“Date/Time”.

43. Setting the date format lets you


specify how to display the date.
For today set the format to
“Medium Date”.

44. For excellence you need to present the data effectively, which means to set the
format for any date fields to display appropriately.

By J Murfitt Page 9 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Setup the Height Field


If you know how to do the task(s) below go to the next heading (page 10), otherwise read the instructions below.
▪ Set up the “Height” field as a “byte” so it can store heights between 0cm and 255cm.
▪ Look at the difference between byte and single numbers (merit).

45. Add a “height” field.


Fast Track –Do

46. Set the field size to “Byte”.


this

47. The “Byte” database allows you to


store a whole number (no deimal
places) between 0 and 255. For
example: 180cm.

48. If you wanted to store height as 1.8m


instead, you would need to select
“Single” precision numbers which
allow for decimal places.

Theory – Bytes, Integers, Long Integers


If you know how to do the task(s) below go to the next heading (page 11), otherwise read the instructions below.
▪ Understand what a byte, integer, and long integer represent (Merit).

49. Just like we did for text, we are trying to reduce the amount of disk space our database will use. As
such, we need to tell Access what kind of number we will store as some number types take up more
space than others. To reduce confusion, we will just go over a few number types. There are more,
but we will ignore them for now.
Number Type Range Example
Byte Numbers between 0-255. We set height to byte. Not many
Can only be whole numbers (no decimals) people go over 255 cm tall.
Integer Numbers between minus 32,678 to 32,767. Used for large whole numbers under
Can only be whole numbers (no decimals) 32’ish thousand.
Long Integer -2,147,483,648 to 2,147,483,647 For large whole numbers.
Single Bigger than long integer, and can include For numbers requiring decimals,
decimal places. such as money etc.

50. A byte is one piece of memory, which can hold 1 character or 1 number between 0 and 255. Not many
people are over 255 cm tall so we can use a “byte”. . However, if we wanted to store height as
“1.8m” then we would have to use a “single”. The catch is that a single can hold very large numbers
so it would be more economical to use centimeters and use a date type of “byte”.

51. For an achieved you can leave your numbers as the default Integer or Long Integer,
but for merit you need to select the correct number type to show you are structuring
and organizing your data.

52. If you wanted to store “1.8” and used a byte, it would automatically convert to the whole number 2.

By J Murfitt Page 10 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Setup the Gender Field


If you know how to do the task(s) below go to the next heading (page 11), otherwise read the instructions below.
▪ Set up the “Gender” field with a field size of 1.

53. Gender is only going to be M or F, so 1 character


Fast Track –Do this

is enough.

Set up the gender fields as shown.

Gender, Text, 1 character

Theory – Not All Numbers Are Numbers


If you know how to do the task(s) below go to the next heading (page 12), otherwise read the instructions below.
▪ Find out why a phone number is text, not a number.
▪ Set up the “MobilePhoneNumber” field and set it as text, 11 characters long (Merit).

54. Phone is a number, but we chose to use text. There is a good reason for this. The
only time you want to use a number is if you need to perform a calculation on it. You
may be saying that you probably won’t perform a calculation on “Age”, but you could
actually create a query that lists all millionaires over 20, which is a calculation. You
probably won’t create a query to list all millionaires with a phone number bigger than 1234567. The
other reason is that phone numbers often have a zero in front of them (like 07 for Hamilton). A text
field lets you enter “07”, where as a number field will convert 07 to just the number 7 without the
zero. Setting a phone “number” as “text” is something you would do for a merit.

55. Create a “MobilePhoneNumber field”.

56. Set the mobile phone number field as text,


with a field size of 11.

57. You could also consider setting the field size to


something a bit bigger if you wanted to also
include a country code for international mobile
numbers. We won’t do that, but you could.

By J Murfitt Page 11 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Setup the Net Worth Field


If you know how to do the task(s) below go to the next heading (page 12), otherwise read the instructions below.
▪ Set up “NetWorth” field with a “currency” data type (Merit).
▪ Set the “NetWorth” field to have no decimals places (Excellence).

58. We have already talked about different types of


Fast Track –Do this

numbers. There is a special data type called


“Currency”. This sets numbers to automatically
display a $ sign in front, and automatically
defaults to 2 decimal places.

59. Create a NetWorth field and set its data type to


“currency”.

60. Set the “Decimal Places” to zero.


When you are talking about billions of dollars who cares about the cents!

61. Merit involves structuring and organizing your data, so setting a currency amount field
to “currency” is something you would do for a merit, as opposed to leaving it as a byte
or integer.
62. Excellence involves presenting data effectively, so setting an appropriate number for
decimal places in your table fields is something for excellence.

Setup the Tax Evader Field


If you know how to do the task(s) below go to the next heading (page 12), otherwise read the instructions below.
▪ Set up “TaxEvader” field with a “Yes/No” data type.

63. A tax evader is someone who avoids paying


Fast Track –Do this

their taxes. We will store either “Yes” or “No”


in this field.

64. Create a “TaxEvader” field with a data type of


“Yes/No”.

65. Set it’s format to “Yes/No”.

Notice that you could also set it as “True/False” or “On/Off”.

Setup the Source of Wealth Field


If you know how to do the task(s) below go to the next heading (page 13), otherwise read the instructions below.
▪ Set up “SourceOfWealth” field with size of 30.

66. Our final field is called “SourceOfWealth”, or where the money came from.
67. Create a “SourceOfWealth” field with a data type of “Short Text”, size 30.

By J Murfitt Page 12 of 13
AS 91892 Database 4 credits
Project 1 – Creating a Database

Structuring, Organizing the Data Logically


If you know how to do the task(s) below go to the next heading (page 13), otherwise read the instructions below.
▪ Summary of how to organise your information for merit, and present data effectively for excellence.

68. For merit you also need to show evidence that your tables were created properly
(structuring, organising and querying the data logically). You would also do the
following…
• Save your work in a well named folder.
• Save your database with a logical file name.
• Add “tbl” before the name of the table.
• Not use spaces in table names.
• Not use spaces in a fieldname.
• Change the default text length of 255 to an appropriate number.
• Select the correct data type from the dropdown list (short text, long text etc)
• Select the correct number type (byte, integer, long interger, single etc)
• Setting a phone “number” as “text”.
• Setting a currency amount field to “currency”.
• Use of validation rules or input masks to ensure correct data entered (we’ll talk about what
this means later on)
For excellence you should present your data effectively, so would do the following
• Including only relevant fields in table, and in a logical order (so we didn’t include age).
• Setting date field formatting options.
• Setting the correct number of decimal places to display.

That’s it for now.

Learning Outcomes (What You Should Have Learnt)


• How to create a database from scratch.
• Learn how to organize your data for a flatfile database, and about selecting the correct data type (text,
number).
• Find out that you don’t need to include a field if you can calculate it.
• Look at merit requirements for organizing and naming things.
• Learn that phone numbers are stored as text.

By J Murfitt Page 13 of 13

You might also like