Uploaded by lissy Flower

Access2016TutorialINFS247

advertisement
INFS 247
MS Access Tutorial
SAMPLE DATABASE
This Access tutorial will use a database based on the following ER
diagram:
Slide 2
SAMPLE DATABASE
Relational Schema for the ER Diagram from the previous page:
Slide 3
CREATING A NEW DATABASE
•
To create a blank database:
–
–
–
–
–
Start Access 2016
Click the Blank Desktop Database icon once
Enter ExampleCompany in the file name text box that appears in the
middle of the screen.
Click the browse button next to the file name text box to select a
location to save the file
Click Create
• Access is saved different from typical Office documents:
– When the data is added, changed, or deleted — Access automatically
saves the changes
– Due to the automatic data-saving feature, when a new database is
created, Access saves it to a file before starting work
Slide 4
USING THE DATABASE WINDOW AND
OBJECT VIEWS
• Whenever a database is open, Access displays the
Navigation Pane.
– This serves as the central location for working with the database
objects (tables, queries, etc.)
– You can open and close the Navigation Pane by clicking the
Shutter Bar Open/Close Button (See next slide)
Slide 5
Shutter Bar Open/Close Button
Navigation Pane
This is what your Navigation Pane will look
like at the end of the tutorial. When you first
open a blank Access Database the Pane will
only include one table item. The Pane will
grow as you add tables, queries, etc.
Slide 6
Designing a Database
• Use the Design view to define the design of a new
blank table
• Design view is used to:
– Add, remove, or rearrange fields
– Define the name, the data type, and other properties of
each field
– Designate a primary key for the table
Slide 7
CREATE A TABLE
• Access 2016 automatically opens with a table in data sheet view. To change
the view to design view click view under the Home tab. Then enter the tables
name and click OK. To create a new, blank table in Design view and to add
fields and properties, select the Table Design under the Create tab and in
the table group.
Slide 8
Adding a Field
& Setting the Field Properties
• To add a new field to a table at the end of the list, click in the Field Name
column of the first blank row in the field list
• Each of the fields in a table is described by a set of properties
• The field's properties determine how the field's data is stored, handled, or
displayed
• The properties include:
– The field name, the data type, field size, etc …
– Every field is assigned a specific Data Type
• The default data type of a new field is Short Text
• To change a field's data type, click in the Data Type column for that field, and select a new Data
Type from the drop-down list
– The Field Size property controls the amount of space that is allocated for a particular field
• Available only for a field that has the Short Text or Number Data Type
• For a Short Text field, the Field Size specifies the maximum number of characters
– A value between 1 and 255, the default value is 255
• For a Number field, select a value from the drop-down list
Slide 9
Setting the Field Properties
Slide 10
DESIGNATING A PRIMARY KEY
• The primary key consists of one or more fields that
Access can use to uniquely identify the records
contained within the table
• To designate a field as the primary key, select the
field, click the Primary Key button located under
Table Tools Design Tab and within the tools group
Slide 11
DESIGNATING A PRIMARY KEY
Slide 12
Hands On – Build Tables
• Once you have opened Access 2016 and created the
ExampleCompany database file (see Slide # 2), click the views
button under the home tab, within the views group, and then click on
Design View.
• Enter EMPLOYEE as the Table name, and click OK
• Create fields for the following:
– Field Name = Essn, Data Type = Short Text, Field Size = 11, Primary Key
(you will re-name the default ID field into Essn and change the data type from AutoNumber to Short Text)
– Field Name = Ename, Data Type = Short Text, Field Size = 25
– Field Name = Dnumber, Data Type = Short Text, Field Size = 2
• Close the Tables dialog box, and click Yes to Save the changes
Slide 13
Hands On – Build Tables
• Click on the Create tab and within the tables group click on Table
Design
• Create fields for the following:
– Field Name = Dnumber, Data Type = Short Text, Field Size = 2, Primary Key
– Field Name = Dname, Data Type = Short Text, Field Size = 20
– Field Name = Dlocation, Data Type = Short Text, Field Size = 20
• Close the Tables dialog box, and click Yes to Save the changes
• Enter DEPARTMENT as the Table name, and click OK
Slide 14
Hands On – Build Tables
• Click on the Create tab and within the tables group click on Table
Design
• Create fields for the following:
–
–
–
–
Field Name = PID, Data Type = Short Text, Field Size = 3, Primary Key
Field Name = Pname, Data Type = Short Text, Field Size = 20
Field Name = Pdescription, Data Type = Short Text, Field Size = 40
Field Name = ControllingDeptNo, Data Type = Short Text, Field Size = 2
• Close the Tables dialog box, and click Yes to Save the changes
• Enter PROJECT as the Table name, and click OK
Slide 15
Hands On – Build Tables
• Click on the Create tab and within the tables group click on Table
Design
• Create fields for the following:
– Field Name = PID, Data Type = Short Text, Field Size = 3,
– Field Name = Essn, Data Type = Short Text, Field Size = 11,
Composite
Primary Key
(see next slide)
• Close the Tables dialog box, and click Yes to Save the changes
• Enter WORKS_ON as the Table name, and click OK
Slide 16
Hands On – Build Tables
Slide 17
SETTING UP TABLE RELATIONSHIPS
• Relationships between associated tables must be explicitly defined
• The required relationships must explicitly be defined before
Access can combine the related data
• Referential integrity – states that every non-null foreign key value
must match an existing primary key value
• When one table has a foreign key to another table, the concept of
referential integrity states that a record to the table that contains
the foreign key can not be added unless there is a corresponding
record in the linked table
Slide 18
Hands On – Create Relationships
• Open the Relationships window by clicking the Database Tools tab
and within the Relationships group click the Relationships button
• If MySysNavPaneGroup… tables show up in the Relationships
window, right click the top of each one and then click Hide Table
• Click the Show Table button, select each table listed (i.e.,
EMPLOYEE, DEPARTMENT, PROJECT and WORKS_ON) and
click the Add button
• Click on Close button in Show Table window.
Slide 19
Hands On – Create Relationships
• To define a new relationship, click and drag the Dnumber from the
DEPARTMENT table and drop it on the Dnumber in the
EMPLOYEE table
• Select the Enforce Referential Integrity box
• Click the Create button in the Edit Relationships dialog box that
Access shows
Slide 20
Hands On – Create Relationships
• To define another relationship, click and drag the Essn from the EMPLOYEE table
and drop it on the Essn in the WORKS_ON table
• Select the Enforce Referential Integrity box
• Click the Create button in the Edit Relationships dialog box that Access shows
• To define another relationship, click and drag the PID from the PROJECT table and
drop it on the PID in the WORKS_ON table
• Select the Enforce Referential Integrity box
• Click the Create button in the Edit Relationships dialog box that Access shows
• To define the last relationship, click and drag the Dnumber from the DEPARTMENT
table and drop it on the ControllingDeptNo in the PROJECT table
• Select the Enforce Referential Integrity box
• Click the Create button in the Edit Relationships dialog box that Access shows
• Close the Relationships window, and Save the layout
Slide 21
Hands On – Create Relationships
• Complete diagram with the Relationships is shown below
Slide 22
Hands On - Entering Data
• Entering data into a table
– In order to enter data in the table, you must open the table first by
double-clicking on the table name in the Navigation Pane. (If the
Navigation Pane is not visible click the Shutter Bar Open/Close
Button.
• Enter
– first: two records in DEPARTMENT table
– then: four records in EMPLOYEE table and two records in
PROJECT table
– and finally: six records in WORKS_ON table.
• Be careful of the order of data entry
– Why is the order of data entry important?
• Hint: Referential Integrity
Slide 23
Creating A Query
• A Query is a tool for extracting, combining, and
displaying data from one or more tables, according
to any criteria specified.
• Information is sorted, summarized (e.g., totals,
averages, counts), and displayed according to sort
criteria and/or results of calculations on data
Slide 24
Hands On – Create A Query
• Under the Create tab, and under the Queries group
select Query design
• First add EMPLOYEE table and then
DEPARTMENT table, and then click on Close
button in Show Table window.
Slide 25
Hands On – Create A Query
Slide 26
Hands On – Create A Query
• Click and drag Essn file from the EMPLOYEE table
and drop it to the field cell of the first query column
(see next slide)
• Click and drag Ename filed from the EMPLOYEE
table and drop it to the field cell of the second
query column (see next slide)
• Click and drag Dname filed from the
DEPARTMENT table and drop it to the field cell of
the third query column (see next slide)
Slide 27
Hands On – Create A Query
Slide 28
Hands On – Run A Query
• Run the query by clicking on the ! Icon. It is under
the Query Tools Design tab and within the Results
group.
• Save the query as “Employees and their
Departments” and close it.
• You can run this query any time by double-clicking
on either icon in the navigation pane.
Slide 29
Hands On – Run A Query
Your records will, of course, be different than the
ones in this slide
Slide 30
Creating A Form
• The purpose of a Form is to make the process of
inserting, modifying, and deleting records easier
and more visually appealing.
– Data shown in the form is obtained directly from one or
more tables or data that has been extracted using a
query
Slide 31
Hands On - Create a Form using the form
wizard
• Click on the Create Tab, and within the forms group click on the
Form Wizard button.
• In the first Form Wizard dialog box, you will select all the fields
needed to display on the form
• Select the EMPLOYEE table from the Tables/Query drop down list
• Move all the Available Fields, Essn, Ename, Dnumber, from the
Available Fields list to the Selected Fields list
• Click the Next button
• In the second Form Wizard dialog box, select the Columnar radio
button
Slide 32
Hands On - Create a Form using the form
wizard
Slide 33
Hands On - Create a Form using the form
wizard
Slide 34
Hands On - Create a Form using the form
wizard
•
Click the Next button to open the final wizard dialog box
•
In the final Form Wizard dialog box, the EMPLOYEE
table name is inserted into the form title text box
–
•
This assigns a name to the form and chooses the way the
form will initially be opened
Click the Finish button to have Access create the form
Slide 35
Hands On - Create a Form using the form
wizard
Slide 36
Hands On - Create a Form using the form
wizard
Your record will, of course, be different than the one in this slide
Slide 37
Hands On - Create a Form using the form
wizard
• Using the EMPLOYEE form, type in two more
records in the EMPLOYEE table (one of the new
employee records should have your first name)
Click on the New Record
Button (Right Arrow with Star
on the bottom of the screen)
before entering each new
record.
Close the form when finished
Slide 38
Generating Reports
• A Report is used primarily for printing selected
database information
• A report labels, groups, sorts, and summarizes the
data it presents
Slide 39
Hands On - use the Report wizard
• Click on the Create Tab, and within the Reports group click on the
Report Wizard
• In the first Report Wizard dialog box, select the query Employees
and their Departments, to be included in the report
• Move all the Available Fields, Essn, Ename, Dname, from the
Available Fields to the Selected Fields:
Slide 40
Hands On - use the Report wizard
Slide 41
Hands On - use the Report wizard
• Click the Next button
• In the second Report Wizard dialog box, when asked “How
do you want to view your data?”, choose the option
by DEPARTMENT
• Click the Next button
• Do not add any more grouping levels or any sorting
options, simply click the Next button twice again
Slide 42
Hands On - use the Report wizard
Slide 43
Hands On - use the Report wizard
• Make sure Stepped option is chosen as the lay out.
• Click the Next button
Slide 44
Hands On - use the Report wizard
Slide 45
Hands On - use the Report wizard
• In the final Report Wizard dialog box, the DEPARTMENT
table name is inserted into the title text box
– Change this name into Department and Employee Report
• Click the Finish button to have Access create the form
Slide 46
Hands On - use the Report wizard
Slide 47
Hands On - use the Report wizard
Your values shown will, of course, be different than the ones in this report
Slide 48
Close the report when finished
Download