SQL Views Chapter 3A. Appendix Objectives Learn basic SQL statements for creating views Learn basic SQL statements for using views Understand the reasons.

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,
SQL Views Chapter 3A. Appendix Objectives Learn basic SQL statements for creating views Learn basic SQL statements for using views Learn basic SQL statements.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
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.
SQL Views Chapter 3A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 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.
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.
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.
1 Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
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.
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.
Chapter Five Market Segmentation and Segmentation Strategies.
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.
© 2012 Pearson Education, Inc. publishing Prentice Hall. Note 18 Generic Strategies—The Value Map.
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 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

Appendix Objectives Learn basic SQL statements for creating views Learn basic SQL statements for using views Understand the reasons for using views

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 However, Oracle allows you to create the views that contain an ORDER BY clause

SQL CREATE VIEW Statement The SQL CREATE VIEW statement is used to create view structures. CREATE VIEW ViewName AS {SQL SELECT statement};

SQL CREATE VIEW Example Create a view to list the city and product name for each product ordered by its quantity: create view v_products as select city, pname as myname from products order by quantity;

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 v_products;

Some Uses for SQL Views Hide columns or rows Display results of computations Hide complicated SQL syntax Layer built-in functions

Using SQL Views: Hide columns or rows I Why do we want to hide columns/rows? 1. simplify results 2. security reasons prevent the display of sensitive data CREATE VIEW BasicDepartmentDataView AS SELECT DepartmentName, Phone AS DepartmentPhone FROM DEPARTMENT; SELECT * FROM BasicDepartmentDataView ORDER BY DepartmentName;

Using SQL Views: Hide columns or rows II How do we hide rows? Using WHERE clause CREATE VIEW MarkingDepartmentProjectView AS SELECT ProjectID, Name AS ProjectName, MaxHours, StartDate, EndDate FROM PROJECT WHERE Department = 'Marketing'; SELECT * FROM MarkingDepartmentProjectView ORDER BY ProjectID;

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;

Using SQL Views: Display results of computations – Results SELECT * FROM ProjectHoursToDateView ORDER BY PROJECT.ProjectID;

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;

Using SQL Views: Hide complicated SQL syntax – Results SELECT * FROM EmployeeProjectHoursWorkedView;

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;

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;

Using SQL Views: Layering Computations and Built-in Functions Results SELECT ProjectID, ProjectName, ProjectMaxHours, ProjectHoursWorkedToDate, (ProjectHoursWorkedToDate - ProjectMaxHours) AS HoursOverMaxAllocated FROM ProjectsOverAllotedMaxHoursView ORDER BY ProjectID;

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