Download presentation
Presentation is loading. Please wait.
Published byRandolph Johnston Modified over 8 years ago
1
CSIS 115 Database Design and Applications for Business Dr. Meg Fryling “Dr. Meg” Fall 2012 @SienaDrMeg #csis115 © 2012 Meg Fryling
2
Agenda Chapter 2: Advanced SQL Next Quiz (Mon, 12/3) –Take online via Blackboard before 11:59pm –Must complete quiz once it is started –Topics: Normalization & Other DB Issues Homework 4 –Due Wednesday, November 28 th by START of class
3
Rest of Semester Agenda 11/28: Advanced SQL 12/3: Advanced SQL –Online quiz on normalization & other DB issues 12/5: Forms and Reports Workshop –Online quiz on SQL 12/10: Review Final Exam –Thursday, December 13 th, 8:30-10:30am –RB350 (Open Lab) A-3
4
Student Evaluations Available starting tomorrow Have until midnight on December 11 th (Reading Day) to complete If I get at least a 95% response rate, I will drop the lowest quiz grade for everyone!
5
Normalization Activity Blackboard In-Class Activities > Normalization A-5
6
Common Design Problems 4-6 Multivalue/multicolumn problem Inconsistent values Comments mixed with other data Storing data that change too frequently A single column that should be split Missing input mask Missing check constraint
7
The Multivalue, Multicolumn Problem The multivalue, multicolumn problem occurs when multiple values of an attribute are stored in more than one column: EMPLOYEE (EmployeeNumber, EmployeeLastName, EmployeeLastName, Email, Phone1, Phone2, Phone3) This is another form of a multivalued dependecy. Solution = like solution for multivalued dependencies, use a separate table to store the multiple values. 4-7 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
8
Inconsistent Values Inconsistent values occur when different users, or different data sources, use slightly different forms of the same data value: –Different codings: SKU_Description = 'Corn, Large Can' SKU_Description = 'Can, Corn, Large' SKU_Description = 'Large Can Corn‘ –Different spellings: Coffee, Cofee, Coffeee 4-8 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
9
Storing Data that Changes to Frequently What’s the problem? Why is it a problem? A-9
10
Comments Mixed with Other Data What problems does this cause?? A-10
11
A Single Column that Should be Split KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall A-11
12
Missing Input Mask Missing Check Constraint A-12
13
Blackboard - In-Class Activity 7 Multivalue/multicolumn problem Inconsistent values Comments mixed with other data Storing data that change too frequently A single column that should be split Missing input mask Missing check constraint 6-13
14
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design, and Implementation Chapter Two: Introduction to Structured Query Language 2-14 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
15
Chapter Objectives SQL SELECT, FROM, WHERE, ORDER BY, GROUP BY, and HAVING clauses SQL DISTINCT, AND, OR, NOT, BETWEEN, LIKE, and IN keywords SUM, COUNT, MIN, MAX, and AVG functions Subqueries (we are going to skip these) Joining tables 2-15 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
16
Ad-Hoc Queries Ad-hoc queries: –Questions that can be answered using database data –Example: “How many customers in Portland, Oregon, bought our green baseball cap?” –Created by the user as needed, instead of programmed into an application –Common in business 2-16 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
17
Structured Query Language Structured Query Language (SQL) was developed by the IBM Corporation in the late 1970’s. SQL is not a full featured programming language. –C, C#, Java SQL is a data sublanguage for creating and processing database data and metadata. SQL is ubiquitous in enterprise-class DBMS products. SQL programming is a critical skill. 2-17 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
18
The SQL SELECT Statement The fundamental framework for an SQL query is the SQL SELECT statement. –SELECT{ColumnName(s)} –FROM{TableName(s)} –WHERE{Condition(s)} All SQL statements end with a semi-colon (;). 2-18 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
19
Cape-Codd Database [in Microsoft Access 2010] 2-19 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
20
Let’s Explore More SQL Open Cape-Codd Database KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall 6-20
21
SQL Built-In Functions I There are five SQL built-in functions: –Any field or * COUNT – counting rows returned –Number fields only SUM – Adding values in a number field AVG – Averaging values in a number field –Typically number fields MIN – Selecting the smallest value in a field MAX – Selecting the largest value in a field 2-21 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
22
SQL Built-In Functions Return the total of the ExtendedPrice field for all OrderNumber 3000 records (rows). Give the aggregate data returned meaningful labels 2-22 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
23
SQL Built-In Functions Return the total of the ExtendedPrice field for all OrderNumber 3000 records (rows). Give the aggregate data returned meaningful labels SELECTSUM(ExtendedPrice) ASOrder3000Sum FROMORDER_ITEM WHEREOrderNumber = 3000; 2-23 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
24
SQL Built-In Functions Return the total, average, minimum value, and maximum value of the ExtendedPrice field for all rows in the table. Give the aggregate data returned meaningful labels. 2-24 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
25
SQL Built-In Functions Return the total, average, minimum value, and maximum value of the ExtendedPrice field for all rows in the table. Give the aggregate data returned meaningful labels. SELECTSUM(ExtendedPrice) AS OrderItemSum, AVG(ExtendedPrice) AS OrderItemAvg, MIN(ExtendedPrice) AS OrderItemMin, MAX(ExtendedPrice) AS OrderItemMax FROMORDER_ITEM; 2-25 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
26
SQL Built-In Functions Count the number of rows in the ORDER_ITEM table. Label the count column returned as NumberOfRows 2-26 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
27
SQL Built-In Functions Count the number of rows in the ORDER_ITEM table. Label the count column returned as NumberOfRows SELECTCOUNT(*) AS NumberOfRows FROMORDER_ITEM; 2-27 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
28
SQL Built-In Functions Count the number of unique departments in the SKU_DATA table. Give the aggregate data returned a meaningful label. SELECTCOUNT (DISTINCT Department) AS DeptCount FROMSKU_DATA; 2-28 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
29
Arithmetic in SELECT Statements SELECTQuantity * Price AS EP, ExtendedPrice FROMORDER_ITEM; What is this query going to return? 2-29 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
30
String Functions in SELECT Statements SELECTDISTINCT RTRIM (Buyer) + ' in ' + RTRIM (Department) AS Sponsor FROMSKU_DATA; What is this query going to return? 2-30 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall NOTE: This SQL statement uses SQL Server 2008 R2 syntax (works for Access as well) —other DBMS products use different concatenation and character string operators.
31
The SQL Keyword GROUP BY SELECTDepartment, Buyer, COUNT(*) AS Dept_Buyer_SKU_Count FROMSKU_DATA GROUP BY Department, Buyer; What is this query going to return? 2-31 KROENKE AND AUER - DATABASE PROCESSING, 12th Edition © 2012 Pearson Prentice Hall
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.