0% found this document useful (0 votes)
13 views

Database Notes

A database is an organized collection of related data that can store and manipulate information across multiple tables, allowing for efficient data retrieval and reporting. Relational databases reduce data duplication by linking related tables, while tables consist of records (rows) and fields (columns) that store specific data types. Various professionals, including database designers and administrators, manage databases, which are widely used in applications such as airline booking systems, government records, and medical records.

Uploaded by

tinasherufudza18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Database Notes

A database is an organized collection of related data that can store and manipulate information across multiple tables, allowing for efficient data retrieval and reporting. Relational databases reduce data duplication by linking related tables, while tables consist of records (rows) and fields (columns) that store specific data types. Various professionals, including database designers and administrators, manage databases, which are widely used in applications such as airline booking systems, government records, and medical records.

Uploaded by

tinasherufudza18
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 99

DATABASE

What is a database?
• A database is defined as an organized
collection of related data (information).
• It can be defined as a database is defined as
a collection of objects, such as tables, forms,
queries and reports.
A database will be able to store data in a
structured manner across multiple tables, use
queries to locate specific information
according to given criteria, produce detailed
(on-screen or printed) reports, perform
What are databases used for?
• Databases are used to group and format data
and then extract information from that data.
Examples of databases usages include: - A
phone directory
-Criminal databases used by the police to keep
track of known criminals
-Patient records are kept on a database within
the health system
-Tax details are kept on a government
What is a relational database?
• Unlike a single table database, a relational database is
able to store and manipulate data across multiple tables.
• By utilising multiple tables, a relational database reduces
unnecessary duplication of data. For example, when using
a large database to store customer information, including
addresses, it is likely many individuals will live in the same
street and share other common parts of the address.
Rather than storing the same street name, county,
state, etc, over and over, this information can be stored
in a separate table. As each new customer is added to the
database, only the unique house number needs to be
recorded.
What is a table?
• Tables are used to store the data in a structured
and organised format. As previously mentioned,
tables are similar to those of Word and Excel, in
that they contain rows (records) and columns
(fields).
What is a record (row)?
• A record applies to data entered into a single row of a
table. All data in that row would belong to an individual or
item. A record would normally include a unique ID
number, Name, Description, plus other relevant
information. With each new record, a new row is created.

What is a field (column)?


Each column (previously known as a ‘field’) is used to
define what specific information is to be entered into that
particular column. A column titled ‘Street’ for example
would signify this to be the point in a record to enter in
the Street name when creating each new record.
What is data?
• Data is the information entered into tables within the database.
Databases are used daily by large corporations, small businesses
and individuals, often without people realising they are using a
database. Even something as simple as entering contact details
into the ‘Contact’ or ‘Address Book’ section of an email client such
as Microsoft Outlook / Outlook Express, involves entering data into
a database.
• Data entered will generally be alphabetical (names / addresses)
or numerical (Dates / Currency), however Access is also able to
store other forms of data, such as links to websites, documents
created in other packages (OLE) as well as file attachments (files &
images).
• Data can be entered into the database manually, via the
keyboard, imported from or linked to external sources or even
The difference between data and
information
• Data: - Facts, statistics used for reference or
analysis. - Numbers, characters, symbols,
images etc., which can be processed by a
computer - Data must be interpreted, by a
human or machine, to derive meaning
• Information: - Information is interpreted data
- Data that has been processed to produce
meaning.
Data types
• Data types define what type of data will be entered into
each ‘field’ (column) in a table. If for example the date
‘12June2007’ or Price 1.59 is entered into a field, which
by default is set as ‘Text’ the input characters will remain
unchanged.
Common uses of large-scale databases
• These include:
Airline booking systems: These systems maintain a database of
all the seats on all the available flight, allowing passengers to be
quickly booked onto fights to their destination.
Government records: Governments all over to world rely on
multiple large databases in order to function. Tax records, criminal
records and social security all require sophisticated database
systems.
Bank account records: Banks require extremely reliable
databases in order to keep track of all their customer account &
log transactions.
Hospital patient details: Medical records are being moved onto
a database system. This system should allow your medical history
to be instantly available wherever you require treatment.
Each table in a database should contain data related to a
single subject
• A database can have many tables. A table should only contain records
related to a particular subject. For example you may have a table called
customers containing information about your customers with a separate table
called orders. You can then link the tables by creating a relationship,
connecting each customer with their associated orders.

