Вы находитесь на странице: 1из 35

Introduction to Databases

Today’s Topic
(Lecture 3)

Introduction to Database
Design
Newports Institute of
Communications and Economics
05/17/20 Lecture 3 1
Step One: Step Two: Decide
Decide… (On Paper)…
What info do I want out? What tables do you need?
Work backwards, and decide What fields do you need? – Which ones
what info you need to go in! should be lookups?

Step Four: Step Three:


Create the Consult!
It’s crucial you take the time
Database to talk to anyone who might
Create a new database and name it use your database or need
to take info from it!

Step Five: Step Six:


Create Tables Relationships
Create your tables and your fields
Create lookups Determine the relationships
between your tables
Key in a few dummy records

Step Eight: Step Seven:


Forms & Queries
Create your most important
Reports queries (this will test
Create your forms whether you have put in
Create your reports everything that you need)

Step Nine:
Test! Step Ten:
Test your database again
Consult everyone and make Written
sure that nothing has been
05/17/20
missed!
Lecture 3 Record 2
Delete the dummy records and Make a written record of the
key in your real info tables, fields, lookups and
Planning a Database
 Designing databases can be a complex
business.
 The more time and thought you put into the
planning stage, the more effective your
database will be later!

05/17/20 Lecture 3 3
Questions that need answers
 To get an idea of what you will need, ask
yourself the following questions…
 What do you want the database to do for you?
 What will other people need the database to do?
 Do you already use some paper forms in a
manual system? This information could be
valuable.

05/17/20 Lecture 3 4
The Requirement Analysis
Process
While designing a database the questions
may be answered by the help of
 Interviewing the End User
 Observing various business transaction records
and documents such as bills, reports, forms and
memos
 Observing the current system

05/17/20 Lecture 3 5
The Key Question
 The Key Question - What Information Do I
Want out of My Database?
 Start working on paper first!
 List all of the information that you want out
 Spend time ensuring that you have thought of
everything

05/17/20 Lecture 3 6
Separate Fields for Data
 Make sure there is a separate field for data
you wish to sort or extract…
 For example, if you create a field called
name, which includes both firstname and
lastname - you will not be able to sort it
alphabetically by lastname. It will also be
difficult to extract people whose last name is,
for example, 'Smith'. When you create the
query you will have to use wildcards.
05/17/20 Lecture 3 7
The Golden Rule

The Golden Rule is…


Information should NEVER need to be keyed in
twice!

 The greatest mistake in designing a database is


creating something where information is duplicated
in different places.
 This makes your database almost impossible to
work with!

05/17/20 Lecture 3 8
Data Redundancy
 This term refers to a situation where
information is repeated at number of places
in a table.

05/17/20 Lecture 3 9
Example
Consider the following…
 You are creating a database which is to hold
information about employees and which
training course(s) they are going on.
 You need to produce a list of the people's
names and the course(s) they are going on.
 You also need to produce a list of the
courses and the people that are going on that
course.
05/17/20 Lecture 3 10
Example 1 – Duplicating
Records
 The temptation is to cram all this information
into one table. You would probably decide
that the following fields are crucial: Lastname,
Firstname, Course
 But look what happens when you create a
table with these fields and start to input data:-

05/17/20 Lecture 3 11
Example 1 – Duplicating
Records

Racquel Welch is
going on four
courses, which means
her details have to be
inputted four times

05/17/20 Lecture 3 12
Problems with Example 1
 Waste of time inputting the same details again and
again.
 Chances of mistake increased in entering records.
 Misspelled records will not be retrieved
 Updating the details will be time consuming and a
tedious job
 Difficulty in sorting or querying the table
 For example, finding the total number of employees or
producing a list of courses

05/17/20 Lecture 3 13
Example 2 – Duplicating Fields

Course field
is duplicated
six times

05/17/20 Lecture 3 14
Problems with Example 2
 Imagine that you want an alphabetical list of all the
courses. As the course names are spread out over
six different fields, there is no way of doing this.
 Look at the number of blank fields which there are in
this table. Most people may only be going on one or
two courses, and yet you have a table with six
course fields, and most of them are blank! This
creates a very unweildy table.
 You probably won't just want the course name, as in
the picture above, but the date, the location, the
price etc. You will end up having to create several
duplicated fields for all this information as well.

