Top Banner
What is a Database? • A collection of organized information on a particular subject. • It is organized so that queries and reports based on the information can be readily performed. • Common examples of databases: – telephone book – Student records
73

What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Dec 14, 2015

Download

Documents

Rylan Harland
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

What is a Database?

• A collection of organized information on a particular subject.

• It is organized so that queries and reports based on the information can be readily performed.

• Common examples of databases:– telephone book– Student records

Page 2: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Other databases- Company records- Police records- Census records- University records

The organization is important to be able to retrieve information from a data base.

Page 3: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Databases and Spreadsheets

Databases more for organization of large amounts of non numeric data where queries are more important then computation.

Spreadsheets are more powerful computational tools.

Page 4: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

.

DBMS: A database management system is a collection of software for managing the database and contains software for organizing the data and verifying it, as well as software for retrieving the data through queries as well as creating reports based on the data.

Page 5: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

DBMS Software

• There are different DBMS software versions available:– Microsoft Access (which we’ll be using)– Microsoft SQL Server (more features than Access)– Oracle– Corel Paradox– MySQL (open-source)– a lot more…

Page 6: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

A DBMS can:-Create / Delete tables

-Modify tables:  add recordsdelete recordsedit recordsrearrange recordschange the table structure

Retrieve data from a single / multiple table(s) find and display a recordanswers queries

Create reports formatted displays of query results or table contents

Page 7: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Tables and Records

The basic organizational tool in the database is the table which is organized into records which are subdivided into fields.Conceptually it looks like: Id Lastname Firstname Age Weight

1 Smith Joe 25 70 2 Lee Jane 57 45 3 Harper Stephen 60 67

The data base may be made up of several tables of interrelated information

Page 8: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

A record contains a number of fields:

Examples of fields are :Student number (This field is called a key)Last nameFirst Name Degree ProgramAddressChild of Alumnus

And field may be of different types text, number, dates etc.

Page 9: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

A particularly important field is called a key.

A key is a field that uniquely identifies the record. This field is called the primary key of the table.

A name would not be a suitable key because it is not unique.

Suitable keys are

-student number-social insurance number-drivers license number

Page 10: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Structure of the Table

• The structure of the table is the specification of fields for records in table.

• The structure specifies the type (or kind of data) for each field.

• Different types of fields are treated differently – when they are entered– when they are displayed– when they are used

Page 11: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Field Types

• Examples of field types: – integer (whole numbers, ex: 1, 55, 993)– currency (ex: dollars, pounds, euros)– real number (ex: 1.034, 55.3321, etc)– time (ex: 10:42)– date (03/03/09, or January 1st 2006).– string (text)

Page 12: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

The Four basic operations in a database.

• Design: – Create the database by defining the tables and Specifying the fields.

• Data Entry: – Adding the actual data by hand or imported from

other files. Easy to make errors.• Queries:

– Ask questions about the data.

• Reports: -producing a document with info

Page 13: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Video Store Database Example

Page 14: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Video Store Example

• We want to create a database for a video store.

• Questions:– How will information be organized?– What will we represent as tables? – What information is required?

Page 15: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Video Store Example (2)

• Decision: – Three groups of information (tables). – Videos– Customers– Rental information.

• For each table:– What information would we like to maintain? – What will be the unique primary key (or

composite key)?

Page 16: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Table 1: The Video Table

• Required information:– Video ID (primary key)– Title – Price – Quantity – Category

Page 17: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Example Video Table

Page 18: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Table 2: The Customer Table

• Required Information: – Membership Number (primary key)– Name– Address– Phone Number

Page 19: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Example Customer Table

Page 20: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

• Required Information: – Membership Number – Video ID – Date Rented– Date Due– Returned Yet?

Table 3; Rental Information TableThis is a table of transactions

Page 21: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Example Rental Information Table

Page 22: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Introduction to Microsoft Access 2007

Page 23: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Access Database Objects

• First we’ll see some objects defined in Access Databases.

• Tables: store your data in rows and columns. All databases contain one or more tables.

• Queries: retrieve and process your data. They can combine data from different tables, update your data, and perform calculations on your data.

Page 24: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Access Database Objects

• Forms: control data entry and data views. They provide visual cues that make data easier to work with.

• Reports: summarize and print your data. They turn the data in your tables and queries into documents for communicating ideas.

Page 25: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Microsoft Access in MS Office

• First of all, not all versions of Microsoft Office include Access.– only the “Professional” version of office includes

Access, NOT the student version.– NOT part of any version of Office for the Mac.

