Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nagendra Vemulapalli Nagendra.vemulapalli@mail.wvu.edu Access chapters 3&6 Nagendra Vemulapalli Nagendra.vemulapalli@mail.wvu.edu.

Similar presentations


Presentation on theme: "Nagendra Vemulapalli Nagendra.vemulapalli@mail.wvu.edu Access chapters 3&6 Nagendra Vemulapalli Nagendra.vemulapalli@mail.wvu.edu."— Presentation transcript:

1 Nagendra Vemulapalli Nagendra.vemulapalli@mail.wvu.edu
Access chapters 3&6 Nagendra Vemulapalli

2 Announcement Lesson C in MyITLab is due today by 11:59pm
Homework 4 is due on 03/22/2013 by 11:59pm 4/9/2019 Nagendra Vemulapalli

3 Operators Note: This technique is similar to what part of a query asks for in HW4 ! 4/9/2019 Nagendra Vemulapalli

4 Date Field Entries for Birthday
Note Born field in Members table is completed Close Members table 4/9/2019 Nagendra Vemulapalli

5 Criteria & Operators Exercise
Go to Design view for RockTrivia, add the Born field. In the criteria row for born, add: >1/1/1960 Note we get 3 records Try making it: >=1/1/1950 AND <=1/1/1960 We get 9 Records Change it to: <1/1/1960 We get 13 records 4/9/2019 Nagendra Vemulapalli

6 Calculations in a Query…
Mathematical calculation can be done as part of the query.. We often do this for things that we do not need to store and take up space with Expressions can be entered into the query design grid as if they were regular fields Done on data type fields treated as numbers 4/9/2019 Nagendra Vemulapalli

7 Calculations in a Query…
To perform a calculation in a query, you must created a calculated field in query design. Make certain that you are following the rules of precedence !(Please Excuse My Dear Aunt Sally) Two options for entering expressions: Enter the expression directly into the field text box Enter the expression in the Expression Builder 4/9/2019 Nagendra Vemulapalli

8 Creating a Calculated Field
Remove the existing criteria Click in the next available blank field where the name would be, and then click the magic wand “Builder” icon above The expression builder shows up… 4/9/2019 Nagendra Vemulapalli

9 The Expression Builder…
4/9/2019 Nagendra Vemulapalli

10 Let’s make a Query to try this…
We want to figure out how many years they are/would be alive. It would be inefficient to store this and we would have to update it all the time too ! Build or type the following: Age: (Date()-[Members]![Born])/365 Note: If you see <<expr>> be sure to remove it ! ! ! Run it ! Expand the width of the column if you see #### 4/9/2019 Nagendra Vemulapalli

11 Changing Decimals Precision
Note: Similar to what is needed for to set decimal places on query results in homeworks!! YOU MUST RUN THE QUERY ONCE FIRST ! In design view, right click Age field Click Properties Select Fixed for Format and 0 for Decimal Places Re-run it to see it without the decimal places 4/9/2019 Nagendra Vemulapalli

12 Total Queries “Totals” in a query can group field values and also perform basic computational functions on them To make the Total row appear, you need to click the Sigma symbol “Totals” button in query design view ! 4/9/2019 Nagendra Vemulapalli

13 Premise We are running an investment firm and have some consultants working for us who have clients for which they manage investments. We want a query that will show us how many clients each consultant has and the total amount of investments each consultant is handling… Save locally and open Total_example.accdb 4/9/2019 Nagendra Vemulapalli

14 Structure of Tables & Relationship
This Database has not yet had a relationship created. We will do it in the query for this one. Sometimes under special circumstances you will create them here instead of in the relationships window. Generally it is done in the relationships window though… 4/9/2019 Nagendra Vemulapalli

15 Building the Total Query
Create ribbon > Queries group > Query Design Add both tables Create relationship inside query by dragging ConsultantID fields together 4/9/2019 Nagendra Vemulapalli

16 Building the Total Query
Add the field [Consultants]LastName Add the field [Clients]LastName Add the field [Clients]Assets Run it without Total options > back to design view Click the button on the Query Tools / Design ribbon to insert a “Total:” row Note that the default for each is “Group By” 4/9/2019 Nagendra Vemulapalli

17 Building the Total Query
We will Group By the last name of the consults to show each of them singularly We will Count the last names of the clients as they are tied to the consultants to show how many clients each has ! (Yes, kind of cool) We will Sum the assets of the clients to show how much all clients of each consultant have together 4/9/2019 Nagendra Vemulapalli

18 Setting up the Total Row
Have [Consultants] LastName as Group By Have [Clients] LastName as Count Have Assets as Sum Run the Query ! 4/9/2019 Nagendra Vemulapalli

19 Aliasing the Field Names
Sometimes for a Field, a Calculated field, or a Total field, we like to make the display name more specific in the query results To do this, simply change the field name in design view by adding a new name and an “:” An example for the clients LastName field: # of Clients: LastName 4/9/2019 Nagendra Vemulapalli

20 Alias the 3 fields in Design View
Consultant: LastName # Clients: LastName Total Assets: Assets Run the Query and note the field names in the dynaset ! 4/9/2019 Nagendra Vemulapalli

21 Doing Multiple Things to 1 Field
Sometimes you may need to do multiple total query-type actions to a single field. Download and open the file CSDemo.accdb from the site 4/9/2019 Nagendra Vemulapalli

22 Background for Total Query
Look at the contents of the Sales table We want to display our: Number of sales Total dollar amount of sales Average dollar amount sale 4/9/2019 Nagendra Vemulapalli

23 Creating the Total Query
Create a new query in design view Add the Sales Table Add the Amount field 3 Times ! ! ! Click button to show the Total row Set them to Count, Sum, and Average Run it ! Close Access 4/9/2019 Nagendra Vemulapalli

24 Using Referential Integrity
When dealing with related tables, you need to decide if you want to enforce “referential integrity”. Referential integrity allows you to maintain the integrity between related tables In our Rock & Roll Database we used referential integrity between bands and members 4/9/2019 Nagendra Vemulapalli

25 Referential Integrity
Primary Table Related Table 4/9/2019 Nagendra Vemulapalli

26 Referential Integrity
The rules of Referential integrity specify that when you add a record to a related table, there must be a matching record in the primary table! Ex: Cannot have a Member who is not from any of the Bands in the bands table. So, If you enforce Referential Integrity, you ensure that you will not have orphaned records (records that have no matching record in the primary table) 4/9/2019 Nagendra Vemulapalli

27 Cascade Update and Delete
After Enforcing the Referential Integrity the options for Cascade Updates and Delete show up. Cascade updates means making a change in a field that is common to two related tables will cause the update to be made in both tables In Cascade deletes, deleting a field that is common to two tables causes deletion in both tables Carefully consider whether you want to implement these features, as they can have dramatic effects on your data 4/9/2019 Nagendra Vemulapalli

28 Importing XML Data to Tables
Download and save these files on the desktop: Bands.xml Open Access Create a new blank database called Practice.accdb 4/9/2019 Nagendra Vemulapalli

29 Importing XML Data To Tables
External Data Ribbon > Import group > XML File Browse for first file Select Open & Ok 4/9/2019 Nagendra Vemulapalli

30 Importing Tables Exercise
Verify Structure and Data is checked This brings in the table & its records Later in the course we will use other options Click OK and Close Open the table in the database ! 4/9/2019 Nagendra Vemulapalli


Download ppt "Nagendra Vemulapalli Nagendra.vemulapalli@mail.wvu.edu Access chapters 3&6 Nagendra Vemulapalli Nagendra.vemulapalli@mail.wvu.edu."

Similar presentations


Ads by Google