Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports.

Similar presentations


Presentation on theme: "CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports."— Presentation transcript:

1 CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports

2 CSC 240 (Blum)2 Recall that our database had four tables: Customer, Item, Order and ItemInOrder

3 CSC 240 (Blum)3 Lookup Wizard Recall that we used the Lookup Wizard to establish relationships between tables, for example the Order table has a field corresponding to the CustomerID. When entering an order, a person will be presented with a drop-down list of customers. There is an implication here that the customer data precedes the order data. Similarly the order data and item data precede the item-in-order data. The logic/structure of our database design implies a logic/order to data entry.

4 CSC 240 (Blum)4 Data Entry Dependence CustomerItem Order ItemInOrder Customer must precede Order. Order and Item must precede ItemInOrder.

5 CSC 240 (Blum)5 Double click on the Customer table to open it up in DataSheet view.

6 CSC 240 (Blum)6 Enter some customer data

7 CSC 240 (Blum)7 What one can do in DataSheet view In DataSheet view, one can look at the data, add new data, remove any of the data and change any of the existing fields. With more sophisticated database, one will separate out these possibilities and assign different users different permissions. One will specify whether a user can SELECT, INSERT, DELETE and UPDATE particular data.

8 CSC 240 (Blum)8 Open the Item table in DataSheet view and enter some data.

9 CSC 240 (Blum)9 Open up the Order table

10 CSC 240 (Blum)10 It’s not all or nothing In order to start associating items with an order in the ItemInOrder table we must first have the corresponding Order record. But that does not mean we must know the final value for every field in the Order record. –Clearly we will not immediately know the OrderDateShipped.

11 CSC 240 (Blum)11 Go to the View drop-down selector and choose Design View

12 CSC 240 (Blum)12 Make sure the OrderDateShipped is not required.

13 CSC 240 (Blum)13 Back in DataSheet view when one clicks in the CustomerID field a drop-down arrow appears on the right. Use it to lookup the Customer. Recall we designed it to show customer names even though we are really looking up customer IDs.

14 CSC 240 (Blum)14 Strictly speaking it is looking up CustomerID, but the user is expected to supply customer names. If one types something that is not a valid customer last name and hit Enter, an error message results. Referential Integrity!

15 CSC 240 (Blum)15 Even if one enters a valid customer ID, it does not accept it – since we told Access the user would be using customer names here, that is what it expects. (If one types a valid last name, it accepts it.)

16 CSC 240 (Blum)16 Enter some Order records.

17 CSC 240 (Blum)17 Open the ItemInOrder table in DataSheet view and enter some data.

18 CSC 240 (Blum)18 If one tries to enter a duplicate item within the same order, an error message arises because the combination of Order and Item serves as a primary key and thus must be unique for each record. (Occurs when you try to move to another record.)

19 CSC 240 (Blum)19 No escape After entering an invalid record –If there are other records to enter, there is no problem. –If there are not, one will have started a record that is invalid and trying to leave it will produce error messages and give the data entry person a sense that the cannot escape from this problem. –Closing the table will produce some error messages but will produce the desired result – all of the previously entered valid records will be saved and the invalid record will not.

20 Saving occurs more often than in other Office applications and without the user explicitly selecting Save. CSC 240 (Blum)20

21 CSC 240 (Blum)21 Click on the Create tab and then on Query Design.

22 CSC 240 (Blum)22 Introduction to Querying The approach we will be taking here is known as Query-by-Example. The language for querying is SQL, so we could also write a SQL statement. The first step is to settle on a question to ask. –Let us start with something simple such as what are our customer’s names. The next step is to add the tables necessary to answer the question. –This query involves only the customer table.

23 CSC 240 (Blum)23 Select the Customer table and click Add to make it part of the query. (Close if this is the only table you want.)

24 CSC 240 (Blum)24 Next drag the fields involved in the query into the grid below.

25 CSC 240 (Blum)25 Click on the drop-down list in the View button and select DataSheet View.

