Master database management for cxc
description
Transcript of Master database management for cxc
Database Database ManagementManagement
Microsoft Access – SimplifiedMicrosoft Access – Simplified
By: A. VanhorneBy: A. Vanhorne
QueriesTablesGetting Started
Starting Microsoft Starting Microsoft AccessAccess Click Blank
Database
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””
QueriesTablesGetting Started
Starting Microsoft Starting Microsoft AccessAccess Write your
database name here
QueriesTablesGetting Started
Starting Microsoft Starting Microsoft AccessAccess
Database Name
QueriesTablesGetting Started
Starting Microsoft Starting Microsoft AccessAccessClick Create
QueriesTablesGetting Started
Starting Microsoft Starting Microsoft AccessAccess
QueriesTablesGetting Started
Starting Microsoft Starting Microsoft AccessAccess
Click Create to see a list of the objects that
we can create in Microsoft Access
QueriesTablesGetting Started
Starting Microsoft Starting Microsoft AccessAccess
Our Focus will be on: Table Form Report Query
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
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
QueriesTablesGetting Started
Table Design ViewTable Design View
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
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
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
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
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
QueriesTablesGetting Started
Setting Primary KeySetting Primary Key
Select Idnumber
Select Primary Key
QueriesTablesGetting Started
Creating a Student TableCreating a Student Table
A Key appears beside Idnumber.
QueriesTablesGetting Started
Save the TableSave the Table
Click the save button
Enter “Student” for
the table name and click ok
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
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
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.
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.
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
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.
QueriesTablesGetting Started
Creating a Select QueryCreating a Select Query
Click on CreateClick on CreateSelect Query Select Query
DesignDesign
QueriesTablesGetting Started
Creating a Select QueryCreating a Select Query
Select StudentSelect Student
Click AddClick Add
QueriesTablesGetting Started
Creating a Select QueryCreating a Select Query
Select StudentSelect StudentClick Click
AddAddClick Click CloseClose
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
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
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
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
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.
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
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
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
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]
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]
Main Menu
The following summary options are often used in queries: Sum Average Maximum Minimum Count
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
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”
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
QueriesTablesGetting Started
Summary option Cont’dSummary option Cont’d
Your design view nowYour design view now
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
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
Main Menu
This query deletes specific records from a database table.
Example: to delete the student with Idnumber “113”.
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.
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
QueriesTablesGetting Started
Delete Query Cont’dDelete Query Cont’d
If Prompted, enable securityIf Prompted, enable securityClick
Options
Click Enable
Click Ok
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.
QueriesTablesGetting Started
Records after DeletionRecords after Deletion
The record has been removed from The record has been removed from the table:the table:
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
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
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]
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.
QueriesTablesGetting Started
Creating an Update Creating an Update QueryQuery
Select Run from the Results tabSelect Run from the Results tab
Click Click YesYes
QueriesTablesGetting Started
Update Query Cont’dUpdate Query Cont’d
Table before updateTable before update
Table after updateTable after update
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.
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
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
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:
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).
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
QueriesTablesGetting Started
Append Query Cont’dAppend Query Cont’d
Select “Append Query” from the Select “Append Query” from the query tabquery tab
QueriesTablesGetting Started
Append Query Cont’dAppend Query Cont’d
Run the QueryRun the Query
Click YesClick YesClick RunClick Run
QueriesTablesGetting Started
Append queryAppend query
““Copy of Student” table Copy of Student” table BeforeBefore APPENDAPPEND
QueriesTablesGetting Started
Append Query Cont’dAppend Query Cont’d
““Copy of Student” table Copy of Student” table AfterAfter APPENDAPPEND
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.