Page 26: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Starting Microsoft Access

• As with other Microsoft Office applications, you can start Access by: – double-clicking the desktop icon of

there is one.– double-clicking an Access file you

have created previously.– going through the Start menu.

Page 27: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Getting Started Window in Access

Page 28: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Creating a New Database

• In order to create a new database in Access we can first select what type of database we want.

• Access has several built-in templates such as:– Business– Personal– Sample– Education (Faculty, student).

Page 29: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

We wont be using the templates but starting from a blank database. But we could use one of the templates.

• Faculty– Keep track of information

about faculty members such as names, contact information, etc.

• Student– Names, contact, medical

information, etc.

For example: Education Databases

Page 30: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Creating a Blank Database

• Of course if none of these templates meet our requirements, we can create a blank database.

• Click on Featuring, then the Blank Database option.

Page 31: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Creating a Blank Database (2)

• After clicking the Blank Database option, a menu will show up on the right that allows you to chose a filename and location for your new blank database.

Page 32: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Access Window

Toolbar

Table listTable panel

Page 33: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Access Window (2)

• The Microsoft Access window should look a bit familiar.– uses the same types of tabs as used by Excel 2007 and also other Microsoft 2007 office products– The table panel actually looks a lot like Excel with

Rows (Records) and Columns (Fields).

Page 34: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Access Toolbars

• As with the other Microsoft software we have seen Access has multiple Tabs or toolbars instead of menus.

• Like we have done for the other applications, we’ll see some of the Tabs relevant to Access, the others we have seen before.

Page 35: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Create Tab

• The Create tab contains options to create new:– tables– forms– reports, etc

Page 36: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

External Data Tab

• The External Data tab allows the database creator to import data from other sources such as:– Excel File– Other Access file– Text files– etc…

Page 37: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Database Tools Tab

• The Database Tools tab allows us to create relationships between tables or with other databases, etc.

Page 38: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Datasheet Tab

• The Datasheet tab allows us to add new fields, change the type for the fields, edit relationships, etc.

Page 39: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Access Views

• There are several different views you can use for your database, we’ll see the two most useful:– Datasheet View: which displays the fields

and the records. This view is useful to enter records.

– Design View: This view allows us to add fields, change the field type, set the Primary key. This view does not show the records.

– You can switch view with the Views button.

Page 40: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Datasheet View

Page 41: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Design View

Page 42: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Tables: Fields and Records

• Databases in Access contain at least one table.• Each column( e.g. Category) is a field.• Each row is a record.• A record is a collection fields.• A field is a single piece of information.

Page 43: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Tables

• Tables store data• The most important building block of a

database.• If the table is well designed then data should

not be duplicated.• Having to duplicate data shows poor design• Table is composed of records and each record

is composed of fields.

Page 44: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Attributes of the Table FieldsPrimary Key: the unique identifier for each record (row)

Data Type: specifies what kind of data in going to be storedin each field.

Page 45: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

More on Primary Keys

• Primary Keys are like fingerprints: there are no two human beings with identical fingerprints.

• Between different records, the fields that are not part of the primary key may be equal.

• In the case of composite key, the full set is unique for each record (individually they might have duplicates).

Page 46: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

More on Primary Keys (2)

• When you create a table, access allows you to specify which field will be the primary key.

• Also, Access can assign a numeric integer data increment in 1 unit automatically, every time you enter a new record.– Called ID by default.– Each record will have a unique ID number.– You can change the field name to a user friendly

one such as VIDEO_ID or STUDENT_ID.

Page 47: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Assigning Primary Keys

• Right click over the field you want to specify as primary key.

• Click on Primary Key.• A key will appear next to the

field.

Page 48: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Assigning Primary Keys (2)

• You can also use the Primary Key button at in the Design toolbar.

Page 49: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Creating a Database

Page 50: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Creating a Database

• We’ll demonstrate how to create a database by using the Video store example we have seen last lecture.

• The Video Store database had three tables:– Video– Customer– Rental Information.

• We’ll show step by step how to create this database using Microsoft Access.

• We’ll first create our Video table.

Page 51: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 1: Creating the Database

• Our first step is to create a blank database document. We’ve seen how to do this last lecture.

• After opening Access, click on Blank Database and enter a name. Here we’ll use the name VideoStore.

Page 52: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 1: Creating the Database (2)

Page 53: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 2: Creating the Table

• By default a new blank database will have one table (Table1). Instead of creating a new one we’ll change the name of this first table by saving it. Click the Office button, then Save.

• Enter the table name Video.

Before Saving:

AfterSaving:

Page 54: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 3: Adding Fields

• We are now ready to add new fields to our Video table.

• We can add fields in different ways, if you notice in the Datasheet view below, we have the option to “Add New Field” but instead we’ll use the Design View.

Page 55: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 3: Adding Fields (2)

• At the top left of the Access window, click on the View button then select Design View.

• This will change the view of the window to the Design View which will make it easier for us to enter new fields.

Page 56: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 3: Adding Fields (3)

Page 57: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 3: Adding Fields (4)

• Be default new tables will have at least one field: ID.• This field is also the default primary key.• ID will increment automatically (AutoNumber) as we

insert new records.• This way, Access can be sure that your table will have

a unique field to use for a primary key.

Page 58: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 3: Adding Fields (5)

• We’ll keep this ID field, but we’ll rename it to something more meaningful for us, VideoID.

• What other fields did we need for our Video table? What type should each field be ($, text, number)?– Title (type: Text)– Price (type: Currency)– Quantity (type: Number)– Category (type: Text).

• We simply enter each field name and type into our field table.

Page 59: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Step 3: Adding Fields (6)

• We can also enter descriptions for each field, just in case we forget what each field was for.

• All our fields are entered for this table.

Page 60: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Adding a New Table

• To add a new table after the first one, click on the Create tab, then click the Table button.

Page 61: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Adding a New Table (2)

• To change the name of the new table you must also save it (Office button, then Save). Change the name to Customer.

Page 62: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Customer Table

• Here is our Customer table after entering all the fields like we did for the Video table.

Page 63: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Issues with entering data:

Very dull and prone to errors.

DBMS’s have features to help avoiding errors and help entering data.

Typically they are called “validation” tools

They are found in the bottom part of the design view window

Page 64: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Click here for options

Page 65: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Input masks Also called "pictures" in some DBMS’s

Allow for ease in entering text or date data by providing a template which is enforced by theDBMS

Thus for example:

A postal code such as K1S 5B6

Can have a mask: >L0L 0L0

> Capitals L: a letter required 0 number required

Page 66: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Input masks Also called "pictures" in some DBMS Used for text, date and time only. Character Description0 Number required 9 Number or space optional # Number or space (entry optionalL Letter required (A through Z) ? Letter (A through Z, entry optional).A Letter or number (entry required).a Letter or number (entry optional).& Any character or a space (entry required).C Any character or a space (entry optional).. , : ; – / Decimal placeholder and thousands, date, and time separators.< Converts all characters that follow to lowercase.> Converts all characters that follow to uppercase.\ Causes the character that follows to be displayed as a literal

character (for example, \A is displayed as just A). 

Page 67: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Examples of input masks (some predefined)

>L0L\ 0L0 Postal code

000\ 000\ 000 Social insurance number

(999) 000-0000 telephone number (digits or blanks for the 9’s)

Page 68: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Note that one can have variations of an input Mask, not all of which are equally strong in enforcing a particular mask.

blank

e.g. Postal Code K1S 5B6 (all upper case)

>L0L\ 0L0 The best because it forces everything

L0L\ 0L0 Does not enforce upper case AAA\ AAA A Letter or number (entry required).

aaa\ aaa a Letter or number (entry optional).

&#&\ #&# & any character or space # any digit or space

Page 69: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Validation rules and validation text.

Page 70: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Validation rules:

e.g. For numbers

>45>45 AND <100Between 10 and 25 ( this is inclusive)

e.g. For text

Input mask: LValidation rule: "M" Or "F "

A single letter which can only be "M" Or "F“, however this is not case sensitive. It will accept uppercase or lower case.

Page 71: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Validation rule: "Male" Or "Female “ Or “M” or “F”Will accept ony these (not case sensitive)

Can we enforce that it should be capitalized but only the first letter?

We put a validation rule:

"Male" Or "Female “ Or “M” or “F”

And an input mask: >L<?????

The “?” means an optional letter.

Page 72: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Other aspects of “field properties” for text.

Validation text: Text you want to use when an error is made.

Field size: How many characters are allowed.

Default value: The system can always put in this value if you do not use another valid value.

Required: The system does not allow you to leave this blank.

Page 73: What is a Database? A collection of organized information on a particular subject. It is organized so that queries and reports based on the information.

Restructuring a table after there is data in it.

You must be very careful.

• You can always add a new field without problems.

•You can always delete a field. (right click on field in design view and delete) BUT problems with deleting field in related tables.

• You can change the type of field if it’s compatible with the data.•Problems if the change if not compatible with data