26 CSC 240 (Blum)26 DataSheet View shows the results of the query. This query might be called a projection – it “projects” out the fields we want to see.

27 CSC 240 (Blum)27 Click on the drop-down list in the View button and select SQL View.

28 CSC 240 (Blum)28 SQL View shows a SQL statement that would yield the results of the Query-by-Example.

29 CSC 240 (Blum)29 One can use the drop-down box in the Sort field under the CustomerLastName to choose Ascending to place the names in alphabetical order by last name.

30 CSC 240 (Blum)30 DataSheet View of Alphabetized results

31 CSC 240 (Blum)31 SQL View of Alphabetized results

32 CSC 240 (Blum)32 When one closes the query, one is prompted to save it, give it a name.

33 Use the drop-down on the left-hand side to select Queries to obtain list of queries. CSC 240 (Blum)33

34 CSC 240 (Blum)34 Next design a query that shows only customers from PA. Add the CustomerState field to the query and add a condition to the corresponding Criteria field. Such a query can be called a “selection” – as it selects out records that satisfy some condition.

35 CSC 240 (Blum)35 Results of PA Selection

36 CSC 240 (Blum)36 Uncheck the show checkbox under state so that it is involved in the query but not displayed in the results.

37 CSC 240 (Blum)37 Results of PA Selection without state showing.

38 CSC 240 (Blum)38 SQL View of state selection query. Access generates more parentheses than necessary.

39 CSC 240 (Blum)39 Change the criteria field to a phrase in square brackets to allow the user of the query to enter a state during the query’s execution.

40 CSC 240 (Blum)40 Executing the query now gives rise to an input box for the user to enter a state. Such a query is said to be “parametrized” or “parameterized.”

41 CSC 240 (Blum)41 Results of parameterized state query.

42 CSC 240 (Blum)42 SQL View of Parameterized state query.

43 CSC 240 (Blum)43 Save the parameterized query

44 CSC 240 (Blum)44 The Join Next create a query that lists the orders and the names and phone numbers of those who have placed those orders. This query requires information from two tables: Customer and Order. The tables are said to be “joined.” –More on what that actually means another time, let us just see the results on it here.

45 CSC 240 (Blum)45 Add Customer and Order to the query, then add the desired fields to the grid, choose to sort by Ascending on the OrderID. If that line connecting the tables is not there, make it by dragging the CustomerID field in one table over to the CustomerID field in the other table.

46 CSC 240 (Blum)46 Customer-Order join results in DataSheet View

47 CSC 240 (Blum)47 SQL View of Customer-Order join

48 CSC 240 (Blum)48 Save the Customer-Order query

49 CSC 240 (Blum)49 Building a Customer-Items query Next we want a list of the customers, their phone numbers and the items they have ordered. This involves all four tables – since the relationship of customer is to order, and the relationship of order to item is realized through the ItemInOrder table.

50 CSC 240 (Blum)50 Add the tables, drag the desired fields to the grid, etc.

51 CSC 240 (Blum)51 Customer-Item query in DataSheet View

52 CSC 240 (Blum)52 Customer-Item query in SQL View

53 CSC 240 (Blum)53 Save CustomerItems query.

54 CSC 240 (Blum)54 Suppose we had to recall an item. We would want a list of customers who had bought a particular item. One decision in such a query is whether we select on the item’s name or item’s ID. –Let us choose here to go with ID. One might want to make accompanying queries that will either provide the user with a list of item names and Ids or a parameterized query allowing the user to supply the name and obtain the corresponding ID. Recall query

55 CSC 240 (Blum)55 Design of parameterized recall query.

56 CSC 240 (Blum)56 DataSheet View of parameterized recall query. Recall that we told Access to show us the Item name instead of the itemID in the ItemInOrder table.

57 CSC 240 (Blum)57 SQL View of parameterized recall query.

58 CSC 240 (Blum)58 Save the parameterized query.


Download ppt "CSC 240 (Blum)1 Introduction to Data Entry, Queries and Reports."

Similar presentations


Ads by Google