databases 101 © dolinski 2007. what you will learn how relational databases work what are the...

32
Databases 101 © Dolinski 2007

Upload: marjorie-long

Post on 18-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Databases 101

© Dolinski 2007

Page 2: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

What you will learn

• How relational databases work

• What are the components that make up a database

• How to create each component

Page 3: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases• Unlike a flat file database

– Database with a single flat file table• Address Book• Phone numbers• Online Recipe

• Uses lots of tables which store subject specific information.

• This information is then linked to each other which creates the relationships.

Page 4: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases• DVD Rental Shop

• Flat file databases tend to store lots of repeated data.

• This means the databases becomes very inefficient.

• Flat files are also very restrictive. Updating a DVD’s price means changing every single record. This can lead to mistakes.

Name Age DVD Price Rating

David 15 Matrix £3.99 PG

David 15 Mission Impossible 3 £3.99 15

Laura 14 Mean Girls £2.99 PG

David 15 Mean Girls £2.99 PG

Page 5: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases

• The solution to our problem is simple.

• Break down the tables into subject specific categories.

• In our rental shop example we would end up with three tables:– Customer– DVD– Rental

Page 6: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases

• Customer Table:– Would store all the information we need to know

about the customer.

– This means we only need to store the customer’s details once.

– This means that if a customer’s details change, for example, their address, then we only need to change one record.

Page 7: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases

• DVD Table:– This would store information about the DVD’s in

our shop.

– Again, we only need to store the information once.

– This means that we only have to change the details of a DVD once if they might change, for example, its rental price.

Page 8: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases• Rental Table:

– Would store all the information about each rental.

– The rental table would store the membership code of the customer, the DVD code and a rental code.

– From the membership code in the rental table, we can find the customer’s details in the customer table, and likewise for the DVD details, we can find the details in the DVD table by using the DVD code.

Page 9: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases

• In MS Access, we could see how our tables were linked by using the Relationships View:

Page 10: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases

• Databases have different components that you can use.– Tables– Queries– Forms– Reports

Page 11: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Relational Databases• Tables

– Used for storing data

• Queries– Used for finding data

• Forms– Used for entering data

• Reports– Used for displaying data

Page 12: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables

• These are the first things you set up.

• In MS Access, you can use the design view to set up tables quickly and easily.

• You must decide on two main things:– Field Name– Data Type

Page 13: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables

• Field Names are used to identify the actual piece of data which needs to be entered.– Name– Address– Phone Number– Etc

• They are basically headings for the table.

Page 14: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables

• Data Types let us know what type of data each field will store.

• There are lots and it is important to chose the right one.

Page 15: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables

• Below is a list of data types that you might use:

Data Type What is it used for?

Text Storing text and numbers which are not used in calculations, e.g. telephone and house numbers.

Number Used for storing numbers such as quantities and ages.

Date/Time Used for storing dates and times, e.g. Date of Births and booking dates.

Yes/No Used for storing yes or no data, e.g. Has the Customer Paid?

Currency Used for storing money values, e.g. Prices

AutoNumber Used for storing unique values, e.g. membership numbers.

Page 16: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables

Here is an

example of a

table in the

design View:

Page 17: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables

• Data validation is another important aspect of table design.

• Data validation is the method of preventing bad data from entering the system.

• For your project you will only need to show two or three examples of your system using data validation.

Page 18: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables

• Data validation can be used on things such as:

– Dates• Not allowing underage people from buying certain

products

– Numbers• Not allowing a number to be entered below or above a

certain level e.g. Number of beds in a room

Page 19: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables

• Validation rules are entered in the validation rule field in the table design.

• Rules can be simple things such as:– >20 This rule means a number must be

greater than 20 when entered.

– Like “Mr” Or “Miss” Or “Mrs”

This rule means that only defined entries can be made into the system.

Page 20: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Tables• This is an example validation rule for a customer

table.– It defines the entries that are needed for the Title Field.

– The validation text appears when data has been entered incorrectly or doesn’t meet the validation rule.

Page 21: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Queries

• These are used to find information.

• They can search through tables for data that we ask it to find, for example:– A name– Records between certain dates– Telephone numbers

Page 22: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Queries

• When writing a query we need to know two things:– What data fields we want to display– What data we want to look for

Page 23: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Queries• This is the design view for a query:

• This query will ask the user to enter a valid customer number.

Page 24: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Queries

• The database will display a user input box and the user can type in the customer number:

• The results of the

query will be shown.

Page 25: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Queries• The code to do this is:

• In the Criteria field write this:– [Enter Customer number:]

• [This means open ended…the user defines]

Page 26: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Queries

• If I always wanted to find customer 0001 then in the criteria field I would enter 0001!

• AMAZING!!!

Page 27: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Forms

• Forms are used for data entry.

• They should be designed to allow data to be entered quickly and accurately.

• You can use a design wizard to help you set up your form but you will need to change the design to make it more user friendly.

Page 28: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Forms• The wizard will produce something like this:

• This isn’t very user friendly and will probably result in some bad data from being entered.

Page 29: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Forms

• Changing the design can vastly improve:– The speed at which data is entered.– The accuracy of the data being entered.

• Using drop down boxes and option menus are a great way of speeding up data entry and they provide some data validation.

Page 30: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Forms

Or you can use Option Buttons for example.

You can use Drop Down Menus

Page 31: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Reports• Reports are used to output data from the database.

– Such as printing off a list of customers for example.

• Like the forms, you can use the design wizard to get the initial layout.

• You will need to tweak the layout to maximise the efficiency of the report.

• The wizard does a good job of wasting space!

Page 32: Databases 101 © Dolinski 2007. What you will learn How relational databases work What are the components that make up a database How to create each component

Reports• An example report produced by the wizard might

look like this:

• The report can be designed to output data in any particular order.

• This report prints data out in ascending order of last name.