Each field in a table should contain only one element of data


• Each field should contain the smallest data element. For instance if you are
storing a person’s name, use one field for the first name and another field for
the second name. This means that at a later date you could manipulate the
data to sort by the second name. For the same reason split the details of an
address into as many smaller parts as possible so that later you could search
by state/region , by post code/zip code or even by country if you are
maintaining an international list.
Database designers, database administrators and
database users
• Different groups of people design, maintain and use large scale
databases.
Database designers: These are highly skilled database
professionals with an in-depth knowledge of exactly how the
database works, including its overall function and details
programming.
Database administrators: This group administer the day to day
operation of the database and make sure that the data is kept
secure. These provide technical backup to users of the database.
They provide access to specific data for appropriate users. In the
event of a computer crash the database administrator will be
responsible for restoring normal computer operations.
Database Users: The users are responsible for routine, day to
Saving a table
• Before a table can be used to store information,
fields must be added to a table, named, given the
correct Data Type and formatted appropriately.

Fields are used to separate and organise data into


specific fields (columns), for example a First Name
field would store the first name for every individual
record entered, as would Surname, Birth Date
fields, etc
Click on the Save button on the Quick Access
Toolbar or press the Ctrl+S keys to save the
Adding and renaming fields
• Double click into the Add New
Field cell (to the right of the ID
field). NOTE: Be sure to click on
the top cell within the column,
NOT the second cell down.
• Adding fields using the Datasheet View is straight forwarded enough,
however only part of the setup is done in this view. Fields need to be
formatted according to the data type, input masks need to be set and other
properties need to be configured.
Using Datasheet View
• Every object (Table, Form, Query, Report, etc) in an Access database will
have at least two main views, Datasheet View and Design View. Datasheet
View displays the object as it would be seen in daily use, its working mode so
to speak.

Using Design View


• Design View displays the workings behind the object, as seen by the
database designer. The efficiency of the database and the way it handles data
input / output are controlled by the properties configured in Design View.
NOTE: The View button image displays the opposite view button to the
current view, i.e. if in Datasheet View, the Design View button is displayed.
Table Modification and Navigation
Adding Fields - Design View
• Adding fields to a table in Design View offers the ability
to add additional field names, select the appropriate data
types and configure properties for each field.
• In the Field Name column, move to the next available
row below Part Description.
NOTE: Using the Enter key when working in (Table)
Design View moves the pointer (right) to the Data
Type column, at which point, a Data Type would
normally be selected. Pressing Enter again would
move the pointer (right) to the Description
column, where a brief description as to the purpose
of the field would be entered. A final Enter would
then move the pointer to the next available row,
ready to input a new field name, repeating the
process.
Data Type - Overview
• A Data Type determines the values that can be accepted
and stored within a particular field, the operations that
can be performed, i.e. searching, querying and sorting of
data, etc, as well as setting storage limits on the space to
set aside for each value
• Although Access has the ability to automatically select
data types based on the information entered into fields,
there are occasions when the information entered may
mislead Access, resulting in the wrong Data Type being
selected
TIP: When adding field names to a table, it would be
prudent to do so in Design View and configure data types
manually, alleviating the need for Access 2007 to
Data Type - Descriptions
• There are several data types to choose from and
one or two, i.e. Text has the ability to accept and
store most data input, however data output,
searching, producing reports, calculating value, etc,
will present a problem.

The following Data Type table provides a description


of the types of data each Data Type can store,
format and perform searches and calculations on.
Adding records to a table
• On the left side of the table there is a small * symbol. This symbol
represents the record (row) currently selected. As more records are
entered into the table or as you navigate through the table, this
symbol will provide a confirmation of the exact row you or your
pointer is in.

