Database Notes
Database Notes
Database Objects
An Access desktop database contains different types of objects:
Tables- structure made of rows and columns. Used to store data. Your data is held
in several tables.
Queries- used to retrieve specific data from a table. These bring together the data
from one or more tables and present the data.
Forms- used to fill in data to tables in a database. These allow more flexibility in
presenting data than that allowed in a datasheet. They are the most popular method for
viewing and managing data.
Reports - Allow you to create a paper-based presentation of your data for printing
or previewing on the screen.
TIP When starting Access, you will notice a list of template databases; for example,
Asset tracking (Web App) and the templates prefixed with the name Desktop. Desktop
asset tracking will create a desktop database. It is worth taking the time to look at a few
of these to get some ideas for creating your own applications.
Page 1 of 11
When you create a blank database, Access will open to display a new table called Table1.
This feature allows you to start using one of several techniques for creating blank tables,
which we will look at in the next chapter.
Click on the X to close the Table1 object.
The main ribbon will be displayed without any design objects in the database. The
Navigation pane displaying All Access Objects is empty.
Page 2 of 11
Ribbon Tabs
Access has five key ribbon tabs, although, as you open different objects, additional tabs
will become available, depending on the context. Following is a list of the tabs and their
usage.
File The File tab provides general options and settings for working in the product.
Home This tab is used principally for formatting, filtering, and selecting data while
you view the data.
Create This tab is used to create new objects.
External Data This tab is used to import, export, and link to external data.
Database Tools This tab is associated with general operations in maintaining your
database.
Page 3 of 11
File tab
The File tab has the following features:
Info Allows you to compact and repair your database and encrypt the database with a
password.
New Allows you to create a new database.
Open Provides a path to opening recently accessed databases.
Save If you have a design object open, this will save any changes.
Save As This has two functions. If you have an object open, you can save any changes
to the object, but more importantly, it allows you to save the database in an alternative
format.
Print Allows you to print an object that is open and active.
Close Closes the database.
Account Displays helpful information for connecting to online services.
Options The Access options are used to configure both the Access installation and
database-specific options.
Steps
1. Click File, Info, then Encrypt with Password. The following warning will then
most likely appear:
In order to apply or remove a password or encryption from a database, you need to open
the database using a very specific technique.
2. Click OK to close the message. Use the Open page to browse to or otherwise
locate your database.
Page 4 of 11
3. When prompted to select your database, ensure that you use the Open option to
Open Exclusive.
4. Click File, Info, then Encrypt with Password. You will then be able to create a
password and encrypt your database. Enter and verify your password. Click OK.
5. You will also receive the following warning when you choose this option. Click
OK.
Page 5 of 11
TABLES
Creating tables for your data
Table properties:
a) Field name: column heading
b) Datatype: determines kind of data to be entered in a specific field.
c) Description: gives explanation about a certain field. Not mandatory.
Note: each table needs a way of uniquely distinguishing each record in the table from
other records in the table. One of the simplest ways to do this is to allocate a unique
number for each row of data in the table; any field or combination of fields can be
designated as the primary key, as long as the data or combination of data values are
unique for each row in the table.
1. Click the Create tab, and then click Table Design in the Tables group. This will
open a blank table called Table1 in Design view.
2. In the first row, enter CompanyID for the Field Name, select AutoNumber for
the Data Type, and enter the optional Description property as Unique Identifier.
3. In the second row, enter CompanyName for the Field Name, select Short Text
for the Data Type, and enter the optional Description property as Name of the
company.
In Design view, when you click in each field name in the list, you will notice that the
Field Properties tabs (General and Lookup) will change depending on the data type for
the selected row. All fields have a Caption property, which can be used to display an
Page 6 of 11
alternative Caption or title for the Field (this is the fourth item in the Field Properties on
the tab named General).
4. Click the Caption property on the General tab for the CompanyName field, and
enter the text Company Name.
5. Click the CompanyID field, and then click the Primary Key button. This action
will display a small key icon on the row selector for the field.
6. Click Save on the Quick Access Toolbar (top left on the screen).
7. Enter the name tblCompany when saving your table, and then click OK.
8. Close the Design view for this new table.
9. From the Navigation pane, double-click your new tblCompany table to open the
datasheet and enter sample data (add at least two rows).
Steps:
1. Click the Create tab, and then click Table in the Tables group. This will open a
blank table called Table1 in Datasheet view.
2. Click the Click to Add drop-down list and select Short Text.
Page 7 of 11
3. Enter text over the default field name Field1, which will be highlighted with the
name for your ContactName field.
4. Click in the blank row in the ContactName field. This will save your change to
the field name. Then enter the contact name Kim Abercrombie.
5. Click Save on the Quick Access Toolbar. This will display a Save As window.
6. Enter the table name tblContact, and click OK to save the table.
Note: The two techniques for changing the design of a table in Design view or in Data-
sheet view are complementary, and you can switch between both when working on your
existing tables. When a table is open, click the Table Tools and select the Fields tab,
which will display the design options for Datasheet view. Alternatively, right-click a
table in the Navigation pane and choose Design view.
Choosing a field data type
One of the ways in which you can ensure that the data entered into your system is
correct is by choosing an appropriate type of data to hold. For example, if you hold dates
in a DateTime data type, then this data type will ensure that you can only hold a valid
date/time.
When adding a new field to a table, or changing the data type for an existing field,
you can choose between the data types listed in the following table.
Data type Description
Short Text Can hold up to 255 characters of text. This was called Text
in earlier versions of Access.
Long Text Large amounts of text. This was called a Memo field in
earlier versions of Access. These fields can also be used on
forms and reports to support Rich Text Formatting.
Number Whole number that has no decimal places (Long Integer),
floating-point number (Double), and fixed-point number (for
example, decimal (28,6), 6 decimal places).
Also supported are Byte and Integer for smaller whole
numbers, Single for less precise floating point numbers, and
for backwards compatibility, a Replication ID (older data
type).
Date/Time Date and time.
Currency Money.
Page 8 of 11
Autonumber Automatic number, default long integer, which is added as
you start entering text in a new record.
Yes/No True, False (default is False).
OLE Object Older field type for storing an image or document.
Hyperlink Stores hyperlinks to local or Internet documents and data.
Attachment Can hold multiple copies of other documents such as
spreadsheets and PDF files for each record.
Calculated A calculation combining fields together. For example,
adding or multiplying values from other fields.
Lookup Creates a foreign key lookup to data in another table.
QUERIES
A select query allows you to bring together data from a number of tables and present the
data in a single view.
Creating a query
Steps:
1. Click the Create tab, and then click Query Design in the Queries group.
2. In the Show Table dialog box, click to highlight the Customers table, and click
Add.
3. Click Close to close the Show Table dialog box.
TIP You can double-click the table name to add it to the diagram, rather than clicking the
Add button. Either double-click the * (asterisk) above the list of field names or drag the *
onto the query grid. This adds Customers.* to the query grid.
Page 9 of 11
Creating a query by selecting specific fields
When you create a query by selecting only the fields of interest, this has the
advantage of improving the speed of the query and makes it easier to maintain the
information being displayed without including a number of fields that are not of interest.
Access supports several techniques for adding individual fields and groups of fields to a
query.
Steps:
1. Click the Create tab, and then click Query Design in the Queries group.
2. In the Show Table dialog box, click to highlight the table of your choice e.g.
Customers table and click Add.
3. Click Close to close the Show Table dialog box.
4. Double-click the field Customer ID and then CompanyName. This will add the
two fields to the query grid.
5. Click on “Run” on the design tab.
6. Click Save, and save your query as qryMultipleCustomerFields.
7. Click OK.
8. Close the query.
Steps:
1. From the Navigation pane, right-click the query qryAllCustomers and select Design
view.
2. Double-click the two fields: Country and CompanyName (you will need to scroll
down the table to display both fields). Add both fields to the query grid.
3. In both fields, clear the Show check box.
4. In both fields, select the Sort row and select an Ascending sort.
Page 10 of 11
5. In the Criteria row below the Country column, enter the word france and click any
other area of the screen. Access will add quotes around your text.
6. In the Criteria row below the CompanyName column, enter co* (the * means ignore
any remaining letters, and all company names beginning with the letters co are selected).
Click any other area of the screen. Access will change the syntax to like “co* “.
7. Click Save to save your query, and use the View icon on the Design tab to select
Datasheet View to display the results.
8. Close the query.
This query will sort the data by Country and then by CompanyName (data is sorted from
left to right when you have more than one field to sort on). The data will be filtered to
show records with an exact match to France in the Country field, and a partial match to
any CompanyName beginning with the letters co.
FORMS
REPORTS
Reports provide a presentation of data which is easily printed or saved; for example, in a
PDF format. Like forms, reports can support either a tabulation of records or a single-
record layout. A report can also be embedded on another report to create a parent/child
presentation; the embedded report is called a subreport.
A report can be displayed by using one of four views:
Report view Displays a continuous unpaginated report
Print preview Displays the data with pagination as it will appear when printed
Layout view Allows the data to be viewed and the layout adjusted
Design view Allows the report design to be changed
Page 11 of 11