Sandra Access 2013 Tutorial Part 1
Sandra Access 2013 Tutorial Part 1
Access 2013
Tutorial Part 1
An Introduction to Access 2013
Creating a database
Introduction ........................................................................................................................... 2
Lets Get Started ................................................................................................................... 3
The Navigation Pane............................................................................................................. 4
Compact and Repairing files ................................................................................................. 5
Back Up Database ................................................................................................................ 6
Creating Tables..................................................................................................................... 7
Creating Relationships and Enforcing Referential Integrity .................................................. 13
Adding Data ........................................................................................................................ 18
The database being constructed is for a basic sales system and contains the following tables
and attributes with the stated data types and sizes:
Notice that the names of each attribute are typed with no spaces between the words, but
each new word starts with a capital. This is called CamelCase. Dont use spaces in field
names because different database programmes treat these differently and it can also cause
problems with creating queries later.
Also notice that each attribute name has the table name in front of it. This is not always
done, but is useful when the same field name may be used for different tables. For example,
this database also has an Employee table where the employee name is included. By
including the table name in front of the field name, it is easier to determine which field is
being referred to when using queries and reports.
Give the database a suitable name BasicSalesSystem and choose a folder to save it to by
clicking the folder icon.
Click Create
Select the Create Tab and Click the Table Design button
The CustomerID is going to be the Primary Key, so with the CustomerID field selected, click
the Primary Key button on the ribbon. Notice the key which now appears next to
CustomerID
In the Field Properties Box, change the Field Size to 50, and Required to Yes
By changing the field size to 50, the length of a name is limited to 50 characters. This
improves the efficiency of the database so extra space isnt used when it isnt needed to.
By changing the required property to Yes improves accuracy of the database because this
field is now requires a first name to be entered into the database.
Now add the rest of the Attributes with the following properties
Save and name the table Customer if you havent already named it. This can be achieved
by closing the table, right clicking on the table name tab, or by using the save button
To create the relationships between the tables requires a link to be created between the
primary key in one table and the same data item in the other table.
The Primary/Foreign key link allows any of the information in the primary keys table to be
accessed via the link. For example, because the Sale table has the CustomerID in it, a
query run across the Sale and Customer tables will allow the customer name to be displayed
with the details of the sale. More about this later.
One of the advantages of the relational database design is to ensure that only valid data can
be entered for the foreign key data items. This is done by enforcing referential integrity
which means that before a value can be entered into the foreign key attribute, it must already
exist in the table containing the primary key. This means when entering data, care has to be
taken about the order the data is entered: first enter data in the primary key table and then
enter the data in the foreign key table. For this tutorial database, data will need to be added
to the Customer, Inventory and Employee tables before anything can be added to the Sale
table.
First check that all tables have been closed it is not possible to add a relationship to a table
which is still open and Access will tell you so!
To create the relationship, click and drag the primary key attribute to the appropriate attribute
in the related table:
Notice that the Relationship Type is One-To-Many, This means one CustomerID could relate
to many Sale records.
Click Create
Notice the link which has now been created between the customer table and the Sale table.
The 1 at the Customer table end means 1 customer record could be related to many () sale
records.
Solution
This means there is a mismatch between the data size or type for the fields selected.
Solutions
Option 2: Incorrect data type or size for either the primary key or the foreign key
Check the data type and size of the fields
Note 1: Name of attributes dont have to be the same (eg may have InventoryID and
InventoryCode). As long as the data type and size are correct, this wont cause a
problem
Note 2: The data type and size must be the same for both fields eg number and long
integer, text and size 6. The only exception is where the primary key is an
Autonumber the foreign key field must be of type Number and Long Integer.
If a field has a caption it will show in the field name line, otherwise the field name will be the
name given to the field itself eg
First Name is the caption for CustomerFirstName field, but CustomerLastName is the field
name for the customer last name as there is no caption provided.
Click on CustomerFirstName and type Bill, tab to CustomerLastName and type Smith etc.
The CustomerID does not need to be typed because it is an AutoNumber and is
automatically included by Access.
When you have entered the complete record (line) and move to the next line, Access
automatically saves the entry to the database.
If you make a mistake and delete a record, the autonumber will skip the number for the
deleted record which can mean a gap in the numbering of the ID field. If this happens to
you, dont worry about it but do remember this has happened because other screen shots
activities in later tutorial may have different details because of this.
Make sure the data is added to the Customer, Inventory and Employee tables before adding
data to the Sale table (ie add data to the Sale table last)
Inventory
InventoryID InventoryName InventoryDescription
1 Hammer
2 Screwdriver Phillips
3 Saw
4 Spanner
5 Pliers
Employee
EmployeeID EmployeeFirstName EmployeeLastName EmployeeExtension
1 Joy Smith 123
2 Jack Trigger 124
3 Gary Wood 125
4 Gail Smith
5 Lee Drake 126
Sale
SaleID CustomerID InventoryID EmployeeID SaleDate SaleQuantity SaleUnitPrice
1 1 1 2 12/1/15 3 15.99
2 1 3 5 6/2/15 1 17.99
3 2 2 1 14/2/15 4 6.95
4 4 4 4 28/2/15 1 9.99
5 3 4 2 12/3/15 5 9.99
Inventory Table
Employee Table
Sale Table
If the value included in one of the above fields isnt in the appropriate primary table, Access
will not let the record be added or changed in the table until it is fixed.
Eg for SaleID 5 change the InventoryID to 6 and then either save the table or select a
different record. The Inventory table does not contain an inventory item with an ID of 6 so the
record cannot be changed. Two possibilities exist here either ID 6 is incorrect or ID 6
needs to be added to the Inventory table. If the Inventory table needs to be updated, the
record in the Sale table needs to have correct data added to it before the Inventory table can
be corrected.