69
Database Database Management Management Microsoft Access – Microsoft Access – Simplified Simplified By: A. Vanhorne By: A. Vanhorne

Master database management for cxc

Embed Size (px)

DESCRIPTION

Creating Database step by step in Microsoft Access 2007

Citation preview

Page 1: Master database management for cxc

Database Database ManagementManagement

Microsoft Access – SimplifiedMicrosoft Access – Simplified

By: A. VanhorneBy: A. Vanhorne

Page 2: Master database management for cxc

QueriesTablesGetting Started

Starting Microsoft Starting Microsoft AccessAccess Click Blank

Database

Page 3: Master database management for cxc

QueriesTablesGetting Started

Creating a DatabaseCreating a Database

For this tutorial you will be creating For this tutorial you will be creating a database name: “a database name: “SchoolSchool””

Page 4: Master database management for cxc

QueriesTablesGetting Started

Starting Microsoft Starting Microsoft AccessAccess Write your

database name here

Page 5: Master database management for cxc

QueriesTablesGetting Started

Starting Microsoft Starting Microsoft AccessAccess

Database Name

Page 6: Master database management for cxc

QueriesTablesGetting Started

Starting Microsoft Starting Microsoft AccessAccessClick Create

Page 7: Master database management for cxc

QueriesTablesGetting Started

Starting Microsoft Starting Microsoft AccessAccess

Page 8: Master database management for cxc

QueriesTablesGetting Started

Starting Microsoft Starting Microsoft AccessAccess

Click Create to see a list of the objects that

we can create in Microsoft Access

Page 9: Master database management for cxc

QueriesTablesGetting Started

Starting Microsoft Starting Microsoft AccessAccess

Our Focus will be on: Table Form Report Query

Page 10: Master database management for cxc

QueriesTablesGetting Started

Closing Default TableClosing Default TableBy default, Microsoft Access Create a table name “table1”. We will start by closing this table:

Select Table 1

Click the “X” to the right to

close it

Page 11: Master database management for cxc

QueriesTablesGetting Started

Creating a New TableCreating a New Table

Click on Create

Select Table Design from the table Tab. This will open the

table design view

Page 12: Master database management for cxc

QueriesTablesGetting Started

Table Design ViewTable Design View

Page 13: Master database management for cxc

QueriesTablesGetting Started

Table Design View – Tool Table Design View – Tool BarBar

The view button will be used to switch between

design and datasheet view

The Primary key is a unique field that is

used to identify each record in a table. E.g.

ID

Page 14: Master database management for cxc

QueriesTablesGetting Started

Creating a Student TableCreating a Student Table

The table will have the following The table will have the following fields: Idnumber, Firstname, fields: Idnumber, Firstname, Lastname, DOB, GenderLastname, DOB, Gender

Fields Data Types Field Size

Idnumber number

Firstname Text 14

Lastname Text 20

DOB Date/Time

Gender Lookup Wizard

Page 15: Master database management for cxc

QueriesTablesGetting Started

Creating a Student TableCreating a Student Table

Whenever your create a text field, the database reserve 255 character

spaces. However we don’t always need so much space.

FieldField Size

Page 16: Master database management for cxc

QueriesTablesGetting Started

Creating a Student TableCreating a Student Table

When you select look up wizard for When you select look up wizard for gender- the dialog below will appeargender- the dialog below will appear

Click I will Type in the

values that I want

Click Next

Page 17: Master database management for cxc

QueriesTablesGetting Started

Creating a Student TableCreating a Student Table

Enter the look up items:Enter the look up items:

Click Finish

Type: Male and Female

Page 18: Master database management for cxc

QueriesTablesGetting Started

Setting Primary KeySetting Primary Key

Select Idnumber

Select Primary Key

Page 19: Master database management for cxc

QueriesTablesGetting Started

Creating a Student TableCreating a Student Table

A Key appears beside Idnumber.

Page 20: Master database management for cxc

QueriesTablesGetting Started

Save the TableSave the Table

