BerryMill A Level IT

You might also like

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

INFORMATION

TECHNOLOGY
Creating a database
structure
Contents
Create a database file 3
Import data 4
Copy the data file to make the tables 8
Delete unnecessary fields 9
Assigning data types 9
Change field sizes 10
Specify date formats 11
Changing decimal places 11
Apply input masks 12
Apply presence checks 12
Apply range checks 13
Apply value lookups 13
Assign primary keys 14
Assign foreign keys 15
Combo box foreign keys 15
Foreign keys without combo boxes 21

2|Page
Create a database file
Before you create a database in Microsoft Access you firstly have to save the file. To do this follow
the steps below.

1. Open Microsoft Access and select Blank Desktop Database from the options.

2. You will be asked to name the database file. Enter a suitable name and use the folder icon to
navigate to where you want to save the database then click on Create.

Once you have done this Access will open your file.

3|Page
Import data
You will be required to import supplied text files into your database. You should make sure that you
have saved a copy of the data files in your folder before you start. To import the text file(s) into
Access follow the steps below.

1. Select the External Data tab on the ribbon and then click the Text File icon as shown below.

2. When the import wizard opens browse to where you have the text file you want to import and
click on the text file. Click OK.

4|Page
You do not need to change anything at the next stage, so just click Next.

3. Make sure you place a tick in the First Row Contains Field Names text box. Click Next.

5|Page
6|Page
4. You do not need to do anything at the next stage so just click Next.

5. Select No Primary Key then click Next.

7|Page
6. At this stage you can change the name of the file, make sure you know it is a data set. Click Finish
and close the last dialogue box.

7. The data set table will be created, and it will appear in the left hand pane.

8|Page
8. Repeat the process to import any other data files.

9|Page
Copy the data file to make the tables
You now need to make a copy of the table(s) so that you can format them in line with the table
design you have produced. To do this follow the steps below.

1. Right Click the data table that contains the fields you require and select Copy from the menu.

2. Right Click and select Paste. Select Structure Only and name the table then click OK.

3. Repeat the process until you have created the basic structure for all of your tables.

10 | P a g e
Delete unnecessary fields
You now need to delete all of the fields that are not required in each table so that you are left with
only the fields specified in your table design.

1. Right-click the name of the first table and select Design View

2. Click to the left of the field you want to delete and select

Assigning data types


You now need to assign the relevant data types to each field in your tables.

Select the relevant data type from the Data Type options.

11 | P a g e
Change field sizes

The default size for fields with a Short Text data type is 255. You need to change this to match the
sizes identified on your table design. To do this follow the steps below.

1. Click into the first field you want to change. Change the field size property to apply the field size
listed in your table design.

2. Change the field size of all fields with a Short Text data type to match you table design.

12 | P a g e
Specify date formats
To change the format of fields with a Date/Time format follow the steps below.

1. Click into the relevant field to select it. Display the Format menu and select the relevant
option. In this example Short Date has been selected.

Changing decimal places


For fields that have a Number or Currency data type you need to change the format of these to
match your table design. To do this follow the steps below.

1. Click in the field you want to change to select it. In the properties section display the Decimal
Places drop down menu and select the number of decimal places you want.

13 | P a g e
Apply input masks
Input masks need to be applied to the relevant fields. In this example an input mask has been applied
to the Postcode field.

1. Click into the relevant field to select it. In the properties section enter the appropriate input
mask as shown below.

Apply presence checks


Presence checks need to be applied to the relevant fields. In this example a presence check has been
applied to the PaymentDate field.

14 | P a g e
Apply range checks
Range checks need to be applied to the relevant fields. In this example a range check has been
applied to the PaymentInstalments field. The range is at least 1 and no higher than 4.

Apply value lookups


Value lookups need to be applied to the relevant fields. In this example a value lookup had been
applied to the RelationshipToStudent field.

15 | P a g e
Assign primary keys
Each table must have a primary key in order for the tables to be linked together. To assign a Primary
Key follow the steps below.

1. Click into the field you wish to use as the Primary Key field. Select the Primary Key icon on the
toolbar to assign the primary key. A key should appear in the grey box next to the field name as
shown below.

2. To assign a Composite Key, click the grey box next to the first field heading and using the mouse
drag down to select the second field. Apply the primary key as before by clicking the Primary
Key icon on the toolbar.

16 | P a g e
Assign foreign keys
Foreign keys need to be assigned.

Two methods of assigning foreign keys are shown. The first automatically creates the relationship
and provides a drop down box from which the user can select values. The second shows the manual
creation of relationships with no combo box. The first method is the most user friendly and can save
time and effort when it comes to the forms later.

Combo box foreign keys


1. Go the field that is a foreign key

2. Select Lookup Wizard

3. Select “I want the lookup field to get the values from another table……” and then select Next.

17 | P a g e
4. Select the table where this field is the primary key and then select Next. In this example it is
tblStudent.

5. Move across the ID field and any others that you think would be useful in the drop down box and
then select Next.

18 | P a g e
19 | P a g e
6. Select the field you want to sort if you want to sort the key and then click Next

7. Remove the tick to unhide the key and click Next.

20 | P a g e
8. Select the primary key and click Next.

9. Click Finish

21 | P a g e
10. Click Yes

11. Select Lookup and then change Limit To List to Yes.

12. Click Save to save the table.

13. Close the table

14. Select Database Tools and then Relationships

22 | P a g e
15. Double click the relationship line between the two tables

16. Tick all three boxes and select OK

17. Repeat for all foreign keys.

23 | P a g e
Foreign keys without combo boxes
If you do not wish the foreign keys to have a combo box, you can create the relationships using this
method.

1. Select the Database Tools tab on the Ribbon.

2. Select the Relationship icon on the Ribbon.

3. Hold CTRL down on the keyboard and select the tables you require from the dialogue box and
click Add to add them to the relationship window.

24 | P a g e
4. Click the primary key in the first table and holding the mouse button down drag it and drop it
over the corresponding field in the other table.

5. Check the boxes to Enforce Referential Integrity, Cascade Update Related Fields and Cascade
Delete Related Re cords as shown above. A one-to-many relationship will be created.

6. Create all of the foreign key relationships

25 | P a g e
26 | P a g e
Note: If you make a mistake delete the relationship by right-clicking the relationship line and
selecting delete.
If your tables do not show in the relationship window right-click and select Show All.

27 | P a g e

You might also like