designing a database - webstartscreativeplus.webstarts.com/uploads/fdbs_lecture_5.pdf · the design...
TRANSCRIPT
The Design Process
• The design process consists of the following steps:
▫ Determine the purpose of your database
This helps prepare you for the remaining steps.
▫ Find and organize the information required
Gather all of the types of information you might want to
record in the database.
▫ Divide the information into tables
Divide your information items into major entities or
subjects. Each subject then becomes a table.
The Design Process (cont’d)
• Turn information items into columns
▫ Decide what information you want to store in each table.
Each item becomes a field, and is displayed as a column in
the table.
• Specify primary keys
▫ Choose each table’s primary key.
• Set up the table relationships
▫ Look at each table and decide how the data in one table is
related to the data in other tables. Add fields to tables or
create new tables to clarify the relationships, as necessary.
The Design Process (cont’d)
• Refine your design
▫ Analyze your design for errors. Create the tables and
add a few records of sample data. See if you can get the
results you want from your tables. Make adjustments to
the design, as needed.
• Apply the normalization rules
▫ Apply the data normalization rules to see if your tables
are structured correctly. Make adjustments to the tables,
as needed.
Normalisation
• Normalisation is the process of breaking up larger
relations into many small ones using a set of rules.
• The process involves identifying functional
dependencies. If they are found to be attributes that
are not directly dependent on the PK, these are
extracted to form new relations.
Normalisation (cont’d)
• The process is carried out until all the data in each
relation is clearly and uniquely associated with other
data in the same table. This reduces redundancy
(although it does not eliminate it) and makes the data
easier to maintain.
Normal Forms
• A number of normal forms have been proposed but
the first five normal forms have been widely accepted.
• The norm forms progress from 1NF, to 2NF, and so
on. Data in 2NF implies that it is also in 1NF – i.e.,
each level of normalisation implies that the previous
level has been met.
• Other normal forms such as Boyce-Codd (BCNF)
which is an extension of 3NF, 4NF and 5NF also exist
First Normal Form (1NF)
• A relation (table) that contains a repeating group (or
multiple entries for a single record) is called an
unnormalised relation.
• Removing repeating groups is the starting point in the
quest to create tables that are as free of problems as
possible. Tables without repeating groups are said to be in
1NF
• A relation is in 1NF if – and – only if – all domains contain
only atomic or single values, i.e., all repeating groups of
data are removed.
1NF(cont’d)
• In order to convert an unnormalised relation into
1NF, first identify the key attribute(s) involved. Also,
identify a key for the whole relation.
• Make a separate relation for each group of related
attributes
• Give each new relation a primary key
Second Normal Form (2NF)
• A relation is in 2NF if
▫ it is in 1NF
▫ and all non-key attributes are dependent on the whole of
the primary key and not part of it.
• If an attribute depends on only part of a multi-value
key, remove it to a separate table.
Third Normal Form (3NF) • A relation is in 3NF if
▫ it is in 2NF
▫ non-key attributes are dependent on the primary key and
independent of each other. i.e., non-key attribute must be non-
transitively dependent on the primary key.
▫ a non-key attribute is changed, that change should not affect others
• Make a separate relation for attributes transitively dependent
on the primary key.
• Give each new relation a primary key
• Original relation will include a foreign key to link to new
relation
Example
• Help At Home is an agency which provides various
services such as baby sitting and dog walking. Details
of all bookings and a record of the service carried out
are kept. Assume only one person(employee) is
involved in carrying out each particular service. An
hourly rate is charged depending on the type of service
required. Note that customers will only be able to
make one booking for a particular service per day.
Example (cont’d)
Customer name:
Tel: 081 980 2223
John Smith Customer no: 111
Date of booking: 18.09.06
Type of service required: 02 Service required: Dogwalking
Date service is required: 30.09.06
Person carrying out job: Ben Brown
Charge per hour: $10 Hours: 1
Customer name:
Tel: 081 980 2223
John Smith Customer no: 111
Date of booking: 11.08.06
Type of service required: 01 Service required: Baby sitting
Date service is required: 16.08.06
Person carrying out job: Issa Ahmed
Charge per hour: $7 Hours: 5
Book record example 1
Book record example 2
Example (cont’d)
Relation in un-normalised form
Cus_No Cus_name Cus_Tel Booking_date Service_Type Service Date_required E_no E_name Per_hr_
$
Hrs
111 J Smith 980
2223
11.08 01 Babysit 16.08 1 Issa
Ahmed
7 5
18.09 02 Dogwalking 30.09 2 Ben
Brown
10 1
112 G Best 678
4455
12.06 01 Babysit 13.06 2 Ben
Brown
7 3
Example (cont’d) – 1NF
• Identify PK – Cus_no, Booking_date, Service_type
• 1NF determinacy diagram
Cus_no
Booking_date
Service_type
Cus_Tel
Cus_name
Date_required
E_name
Hrs
Service_required
Per_hr_$
E_no
Example (cont’d) – 1NF
• Relation in 1NF
Cus_No Cus_name Cus_Tel Booking_date Service_Type Service Date_required E_no E_name Per_hr_$ Hrs
111 J Smith 980
2223
11.08 01 Babysit 16.08 1 Issa
Ahmed
7 5
111 J Smith 980
2223
18.09 02 Dogwalking 30.09 2 Ben
Brown
10 1
Example (cont’d) – 2NF
• The relation in 2NF
Cus_No Cus_name Cus_Tel
111 J Smith 980 2223
112 G Best 678 4455
Service_Type Service Per_hr_$
01 Babysit 7
02 Dogwalking 10
Cus_No Booking_date Service_Type Date_required E_no E_name Hrs
111 11.08 01 16.08 1 Issa
Ahmed
5
111 18.09 02 30.09 2 Ben
Brown
1
Example (cont’d) – 3NF
• 3NF determinacy diagram (the service type and
customer diagrams remain the same as in 2NF)
Example (cont’d) – 3NF • The relation in 3NF (the service type and customer tables
remain the same as in 2NF) Cus_No Booking_date Service_Type Date_required E_no Hrs
111 11.08 01 16.08 1 5
111 18.09 02 30.09 2 1
Cus_No Cus_name Cus_Tel
111 J Smith 980 2223
112 G Best 678 4455
Service_Type Service Per_hr_$
01 Babysit 7
02 Dogwalking 10
E_no E_name
1 Issa Ahmed
2 Ben Brown
Query-By-Example (QBE)
• QBE is an approach to writing queries that are very visual.
• With QBE, users ask their questions by entering column names and other criteria using an on-screen grid, and data appears on the screen in tabular form
• In Access 2007 & 2010, queries are created using the Query Wizard or Query Design in the queries groupings under the Create tab
• Practical session to be taken in class
Examples
1. List the number, name, balance and credit limit of all
customers in the database
2. List all fields and all rows in the Orders table
3. Find the name of customer 148
4. List the description, on hand value and warehouse
number for all parts that have more than 10 units on
hand and that are located in warehouse 3
5. List the description, on hand value and warehouse
number for all parts that have more than 10 units on
hand or that are located in warehouse 3
6. List the number, name and balance for each customer
whose balance is between £1000 and £5000