week 3 lab1 review on database dina a. said [email protected]

21
Week 3 Lab1 Review on Database Dina A. Said [email protected]

Upload: ralph-whitehead

Post on 18-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Week 3 Lab1Review on Database

Dina A. [email protected]

Page 2: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Next Week (T1 & T2 only) Next Monday

Lab Quiz #2 on Databases Current Wednesday

“Week 1 Lab 2” of Problem Solving Thanks for TA Paul for Today slides

Page 3: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Uploading Data from Excel Got to the "External Data" tab and then select from the

Import section Excel.

1/21/2009 CPSC203- Week2- Lab1 3

Page 4: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

1/21/2009 CPSC203- Week2- Lab1 4

Page 5: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Create a new database named Stuff.

Page 6: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Create a table called Orders with the fields: OrderID,

ProductID, SalespersonName, SalesDate, Quantity and SellingPricePerPiece.

What is the primary key? Data type for ProductID? Data type for SalespersonName? Data type for SalesDate?

Page 7: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

To Create a new Table1. Choose Tab CreateTable

2. Write click on the table name to choose the design view

3. Start writing variables Names and types Notes:

Choose the unique variable to be primary key To make a variable primary key: choose the variable, right

click primary key Primary key variable is the one with yellow key to its left If you are required to enter values for ID, make its type

number instead of autonumber

1/21/2009 CPSC203- Week2- Lab1 7

Page 8: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Create a table called Products with the fields ProductID,

PName, PurchaseDate, Supplier and PurchasePricePerPiece.

What relationships might be required?

Page 9: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

To create a relationship 1. Choose tab Database Tools

2. Choose relationships

3. Choose both tables

4. To make a relationship between variable A and variable B

I. Drag variable A from the first table to variable B in the second table

II. A box will appear to you with the relationship variables

III. Make sure that variables names are correct and then press ok

1/21/2009 CPSC203- Week2- Lab1 9

Page 10: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Set the default quantity in the Orders table to 0. How?

1. Open the Design view of the required table

2. Choose the variable that you want to set its default value

3. Set default value in the bottom box

Page 11: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Add the following records to the products table:

ProductID: 10089 , PName: Bath Salts, PurchaseDate: 10/20/2008, Supplier: Bath and Beyond, PurchasePricePerPiece: $2

ProductID: 10768 , PName: Shower Gel, PurchaseDate: 10/1/2008, Supplier: Lush, PurchasePricePerPiece: $4.50

ProductID: 10769 , PName: Shampoo, PurchaseDate: 10/1/2007, Supplier: Lush, PurchasePricePerPiece: $8

Page 12: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Add the following data to the orders table:

1/21/2009 CPSC203- Week2- Lab1 12

orders

orderID productIDsalesManName

quantity orderDatesellingPricePerPiece

1 10089 John Smith 2 11/1/2009 5

2 10769 Lora Bill 1 12/1/2009 10

3 10768 Sandra smith

10 5/1/2009 9

4 10768 John Smith 5 2/1/2009 5

Page 13: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Create a query named query_1 that displays all the

information from both tables. How?

1. Choose create tab Query Wizard

2. Choose simple Query wizard

3. Choose both tables

4. Choose which fields you want to be displayed using >

5. If you want to not show a certain field after choosing it, use <

6. Rename the query as required

Page 14: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Create a query named query_2, using query_1, that

displays all fields in both tables, but limit the query to the Supplier "Lush".

How?1. Creating the query using simple query wizard to select all

fields from query-1

2. Open the query in the design view

3. In the suppler field, set the criteria to “Lush”

4. You can check SQL by right-click and choose Show SQL

Page 15: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Create an aggregate query named query_3. Group the

query using SalesPersonName and calculate the Average quantity he/she sells

Page 16: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

How to create Aggregate query?1. Create the query using simple query wizard and choose only salesPersonName and quantity

2. Open the query in the design view

3. Choose Totals

4. You will find a new row added

named total and the word GroupBy is written for both fields

5. For Quantity, change the word GroupBy to be Sum so that the sum of Quantity is displayed

6. Don’t forget to check SQL

1/21/2009 CPSC203- Week2- Lab1 16

Page 17: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Create a new query query_4, that displays all

information in table products. Then, create a new field called RevenueAmount. This should be calculated by Quantity*SellingPricePerPiece.

How? Create the Query using the simple query wizard Display SQL of query_4 Add to the select statement the following:

Select …., Quantity*SellingPricePerPiece as RevenueAmount

Page 18: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 In query_4, create a new field called Status. This should

display "Profit" if SellingPricePerPiece>PurchasePricePerPiece, "Breakeven" if they were equal and "Loss" otherwise.

First, write the expression in English statements if SellingPricePerPiece>PurchasePricePerPiece

Status=profit

Else if SellingPricePerPiece=PurchasePricePerPiece Status=equal

Else Status=loss

Page 19: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

How to make If statement? Go to the design view of the query Add anthoer field as:

Status:IIF(SellingPricePerPiece>PurchasePricePerPiece,

”Profit”, IIF(if SellingPricePerPiece=PurchasePricePerPiece,

“Equal”,”Loss))

1/21/2009 CPSC203- Week2- Lab1 19

Page 20: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Review for Lab Quiz #2 Create a crosstab query from query_1. Let the rows show

the SalesPersonName, the columns show the product name, and calculate the sum of Quantity.

How? Choose Create Query WizardCrosstab query Choose query query1 Select SalesPersonName in rows Select ProductName in column Select quantity as data and sum as function (on the right)

Page 21: Week 3 Lab1 Review on Database Dina A. Said dasaid@ucalgary.ca

Notes Take care which fields are required to be rows and which

fields are required to be columns Take care which function is required to be calculated; avg,

sum, max, etc…

1/21/2009 CPSC203- Week2- Lab1 21