Click the save button

Enter “Student” for

the table name and click ok

Page 21: Master database management for cxc

QueriesTablesGetting Started

Changing the ViewChanging the View

In order to enter data into your In order to enter data into your table, you will have to switch the table, you will have to switch the view to datasheet viewview to datasheet view

Click on view and this will take you to datasheet view

Page 22: Master database management for cxc

QueriesTablesGetting Started

Datasheet ViewDatasheet View

Here you can populate the tableHere you can populate the table

Click on view and this will take you to datasheet view

Page 23: Master database management for cxc

QueriesTablesGetting Started

Datasheet ViewDatasheet View

Populate the table as follows:Populate the table as follows:

*Once you type the data in the table, they are saved automatically.

Page 24: Master database management for cxc

QueriesTablesGetting Started

What is a query?What is a query?

A query is a specific set of A query is a specific set of instructions for retrieving data from instructions for retrieving data from a database and displaying, printing, a database and displaying, printing, modifying or storing it.modifying or storing it.

Page 25: Master database management for cxc

QueriesTablesGetting Started

Types of QueryTypes of Query

Select Select QueryQuery

Action QueryAction Query

Calculate FieldCalculate Field DeleteDelete

Summary Summary OptionsOptions

UpdateUpdate

AppendAppend Make TableMake Table

Page 26: Master database management for cxc

Main Menu

This type of query is designed to list specific information in a database table.

E.g. It could be used to find and display all the female students.

Page 27: Master database management for cxc

QueriesTablesGetting Started

Creating a Select QueryCreating a Select Query

Click on CreateClick on CreateSelect Query Select Query

DesignDesign

Page 28: Master database management for cxc

QueriesTablesGetting Started

Creating a Select QueryCreating a Select Query

Select StudentSelect Student

Click AddClick Add

Page 29: Master database management for cxc

QueriesTablesGetting Started

Creating a Select QueryCreating a Select Query

Select StudentSelect StudentClick Click

AddAddClick Click CloseClose

Page 30: Master database management for cxc

QueriesTablesGetting Started

Creating a Select QueryCreating a Select Query

Double Click each Double Click each of these fields to of these fields to add them to the add them to the

query.query.

Selecting the fields from the table

Page 31: Master database management for cxc

QueriesTablesGetting Started

Viewing the Results of Viewing the Results of the Querythe Query

Click Click viewview to see the result of the to see the result of the query in datasheet viewquery in datasheet view

Click Click ViewView

Page 32: Master database management for cxc

QueriesTablesGetting Started

Viewing the Results of Viewing the Results of the Querythe Query

Query ResultsQuery Results

Click View to Click View to return to the return to the design viewdesign view

Page 33: Master database management for cxc

QueriesTablesGetting Started

Viewing the Results of Viewing the Results of the Querythe Query

Save the Query ResultsSave the Query Results Press Press Ctrl + SCtrl + S or any other method or any other method

Type Type “StudentQuery“StudentQuery” as the Query ” as the Query

NameName

Page 34: Master database management for cxc

QueriesTablesGetting Started

Viewing specific Viewing specific informationinformation

In order to produce a list of specific In order to produce a list of specific information in a table; a criteria information in a table; a criteria must be specified.must be specified.

Criteria is a restriction that data Criteria is a restriction that data must meet while being retrieved.must meet while being retrieved.

Page 35: Master database management for cxc

QueriesTablesGetting Started

Creating a CriteriaCreating a Criteria

E.g: Create a query to view all E.g: Create a query to view all “Male”“Male”

The Criteria The Criteria RowRow

Type Male under Type Male under Gender in the Gender in the Criteria rowCriteria row

Page 36: Master database management for cxc

QueriesTablesGetting Started

View InformationView Information

Click on View to see the resultClick on View to see the result

Click Click ViewView

Result in Datasheet view

Page 37: Master database management for cxc

Main Menu

Example: create a new field to calculate employees’ pay after an increase of $1200.00.

