SQL Views Chapter 3A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.

Slides:



Advertisements
Similar presentations
Object-Oriented Analysis and Design: Activity Diagrams
Advertisements

Chapter 1 Getting Started with Access Databases. Objectives Identify Good Database Design Create a Table and Define Fields in a New Blank Database Change.
Database Design Chapter Five DATABASE CONCEPTS, 6th Edition
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson,
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson,
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 7 th Edition.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Getting Started with Microsoft Visio 2010 Appendix G DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Getting Started Chapter One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Getting Started with Microsoft SQL Server 2012 Express Edition Appendix A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
David M. Kroenke and David J. Auer Database Processing—12 th Edition Fundamentals, Design, and Implementation Chapter One: Introduction KROENKE AND AUER.
Getting Started Chapter One DATABASE CONCEPTS, 7th Edition
Chapter One Customer Focus and Managing Customer Loyalty
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Eric Cameron, Jason Davidson, Rebecca Lawson,
Getting Started with Microsoft Access The Access Workbench: Section One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
Structured Query Language
Getting Started with Oracle Database 11g Release 2 Express Edition Appendix B DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Word 2010 by Robert Grauer, Michelle Hulett, and Mary.
Getting Started Chapter One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Structured Query Language Chapter Three DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Lynn Hogan, Amy Rutledge, Cyndi Krebs, Eric.
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. Access Module 1 Workshop 1 The Four Main Database Objects Series Editor Amy Kinser.
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. Access Module 2 Workshop 4 Accessing, Maintaining, and Presenting Information Series.
Chapter 3 Appendix Object-Oriented Analysis and Design: Project Management Modern Systems Analysis and Design Sixth Edition Jeffrey A. Hoffer Joey F. George.
SQL Views Appendix E DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Lynn Hogan, Amy Rutledge, Cyndi Krebs, Eric.
GO! with Office 2013 Volume 1 By: Shelley Gaskin, Alicia Vargas, and Carolyn McLellan Access Chapter 3 Forms, Filters, and Reports.
SQL Views Chapter 3A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
GO! All In One 2/E By: Shelley Gaskin, Nancy Graviett, Debra Geoghan Chapter 13 Creating and Editing Presentations with Microsoft PowerPoint 2013 Copyright.
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. Access Module 2 Workshop 3 Queries and Data Access Series Editor Amy Kinser by.
Business Intelligence Systems Appendix J DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
1 Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall.
Chapter Six Competitor Analysis and Sources of Advantage.
Integrating Word, Excel,
1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Mary Anne Poatsy, Keith Mulbery, Lynn Hogan, Amy Rutledge, Cyndi Krebs, Eric.
GO! with Office 2013 Volume 1 By: Shelley Gaskin, Alicia Vargas, and Carolyn McLellan Word Chapter 1 Creating Documents with Microsoft Word 2013.
STRUCTURED QUERY LANGUAGE SQL-III IST 210 Organization of Data IST210 1.
Services and Intangibles 10 Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall.
Getting Started Chapter One DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
SQL Views Chapter 3A. Appendix Objectives Learn basic SQL statements for creating views Learn basic SQL statements for using views Understand the reasons.
Skills for Success with Microsoft Office 2013 Volume 1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Kris Townsend, Catherine.
Skills for Success with Microsoft Office 2013 Volume 1 Copyright © 2014 Pearson Education, Inc. Publishing as Prentice Hall. by Kris Townsend, Catherine.
SQL-5 In-Class Exercise Answer IST 210 Organization of Data IST2101.
David M. Kroenke and David J. Auer Database Processing: F undamentals, Design, and Implementation Chapter Seven: SQL for Database Construction and Application.
GO! All In One 2/E By: Shelley Gaskin, Nancy Graviett, Debra Geoghan Chapter 8 Using Word to Create Resumes and Cover Letters Copyright © 2015 Pearson.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
© 2012 Pearson Education, Inc. publishing Prentice Hall. Note 9 The Product Life Cycle.
+ Complex SQL Week 9. + Today’s Objectives TOP GROUP BY JOIN Inner vs. Outer Right vs. Left.
GO! with Office 2013 Volume 1 By: Shelley Gaskin, Alicia Vargas, and Carolyn McLellan Access Chapter 1 Introduction to Microsoft Access 2013.
GO! with Office 2013 Volume 1 By: Shelley Gaskin, Alicia Vargas, and Carolyn McLellan Excel Chapter 3 Analyzing Data with Pie Charts, Line Charts, and.
Chapter Fourteen Building a Marketing Plan. Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall14-2 Building a Marketing Plan Creativity.
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design, and Implementation Chapter One: Introduction.
GO! with Office 2013 Volume 1 By: Shelley Gaskin, Alicia Vargas, and Carolyn McLellan Word Chapter 2 Using Tables and Templates to Create Resumes and Cover.
GO! with Office 2013 Volume 1 By: Shelley Gaskin, Alicia Vargas, and Carolyn McLellan PowerPoint Chapter 3 Enhancing a Presentation with Animation, Video,
GO! with Office 2013 Volume 1 By: Shelley Gaskin, Alicia Vargas, and Carolyn McLellan Excel Chapter 1 Creating a Worksheet and Charting Data.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Appendix A: Getting Started with Microsoft Access 2013.
David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation Appendix E: Getting Started with MySQL Workbench Data Modeling.
David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design, and Implementation Chapter Ten: Managing Databases with SQL Server 2012,
Organizational Behavior 15th Ed Diversity in Organizations Copyright © 2013 Pearson Education, Inc. publishing as Prentice Hall2-1 Robbins and Judge Chapter.
ISQS 6339, Business Intelligence Database vs. Data Warehouse
David M. Kroenke and David J
GO! with Microsoft® Access e
David M. Kroenke and David J
SQL Views Appendix C DATABASE CONCEPTS, 3rd Edition
Getting Started Chapter One DATABASE CONCEPTS, 5th Edition
Getting Started Chapter One DATABASE CONCEPTS, 4th Edition
Presentation transcript:

SQL Views Chapter 3A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Appendix Objectives Learn basic SQL statements for creating views Learn basic SQL statements for using views Understand the reasons for using views 3A-3 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

SQL Views A SQL view is a virtual table that is constructed from other tables or views A view has no data of its own, but uses data stored in tables or other views Views are created using SQL SELECT statements Views are used in other SELECT statements just as if they were a table The SQL statements that create the views may not contain an ORDER BY clause If the results of a query using a view need to be sorted, the sort order must be provided by the SELECT statement that processes the view 3A-4 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

SQL CREATE VIEW Statement The SQL CREATE VIEW statement is used to create view structures. CREATE VIEW ViewName AS {SQL SELECT statement}; 3A-5 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

SQL CREATE VIEW Example CREATE VIEW EmployeePhoneView AS SELECT FirstName, LastName, Phone AS EmployeePhone FROM EMPLOYEE; 3A-6 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Creating an SQL View in SQL Server 2008 R2 3A-7 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Creating an SQL View MySQL 5.1 3A-8 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Creating an SQL View-Equivalent Query in Microsoft Access A-9 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using an SQL SELECT Statement Once the view is created, it can be used in the FROM clause of SELECT statements just like a table. SELECT * FROM EmployeePhoneView ORDER BY LastName; 3A-10 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using the EmployeePhoneView in SQL Server 2008 R2 3A-11 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using the EmployeePhoneView in MySQL 5.1 3A-12 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using an SQL View-Equivalent Query in Microsoft Access 2010 I 3A-13 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using an SQL View-Equivalent Query in Microsoft Access 2010 II 3A-14 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using an SQL View-Equivalent Query in Microsoft Access 2010 III 3A-15 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Some Uses for SQL Views Hide columns or rows Display results of computations Hide complicated SQL syntax Layer built-in functions C-16 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Hide columns or rows I CREATE VIEW BasicDepartmentDataView AS SELECT DepartmentName, Phone AS DepartmentPhone FROM DEPARTMENT; SELECT * FROM BasicDepartmentDataView ORDER BY DepartmentName; 3A-17 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Hide columns or rows II CREATE VIEW MarkingDepartmentProjectView AS SELECT ProjectID, Name AS ProjectName, MaxHours, StartDate, EndDate FROM PROJECT WHERE Department = 'Marketing'; SELECT * FROM MarkingDepartmentProjectView ORDER BY ProjectID; 3A-18 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Display results of computations – SQL Statement CREATE VIEW ProjectHoursToDateView AS SELECT PROJECT.ProjectID, Name AS ProjectName, MaxHours AS ProjectMaxHours, SUM(HoursWorked) AS ProjectHoursWorkedToDate FROM PROJECT, ASSIGNMENT WHERE PROJECT.ProjectID = ASSIGNMENT.ProjectID GROUP BY PROJECT.ProjectID; 3A-19 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Display results of computations – Results SELECT * FROM ProjectHoursToDateView ORDER BY PROJECT.ProjectID; 3A-20 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Hide complicated SQL syntax – SQL Statement CREATE VIEW EmployeeProjectHoursWorkedView AS SELECT Name, FirstName, LastName, HoursWorked FROM EMPLOYEE AS E JOIN ASSIGNMENT AS A ON E.EmployeeNumber = A.EmployeeNumber JOIN PROJECT AS P ON A.ProjectID = P.ProjectID; 3A-21 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Hide complicated SQL syntax – Results SELECT * FROM EmployeeProjectHoursWorkedView; 3A-22 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Layering Computations and Built-in Functions 1 st SQL Statement CREATE VIEW ProjectHoursToDateView AS SELECT PPOJECT.ProjectID, Name AS ProjectName, MaxHours AS ProjectMaxHours, SUM(HoursWorked) AS ProjectHoursWorkedToDate FROM PROJECT, ASSIGNMENT WHERE PROJECT.ProjectID = ASSIGNMENT.ProjectID GROUP BY PROJECT.ProjectID; 3A-23 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Layering Computations and Built-in Functions 2 nd SQL Statement CREATE VIEW ProjectsOverAllotedMaxHoursView AS SELECT ProjectID, ProjectName, ProjectMaxHours, ProjectHoursWorkedToDate FROM ProjectHoursToDateView WHERE ProjectHoursWorkedToDate > ProjectMaxHours; 3A-24 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

Using SQL Views: Layering Computations and Built-in Functions Results SELECT ProjectID, ProjectName, ProjectMaxHours, ProjectHoursWorkedToDate, (ProjectHoursWorkedToDate - ProjectMaxHours) AS HoursOverMaxAllocated FROM ProjectsOverAllotedMaxHoursView ORDER BY ProjectID; 3A-25 KROENKE and AUER - DATABASE CONCEPTS (5th Edition) Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall

SQL Views End of Presentation on Chapter 3A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America. Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall