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

Chapter 10 Database

Uploaded by

nihtweaung.ytu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

Chapter 10 Database

Uploaded by

nihtweaung.ytu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 76

Chapter-10

Database and File Concepts


What is a database?
• A database is an organized collection of data.
• A database program is software which stores and retrieves data in a
structured way.
• Databases allow users to store, organize and search data, as well as
outputting it in either a printed or electronic format.
• Databases have many uses, such as storing school or college students’
academic records, cataloguing of books, films or music.
• Databases are used in banking, police and crime information systems and
vehicle registration systems.

2
What is a database?
• A database is an organized collection of data.
• A database program is software which stores and retrieves data in a
structured way.
• All databases store data using a system of files, records and fields.
• A field is a single item of data, such as a forename or date of birth. Each field contains
one type of data, for example numbers, text or a date.
• A record is a collection of fields, for example all the information about one person or
one item. These may contain different data types.
• A file is an organized collection of records. A file can have one or more tables within
it.
• There are two types of databases: flat-file databases and relational databases.
3
Flat-file databases
• A flat-file database stores its data in one table, which is organized by rows
and columns.

4
Relational databases
• Relational databases are several tables linked together, preventing
unnecessary repetition of data.
• Most tables will have a primary key field that holds unique data and some
tables will have one or more foreign key fields.

5
Flat-file & Relational databases
Flat-file Database Relational Database
Poor at complex queries Better security
Poor at limiting access Cater for future requirements
Harder to update, so inherently inefficient Data is only stored once
Potential duplication Requires more planning
Easy to design
Non unique records
Harder to change data format
6
Data Types
• When data is stored in a database, it must be stored as a specific type of data.
• In Access, an alphanumeric field is called a text field.
• The three main types of field are alphanumeric, numeric and Boolean.
• Alphanumeric data can store alpha characters (text) or numeric data (numbers) that will not be used
for calculations.
• In Access, this is called a text field.
• A numeric data type stores numeric values that may be used for calculations. It should not store
numeric data that is not used for any calculations, like telephone numbers.
• There are three types of numeric field including:
• Integer fields store whole numbers.
• Decimal formats, which will allow a large number of decimal places.
• Currency values, which allow currency formatting to be added to the display.
• Date and time formats, which store a date and/or time as a number.
• A Boolean (or logical) data type stores data in a Yes/No (or True/False, 0/-1). The term Boolean
comes from the name of the 19th century mathematician, George Boole.
7
Data Types

• There are other data types as well, like AutoNumber which generates unique numbers.
• Some packages like Access have long and short versions of their data types, for example long
text and short text (which are versions of alphanumeric data types) or long number and number.
8
Other Data Types
• Other data types can often be found in commercial databases.
• Access can store placeholders for media, such as images, documents, spreadsheets,
presentations, sound bites and video clips.
• All of these are stored using an attachment data type or using an OLE object
(object linking and embedding) data type.
• Media files tend to be used for web applications where a back-end database holds
the media to be displayed in another application like a web page.

9
A document, for example a
File database, that is stored in a One piece of information; for
computer. Field
example, age.

Row All the data horizontally in a table;


for example, all the fields for one
Record A collection of completed fields
patient.
about one object, item or person.

10
This is a table called PATIENTS. It stores
information about patients in a hospital.

Each row is called


a record. Each
record is made up
of all the fields
about one patient.

Each column is a field. It has one piece of data about


each record; for example, Patient ID is one field.

11
Primary key and Foreign key
• Primary key: The key field of a table which is unique and identifies each
record
• Foreign key: The field linked to the primary field of the table linked to
through a relationship

12
Tables
• A table consists of :

• Records (as rows) that contain data about entities, such as people, films, objects or

locations
• Fields (as columns) that are used to store attributes about each entity, such as

gender, date of birth or height.

13
Create a Database
• A theme park is creating a database:
• The theme park database stores data about visitors in a table called ‘Visitors’.
• The theme park has five rides. Data about the rides are stored in a table called
‘Rides’.
• Data about tickets are stored in a table called ‘Tickets’.
• When visitors pay for a ride, they are given a ticket.
• Tickets can be bought at ticket stalls in the theme park.

14
Relationship Types

• Relationships are used to link tables together.

• There are three types of relationship, one-to-one (1–1), one-to-many (1–∞) and

many-to-many.
• One-to-one relationship

• One-to-many relationship

• Many-to-many relationship

15
Creating Relationships between tables

Visitor Ticket Ride

Figure 20.7 Relationships are formed between linked tables

16
Creating Relationships between tables

Library Loan Member Customer Sale Product


book

Sports Entry Competitor


event

Figure 20.8 Other examples of Relationships that can be made between tables for libraries,
retailers and sports events organisers
17
Creating Relationships between tables
• Select the DATABASE TOOLS tab and double click on the Relationships icon to

open the Show Table window.


• Double click on each table names to place the table in the Relationships tab and

click on Close tab after both tables have been added.


• After both the tables have been added, click on Close to see the Relationships tab.

• To create the one-to-many relationship, click the left mouse button down in the first

table on the first field. Hold down this, drag the cursor and drop it in the second table

over the second field.


• The Edit Relationships window will appear.
18
Creating Relationships between tables

19
Creating Relationships between tables

20
Creating Relationships between tables

21
Creating Relationships between tables

22
Creating Relationships between tables

23
Creating Relationships between tables
• Enforcing referential integrity is important when creating relationships between
tables.
• This is because it allows you to make sure that only existing data from the Visitors
table and the Rides table can be entered into the VisitorID and RideID fields of the
Tickets table.
• This helps reduce data entry errors, because users are less likely to make mistakes by
entering invalid data.
• Once relationships have been created between tables, data from one table can be
looked up using criteria from another.
• For example, in the theme park database, you could find out the gender of all visitors
who bought tickets for the Looper ride to see whether it is more popular with women
or with men.

24
25
Validation
• Validation helps to reduce data entry errors.
• It is used to check that data entered in a field is acceptable when compared to criteria
set in the database design.
• Enforcing referential integrity is one type of validation.
• Validation does not check that the data is accurate or correct.
• It just checks that the data meets criteria and can be accepted by the field.
• If the data passes a validation check, then it will be stored in the field.
• If it does not pass the validation check, it will be rejected and an error message will
be displayed.

26
Types of Validation Check

• There are four different types of validation check.

 presence  type  length  range

27
28
29
30
Sort the Data
• You can sort data in either ascending or descending order.
• Data can either be sorted by the data in a single field or in multiple fields, such as
ascending by Surname then descending by DateOfBirth.

31
32
33
34
Inputting Information Consistently
• You have already input some data into your tables.
• When you enter data into a table or a form, you must make sure that you use the same
format throughout.
• For example, if data in a Date field is formatted as DD/MM/YYYY, you should always
enter it in that format.
• Do not change the format to MM/DD/YYYY or change the ‘/’ to ‘:’ (DD:MM:YYYY).
• Similarly, if names start with a title, such as Mrs, you should make sure that the titles are
consistent: do not use ‘Mrs.’ or ‘MRS’.

35
Queries
• Queries are used to search for, retrieve and combine data from one or more tables and
perform calculations on that data.
• Queries that retrieve or calculate data from a table are called select queries.
• The result of a query are stored in a dynaset, which is a DYNAmic subSET of data.
• The data in the dynaset are dynamically linked to the table(s) from which they are
selected.
• Dynamically linked means that any change made to the data in the dynaset is also
applied to the data in the table from which it was originally selected.
• The results of a query are determined by the criteria you enter. You can query records in
one or more tables and use one criterion or multiple criteria to define the search. 36
37
38
39
40
Logical Operators
• Logical operators evaluate to either TRUE or FALSE.

41
42
43
44
45
Relational Operators
• Like logical operators, relational operators also evaluate to either TRUE or FALSE.
• You can combine logical and relational operators, which is useful when you need to set
criteria to find records within a particular data range.

46
47
48
Outputting Data from a Database

• Once data has been input and processed, it can


be output in a range of formats.
• Your choice of format will be decided by the
needs of the target audience.
• Outputs make the data easier for the audience to
read and understand.

49
Reports
• You can display selected data from a database in a report, which can be viewed on
screen or printed.
• In Microsoft Access, you can create a report based on a query using the Report
Wizard from the Reports group on the Create tab.

50
51
52
53
54
55
56
57
58
59
60
Mail Merge Documents

• Many organisations use databases to produce


letters for current and potential customers.
• A database can be used as a source of data for a
mail merge.

61
62
63
64
65
Design View
• You cannot print from Design View.
• You can export the design characteristics of a database object using the following
steps.
• Make sure you have saved all your open objects.
• Select Database Documenter on the Database Tools tab.
• Select the All Object Types tab.
• Select the object you want to print.

66
67
Design View
• In Options, check:
• the include for Table area and remove all three ticks from the boxes, as shown in
Figure 20.50.
• the include for Fields area and choose Names, Data Types, Sizes.
• the include for Indexes area and click Nothing.
• Select OK and, when you are asked if you want to close the table, choose Yes.

68
69
70
Relationship Report
• You can also produce a printable report that shows the relationships in your database
by using the following steps.
• Select Relationships on the Database Tools tab.
• Select Relationship Report in the Tools group on the Design tab. This produces a
report like the one in Figure 20.53.

71
72
Chapter Questions

73
74
75
76

You might also like