OR: Create a field call “Fullname” to display students full name

Page 38: Master database management for cxc

QueriesTablesGetting Started

Calculated Field Cont’dCalculated Field Cont’d

To the right of Gender; enter the To the right of Gender; enter the text “Fullname”, followed by a colon text “Fullname”, followed by a colon ‘:’.‘:’.

Enter the calculation for Fullname: Enter the calculation for Fullname: [Firstname]+[Lastname][Firstname]+[Lastname]

Page 39: Master database management for cxc

QueriesTablesGetting Started

Calculated Field Cont’dCalculated Field Cont’d

Click on View from the menu barClick on View from the menu bar

IF you want space between the names, modify the calculation as following:

Fullname: [Firstname]+” “+[Lastname]

Page 40: Master database management for cxc

Main Menu

The following summary options are often used in queries: Sum Average Maximum Minimum Count

Page 41: Master database management for cxc

QueriesTablesGetting Started

Using Summary optionsUsing Summary options

Example: create a query to Count Example: create a query to Count the number of studentsthe number of students

Click on Click on TotalTotal

The total bar is then The total bar is then activatedactivated

Page 42: Master database management for cxc

QueriesTablesGetting Started

Using Summary optionsUsing Summary options

Example: create a query to Count Example: create a query to Count the number of studentsthe number of students

Click on Group By under Click on Group By under Idnumber and select Idnumber and select

“Count”“Count”

Page 43: Master database management for cxc

QueriesTablesGetting Started

Summary option Cont’dSummary option Cont’d

Delete all fields apart from Delete all fields apart from “Idnumber”:“Idnumber”: Highlight the fieldsHighlight the fields

Press delete on your keyboardPress delete on your keyboard

Page 44: Master database management for cxc

QueriesTablesGetting Started

Summary option Cont’dSummary option Cont’d

Your design view nowYour design view now

Page 45: Master database management for cxc

QueriesTablesGetting Started

Summary option – Cont’dSummary option – Cont’d

To view the result of the count, Click To view the result of the count, Click on Viewon View

Page 46: Master database management for cxc

Main Menu

An action query makes changes to or moves many records in just one operation. There are four types of action queries:

i. Delete ii. Updateii. Append iv. Make-table

Page 47: Master database management for cxc

Main Menu

This query deletes specific records from a database table.

Example: to delete the student with Idnumber “113”.

Page 48: Master database management for cxc

QueriesTablesGetting Started

Creating a Delete QueryCreating a Delete Query

Create a regular select query, using Create a regular select query, using the fields in the table (s) you wish to the fields in the table (s) you wish to use.use.

Page 49: Master database management for cxc

QueriesTablesGetting Started

Delete Query Cont’dDelete Query Cont’d

Select Delete from the query TabSelect Delete from the query Tab

Enter your criteria here. i.e

113

Page 50: Master database management for cxc

QueriesTablesGetting Started

Delete Query Cont’dDelete Query Cont’d

If Prompted, enable securityIf Prompted, enable securityClick

Options

Click Enable

Click Ok

Page 51: Master database management for cxc

QueriesTablesGetting Started

Running the QueryRunning the Query

Click on Click on RunRun Click on YesClick on Yes

Once you click “Yes” your record will be permanently deleted.

Page 52: Master database management for cxc

QueriesTablesGetting Started

Records after DeletionRecords after Deletion

The record has been removed from The record has been removed from the table:the table:

Page 53: Master database management for cxc

Main Menu

An update query is used to modify a field (s) within a database table.

Example to Add the prefix “Mr.” to all Male first name

Page 54: Master database management for cxc

QueriesTablesGetting Started

Creating an Update Creating an Update QueryQuery

Select the field (s) you wishes to Select the field (s) you wishes to update from the table (s). In this update from the table (s). In this case we need “Firstname” and case we need “Firstname” and “Gender”“Gender”

Enter Male for the Enter Male for the CriteriaCriteria

Page 55: Master database management for cxc