To the right of the * symbol, New is displayed just below the ID


field name, signifying this row represents a new record. Data
cannot be typed into this column, as by default this is an ID
column with an AutoNumber Data Type. NOTE: The
AutoNumber Data Type automatically generates a unique,
sequential number for each new record entered so data entry into
this field is restricted.
Navigating through records within a table
• The record navigation bar is located and will only visible from the
bottom of the object window when, for example, a table is open to
view.
Field Properties, Validation & Input Masks
Field Properties
• Field Properties amongst other things, control how information is displayed, specify default values,
prevent incorrect data entry and sorting information. Options available will depend upon the data type
of each field.
• Open access and open the Cheltenham database.
• Open the table called Cheltenham
• With the table now open, click on the Design View button and switch to Design View.
• Click within each of the Field Names, paying
attention to how the Field Properties section (at
the bottom of the screen) changes according to the
Data Type.
TIP: Note the light blue shaded box, displayed to
the right of the Field Properties section. As you
move through the various properties, this box will
provide some useful tips about each property.
• The list displays the options available for the Currency data type according to the Regional settings
of your system.
• Select the General Number 3456.789 from the list.
• Select the Short Date option, and then click on
the Next button. Although it is highly unlikely in the
case of a date, that you would wish to change the
placeholder character, you have the ability to
substitute the character, inserting others in their
place. Do not make any changes in this case,
simply look at what options are available.
• Notice the new Input Mask appears. From this point on, each new
record added to the database will require the operator to follow
the format. No other format will be accepted.
Using Input Masks with Text data type for example, is useful when
storing phone numbers. As calculation is not needed, phone
numbers are entered into fields configured with the Text data
type. Following the same approach as the Date / Time input mask
will ensure data entry operators will enter in phone numbers
according to the mask you have set.
NOTE: If at any stage incomplete data has been entered into the
field using an input mask, you will not be able to move out of the
field or select another function until the data is either removed or
completed. Access will display the following message
Validation Rules
• Validation rules help to control and therefore limit the
type and amount of data users can enter. By providing
conditions (criteria), in the form of expressions in the
Validation property of a field, data entered must match
the given conditions to be accepted.
• If the data fails to meet the conditions specified,
Validation Text, also specified within Field Properties
below the validation rule, will be displayed prompting the
user of the conditions required to meet data entry
requirements.
• Select the Price field.
• The warning refers to the field in which data violates
the new validation rule, in this case, Date Received.
This is because some of the dates entered are prior to
01/01/2007.
• As we are only interested in making certain all new
record entries conform to the rule, click on the Yes
button to keep the new settings and continue testing.
NOTE: Access continues checking any other validation
rules you added and will inform you if they contain data
that fails to meet the rules.
In the Price column, notice how the values now display
the two decimal points since changing the format to
Fixed.
Field Properties - Guides Tables
• These tables provide a reference guide to some of the
most commonly used field properties, along with
examples and descriptions. NOTE: These operators,
wildcards, etc, along with the examples will prove useful
when learning about and using queries (covered in a later
section), therefore it is worth spending some time
familiarising yourself with them.
• Table – Field Properties – Validation Rule
Comparison Operators The following table contains
comparison operators used to compare values and return
a result that is true, false, or null.
• Table – Field Properties – Input Mask Examples The following characters can be used to define
an input mask.
Primary Keys and Indexing
Defining a Primary Key
• A primary key is used as a unique identifier for each record in a database
table and is essential when working with relational tables.
• To be effective, a primary key cannot have duplicate entries and must be set
on a field generating a unique identifier. When creating a new table Access
automatically adds the ID field with an AutoNumber data type. By default the
ID field is also the primary key.