05/17/20 Lecture 3 15
The Solution – A Relational
Database
 If you find that you are duplicating records or
duplicating fields then you almost certainly
need a relational database.
 In other words, a database with more than
one table and where those tables are
related to each other in some way
 Relational Database Design will be discussed
in detail in the lectures to come

05/17/20 Lecture 3 16
Relational Database
 The reason the database we have been
looking at causes problems is because…
One person can go on many courses
 Because there are many courses we have no
choice but to duplicate either the course field
itself, or the records to match up to each of
the many courses the person is going on.

05/17/20 Lecture 3 17
Other Examples
Some other examples may be…
 One organisation has many contacts
 One artist has many albums
 One club has many members
 One doctor has many patients
 When this situation arises you need two
tables, a table for the one side (e.g. people),
and a table for the many side (e.g. courses)

05/17/20 Lecture 3 18
Illustration

FirstName LastName Dept Courses

Bob Hoskins Sales Word

Micheal Caine Sales Access

Racquel Welch Executive Excel

Oliver Reed Execitive FrontPage

05/17/20 Lecture 3 19
Designing Tables in Access
 Before Creating tables we need to

 Design the tables using a model

 Specify a Correct data type and size for fields

 Apply constraints on the columns

05/17/20 Lecture 3 20
Planning the data type

 The kind of data to be stored is


usually obvious from analysis

05/17/20 Text Date Lecture 3 Number 21


Data types
Data type Description Example

Alphanumeric Alphabets “1”,”a”,”a100”


and numbers

Number Numbers only 1,2,4,500

Date Dates only 5-Jan-2000

05/17/20 Lecture 3 22
Specifying field size
 This is the process of specifying the
maximum amount of data that can be
stored in a field
Data Type Description
Text Stores alphanumeric data.
Memo Stores data that exceeds 255 characters
Number Stores numeric data that is to be used in calculations later
Date/Time Stores a date or time
Currency Stores currency values
AutoNumber Automatically generates serial or random numbers (the numbers never
repeat)
Yes/No Stores a logical or ‘Boolean’ value of Yes/No or True/False
Hyperlink Used to Store URLs, email addresses or links to other files on the system

05/17/20 OLE object Stores pictures, photographs


Lecture 3 of employees, Word, Excel or other such 23
files
Enforcing Constraints
 Constraints are
limitations placed
on incoming data
Can be for a range
For total
absence of data

Can be for a value Can be for absence


of a value
05/17/20 Lecture 3 24
Types of Constraints

Constraints

Check Not Null Primary Key Default

05/17/20 Lecture 3 25
Primary key
 Primary key
 Uniquely identifies each row of a given table

 Used to co-related data lying across multiple


tables

05/17/20 Lecture 3 26
Check Constraint
 Checks for the presence of a particular value
or its absence

 Example
 Starts with “A”
 Ends in a number

 Does not contain “$”

05/17/20 Lecture 3 27
Not Null

 Null represents absence of data

 Not Null means can not be left empty

 Access calls this the ‘Required’ property

05/17/20 Lecture 3 28
Default
It is used when

 No values have been specified

 NULL should not be allowed

05/17/20 Lecture 3 29
Planning formats
 Formats are the way in which details to be
entered;
example: the value 100 000 can be denoted
as 1,00,000 or 1000,00 or simply 100000

 It is completely dependent on the user

05/17/20 Lecture 3 30
Some Other Points to
Remember
 Do not use DBMS specific design

 Do consider legacy data

 Maintain Standard for data types

 Look at recovery strategies

05/17/20 Lecture 3 31
RDBMS Views
RDBMS MS Access Description
External View Datasheet View As seen by user
Design View As seen by
Conceptual DBA
As Access Stores it As perceived by
It does not have a DBMS
Internal name

05/17/20 Lecture 3 32
Field properties
 characteristics or “properties” can be
assigned to fields

Validation
rule

Validation
Text
05/17/20 Lecture 3 33
Input Mask

APT-0000 ; *
0;

The Mask Itself Save Literals? The Placeholder


character:

05/17/20 Lecture 3 34
Summary

 Constraints act as a check for incoming data.

 Field properties decide how a field will behave

05/17/20 Lecture 3 35

Вам также может понравиться