QueriesTablesGetting Started

Creating an Update Creating an Update QueryQuery

Select update from the query tabSelect update from the query tab

TO add the prefix “Mr”; TO add the prefix “Mr”; type the following in the type the following in the update To box: update To box: “Mr.”+“Mr.”+

[Firstname][Firstname]

Page 56: Master database management for cxc

QueriesTablesGetting Started

Update Query Cont’dUpdate Query Cont’d

In the “Update To Row”, enter the In the “Update To Row”, enter the information about the field you want information about the field you want to update.to update.

The information should be below the The information should be below the field name.field name.

Field names should be in square Field names should be in square brackets.brackets.

Page 57: Master database management for cxc

QueriesTablesGetting Started

Creating an Update Creating an Update QueryQuery

Select Run from the Results tabSelect Run from the Results tab

Click Click YesYes

Page 58: Master database management for cxc

QueriesTablesGetting Started

Update Query Cont’dUpdate Query Cont’d

Table before updateTable before update

Table after updateTable after update

Page 59: Master database management for cxc

Main Menu

An append query, is use to copy (move) information from one table to another.

Example moving all the records from the New customer’s table to the customer table.

Page 60: Master database management for cxc

QueriesTablesGetting Started

Append Query Cont’dAppend Query Cont’d

Since we do not have more than one Since we do not have more than one table we are going to make a copy of table we are going to make a copy of the student table.the student table.

1.1. Right Click on student and choose Right Click on student and choose copycopy

2.2. Then paste it in a blank areaThen paste it in a blank areaCopyCopy

Paste Paste herehere

Click OkClick Ok

Page 61: Master database management for cxc

QueriesTablesGetting Started

Append Query Cont’dAppend Query Cont’d

To prevent duplicated records, lets To prevent duplicated records, lets change the Idnumbers in the “Copy change the Idnumbers in the “Copy of Student” table:of Student” table:

1.1. Create an update query as follows to Create an update query as follows to add “4” to each Idnumberadd “4” to each Idnumber

Click Click RunRun

Click Click YesYes

Page 62: Master database management for cxc

QueriesTablesGetting Started

Append Query Cont’dAppend Query Cont’d

Since the IDs are now different we Since the IDs are now different we can continue:can continue:

Page 63: Master database management for cxc

QueriesTablesGetting Started

Append Query Cont’dAppend Query Cont’d

To create this query, we will use the To create this query, we will use the table from which we are copying the table from which we are copying the data (in this case data (in this case Student).Student).

Page 64: Master database management for cxc

QueriesTablesGetting Started

Append Query Cont’dAppend Query Cont’d

Select “Append Query” from the Select “Append Query” from the query tabquery tab

Select Select “Copy of “Copy of Student”Student”

Click OKClick OK

Page 65: Master database management for cxc

QueriesTablesGetting Started

Append Query Cont’dAppend Query Cont’d

Select “Append Query” from the Select “Append Query” from the query tabquery tab

Page 66: Master database management for cxc

QueriesTablesGetting Started

Append Query Cont’dAppend Query Cont’d

Run the QueryRun the Query

Click YesClick YesClick RunClick Run

Page 67: Master database management for cxc

QueriesTablesGetting Started

Append queryAppend query

““Copy of Student” table Copy of Student” table BeforeBefore APPENDAPPEND

Page 68: Master database management for cxc

QueriesTablesGetting Started

Append Query Cont’dAppend Query Cont’d

““Copy of Student” table Copy of Student” table AfterAfter APPENDAPPEND

Page 69: Master database management for cxc

QueriesTablesGetting Started

Append Query - ActivityAppend Query - Activity

Using an update query change the Using an update query change the Idnumber for Daniel from 187 to 200 Idnumber for Daniel from 187 to 200 in the Student tablein the Student table

Create a query to append the record Create a query to append the record for Daniel to the “Copy of Student” for Daniel to the “Copy of Student” table.table.

HINTHINT: Criteria may be needed.: Criteria may be needed.