Other fields suitable to be set as a primary key are for example passport,
social security and driving licence numbers, military identification, tax,
workplace or personal identification numbers, unique to each individual.
NOTE: A primary key field can never be empty.
• Access also uses primary keys to index tables (discussed in a later section).
• Open Access.
• Open a database called Keys and indexing.
• Open the Parts table.
Relationships
Table relationships
• Good database design suggests data is organised across multiple
tables, as to store data in one single table would; 1) Result in vast
amounts of duplicated data and 2) Quickly become
unmanageable.
• Relationships are used to create a link between two or more
tables within a database. When a link is established and with the
use of other objects within the database, data can be entered into
or viewed from one or more tables at the same time, without the
need to close one table and open another.
• The most common relationships between tables are: One-Many
Many-Many One-One
• A relationship is built by matching a unique field within one table
with a field within another table.
One-to-many relationship
• Consider a Parts sales database that includes a Customers
table and an Orders table. A customer can place any number of
orders. It follows that for any customer represented in the
Customers table, there can be many orders represented in the
Orders table. The relationship between the Customers table and
the Orders table is therefore a one-to-many relationship.
• To establish a one-to-many relationship between tables, it is
necessary to take the Primary Key (normally the ID field) of the
‘one’ side of the relationship, (in this case the Customer table)
and add it as an additional field within the ‘many’ side (Orders)
table.
TIP: This requires you to add a new (Customers ID) field to the
Orders table and set the data type. As the AutoNumber field can
only be used once in a table, the Number data type is used.
Many-to-many relationship
• Consider the relationship between a Parts (Product) table and an Orders
table. A single order might include more than one product. On the other hand,
a single product can appear on many orders. For each record in the Orders
table therefore, there can be many records in the Products table.
• In addition, for each record in the Parts table, there can be many records in
the Orders table. This type of relationship is called a many-to-many
relationship because, for any product, there can be many orders and, for any
order, there can be many products.
• A many-to-many relationship, is actually achieved by creating two one-to-
many relationships, using a third table, often referred to as a Junction. The
Primary key from both the Parts and Orders tables are added to the third
table (junction) thereby effectively creating two one-to-many relationships.
NOTE: In many circles, a many-to-many relationship between your tables is
not considered ideal and consideration should be given to the design, possibly
breaking data across additional tables to avoid the necessity for many-to-
many relationships.
One-to-one relationships
• In a one-to-one relationship, each record in the first table
can have only one matching record in the second table,
and each record in the second table can have only one
matching record in the first table. This type of relationship
is not common because, most often, the information
related in this way is stored in the same table.
• One example of a one-to-one relationship might be to
transfer sensitive data to another table and isolate it for
security reasons. NOTE: Both tables must share a
common field but not necessarily a Primary key field.
Creating relationships between tables
• Before a relationship can be created, a database must contain two or more
tables upon which a relationship can be formed.
• Start Access and open a database called Relationships from your Access
2007 samples folder. You will notice the Orders and Parts tables in the
navigation pane.
Referential integrity
• Good database design suggests dividing information into many
subject-based tables to minimize data redundancy. Relationships
are then used to bring the data back together by placing common
fields into related tables.
• To bring data back together, Access uses the value in the "many"
table to look up the corresponding value in the "one" table.
• Suppose you have a one-to-many relationship between Parts
and Orders and you want to delete a Part (Item). If the Part you
want to delete has orders in the Orders table, those orders will
become "orphans" when you delete the Parts record.
• The orders will still contain a Part ID, but the record (Parent) that
it references no longer exists. Referential integrity is designed to
prevent this situation occurring and keep references in sync so
that this kind of situation never occurs.
• Referential integrity by default is not enabled and
therefore has to be enabled either during the creation of
relationships or when editing relationships. When enabled,
Access will reject any operation that violates referential
integrity for that particular relationship.
• Access rejects updates that change the target of a
reference or deletions that remove the target of a
reference. In other words, if you attempt to delete an
individual part from the Parts table that has been
referenced in the Orders table (included in an order),
Access will prevent this from happening.
• To enable Referential Integrity, double click on the line
between the two tables to open the Edit Relationships
options box again.

You might also like