Module 7: Implementing Views. Overview Introducing Views Defining and Using Views Using Views to Optimize Performance.

Slides:



Advertisements
Similar presentations
Basic SQL Introduction Presented by: Madhuri Bhogadi.
Advertisements

What Is a User-defined Function? Scalar Functions –Similar to a built-in function Multi-Statement Table-valued Functions –Content like a stored procedure.
Module 6: Working with Subqueries. Overview Introduction to Subqueries Using a Subquery as a Derived Table Using a Subquery as an Expression Using a Subquery.
Index Blocking Factors, Views Rose-Hulman Institute of Technology Curt Clifton.
Module 5: Implementing Data Integrity. Overview Types of Data Integrity Enforcing Data Integrity Defining Constraints Types of Constraints Disabling Constraints.
Stored Procedures and Functions Rose-Hulman Institute of Technology Curt Clifton.
Module 10: Implementing User-defined Functions. Overview What Is a User-defined Function? Defining Examples.
Module 9: Implementing Stored Procedures. Introduction to Stored Procedures Creating Executing Modifying Dropping Using Parameters in Stored Procedures.
Module 11: Implementing Triggers. Overview Introduction Defining Create, drop, alter triggers How Triggers Work Examples Performance Considerations Analyze.
Module 8: Implementing Views. Overview Introduction Advantages Definition Modifying Data Through Views Optimizing Performance by Using Views.
Module 7: Creating and Maintaining Indexes. Overview Creating Indexes Creating Index Options Maintaining Indexes Introduction to Statistics Querying the.
Module 9 Designing an XML Strategy. Module 9: Designing an XML Strategy Designing XML Storage Designing a Data Conversion Strategy Designing an XML Query.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
SQL Review Tonga Institute of Higher Education. SQL Introduction SQL (Structured Query Language) a language that allows a developer to work with data.
Database Management. ICT5 Database Administration (DBA) The DBA’s tasks will include the following: 1. The design of the database. After the initial design,
Defining Stored Procedures Named Collections of Transact-SQL Statements Encapsulate Repetitive Tasks Five Types (System, Local, Temporary, Remote, and.
Module 8: Implementing Stored Procedures. Introducing Stored Procedures Creating, Modifying, Dropping, and Executing Stored Procedures Using Parameters.
Module 1: Introduction to Transact-SQL
Module 9 Designing and Implementing Stored Procedures.
SQL/Lesson 4/Slide 1 of 45 Using Subqueries and Managing Databases Objectives In this lesson, you will learn to: *Use subqueries * Use subqueries with.
Module 4: Managing Security. Overview Implementing an Authentication Mode Assigning Login Accounts to Users and Roles Assigning Permissions to Users and.
Module 11: Programming Across Multiple Servers. Overview Introducing Distributed Queries Setting Up a Linked Server Environment Working with Linked Servers.
Module 5: Upgrading to SQL Server 7.0. Overview Planning an Upgrade Preparing to Upgrade Verifying the Upgrade Setting a Compatibility Level.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Views In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) In some.
Views Lesson 7.
Module 4 Designing and Implementing Views. Module Overview Introduction to Views Creating and Managing Views Performance Considerations for Views.
Chapter 2 Views. Objectives ◦ Create simple and complex views ◦ Creating a view with a check constraint ◦ Retrieve data from views ◦ Data manipulation.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Module 3 Designing and Implementing Tables. Module Overview Designing Tables Working with Schemas Creating and Altering Tables.
Module 4: Implementing Data Integrity
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Permissions Lesson 13. Skills Matrix Security Modes Maintaining data integrity involves creating users, controlling their access and limiting their ability.
Module 7: Modifying Data. Overview Using Transactions Inserting Data Deleting Data Updating Data Performance Considerations.
Module 11 Authorizing Users to Access Resources. Module Overview Authorizing User Access to Objects Authorizing Users to Execute Code Configuring Permissions.
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
Creating Views. 2 home back first prev next last What Will I Learn? List three uses for views from the standpoint of a database administrator Explain,
Working with SQL Server Database Objects Faculty: Nguyen Ngoc Tu.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Session 1 Module 1: Introduction to Data Integrity
SQL Server 2005 Implementation and Maintenance Chapter 6: Security and SQL Server 2005.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
Module 5: Managing Content. Overview Publishing Content Executing Reports Creating Cached Instances Creating Snapshots and Report History Creating Subscriptions.
Chapter 13 Triggers. Trigger Overview A trigger is a program unit that is executed (fired) due to an event Event such as updating tables, deleting data.
SQL Triggers, Functions & Stored Procedures Programming Operations.
SQL Basics Review Reviewing what we’ve learned so far…….
Module 6: Creating and Maintaining Indexes. Overview Creating Indexes Understanding Index Creation Options Maintaining Indexes Introducing Statistics.
Module 9: Implementing Functions. Overview Creating and Using Functions Working with Functions Controlling Execution Context.
Module 9: Implementing User-Defined Functions. Overview Introducing User-Defined Functions Implementing User-Defined Functions.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Module 5: Working with Subqueries. Writing Basic Subqueries Writing Correlated Subqueries Comparing Subqueries with Joins and Temporary Tables Using Common.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Controlling User Access
Implementing Views Advanced Database Dr. AlaaEddin Almabhouh.
Controlling User Access
Controlling User Access
Module 10: Implementing Triggers
STORED PROCEDURES AND FUNCTION (9.6.1)
Module 7: Implementing Views
MySQL Joins MySQL joins are used to combine rows from two or more tables. Different SQL JOINs INNER JOIN: Returns all rows when there is at least one match.
Module 5: Implementing Data Integrity by Using Constraints
Chapter 2 Views.
Chapter 2 Views.
Contents Preface I Introduction Lesson Objectives I-2
IST 318 Database Administration
Manipulating Data Lesson 3.
Presentation transcript:

Module 7: Implementing Views

Overview Introducing Views Defining and Using Views Using Views to Optimize Performance

Lesson: Introducing Views What Are Views? Advantages of Views

What Are Views? EmployeeView Lastname Firstname Davolio Fuller Leverling Davolio Fuller Leverling Nancy Andrew Janet Nancy Andrew Janet Employees EmployeeID LastName Firstname Title Davolio Fuller Leverling Davolio Fuller Leverling Nancy Andrew Janet Nancy Andrew Janet ~~~ USE Northwind GO CREATE VIEW dbo.EmployeeView AS SELECT LastName, Firstname FROM Employees USE Northwind GO CREATE VIEW dbo.EmployeeView AS SELECT LastName, Firstname FROM Employees User’s View

Advantages of Views Focus the Data for Users Mask Database Complexity Simplify Management of User Permissions Improve Performance Organize Data for Export to Other Applications

Lesson: Defining and Using Views The Process of Creating Views Example: View of Joined Tables The Process of Altering and Dropping Views Broken Ownership Chains Location of View Information Encrypted View Definition Restrictions for Modifying Data Through Views

The Process of Creating Views Creating a View Restrictions on View Definitions  Cannot include ORDER BY clause  Cannot include INTO keyword CREATE VIEW dbo.OrderSubtotalsView (OrderID, Subtotal) AS SELECT OD.OrderID, SUM(CONVERT(money,(OD.UnitPrice*Quantity*(1-Discount)/100))*100) FROM [Order Details] OD GROUP BY OD.OrderID GO CREATE VIEW dbo.OrderSubtotalsView (OrderID, Subtotal) AS SELECT OD.OrderID, SUM(CONVERT(money,(OD.UnitPrice*Quantity*(1-Discount)/100))*100) FROM [Order Details] OD GROUP BY OD.OrderID GO

USE Northwind GO CREATE VIEW dbo.ShipStatusView AS SELECT OrderID,ShippedDate,ContactName FROM Customers c INNER JOIN Orders o ON c.CustomerID = O.CustomerID WHERE RequiredDate < ShippedDate USE Northwind GO CREATE VIEW dbo.ShipStatusView AS SELECT OrderID,ShippedDate,ContactName FROM Customers c INNER JOIN Orders o ON c.CustomerID = O.CustomerID WHERE RequiredDate < ShippedDate Example: View of Joined Tables OrdersCustomers ShipStatusView OrderID ShippedDate ContactName Laurence Lebihan Georg Pipps Horst Kloss Laurence Lebihan Georg Pipps Horst Kloss BONAP PICCO QUICK BONAP PICCO QUICK Laurence Lebihan Georg Pipps Horst Kloss Laurence Lebihan Georg Pipps Horst Kloss CustomerID ContactName Bon app' Piccolo und mehr QUICK-Stop Bon app' Piccolo und mehr QUICK-Stop CompanyName BONAP PICCO QUICK BONAP PICCO QUICK ~~~ OrderID CustomerID ShippedDate RequiredDate

The Process of Altering and Dropping Views Altering Views  Retains assigned permissions  Causes new SELECT statement and options to replace existing definition Dropping Views USE Northwind GO ALTER VIEW dbo.EmployeeView AS SELECT LastName, FirstName, Extension FROM Employees USE Northwind GO ALTER VIEW dbo.EmployeeView AS SELECT LastName, FirstName, Extension FROM Employees DROP VIEW dbo.ShipStatusView

Dependent Objects with Different Owners Example: Maria executes: Pierre executes: Broken Ownership Chains GRANT SELECT ON view2 TO pierre SELECT * FROM maria.view2 maria.view2 lucia.view1 lucia.table1

Location of View Information Locating View Definitions  Not available if view was created using WITH ENCRYPTION option Locating View Dependencies  Lists objects upon which view depends  Lists objects that depend on a view

Encrypted View Definition Use the WITH ENCRYPTION Option Do Not Delete Entries in the syscomments Table CREATE VIEW dbo.[Order Subtotals] WITH ENCRYPTION AS SELECT OrderID, Sum(CONVERT(money,(UnitPrice*Quantity*(1-Discount)/100))*100) AS Subtotal FROM [Order Details] GROUP BY OrderID GO CREATE VIEW dbo.[Order Subtotals] WITH ENCRYPTION AS SELECT OrderID, Sum(CONVERT(money,(UnitPrice*Quantity*(1-Discount)/100))*100) AS Subtotal FROM [Order Details] GROUP BY OrderID GO

Restrictions for Modifying Data Through Views Views Do Not Maintain a Separate Copy of Data  Modifications are done to the actual base table Restrictions  Must not include aggregate functions or GROUP BY  Cannot affect more than one underlying table  Cannot be made to certain columns  Are verified if the WITH CHECK OPTION has been specified

Lesson: Using Views to Optimize Performance Potential Performance Problems Indexed Views Partition Data Using Views Best Practices

Potential Performance Problems TotalPurchaseView 1 1 ~ ~ ~ ~ ~ ~ ~ ~ 2 2 ~ ~ ~ ~ ~ ~ ~ ~ 3 3 ~ ~ ~ ~ ~ ~ ~ ~ 4 4 ~ ~ ~ ~ ~ ~ ~ ~ 5 5 ~ ~ ~ ~ ~ ~ ~ ~ 6 6 ~ ~ ~ ~ ~ ~ ~ ~ TopSalesView ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ USE Northwind GO CREATE VIEW dbo.TopSalesView AS SELECT * FROM dbo.TotalPurchaseView WHERE Subtotal > GO USE Northwind GO CREATE VIEW dbo.TopSalesView AS SELECT * FROM dbo.TotalPurchaseView WHERE Subtotal > GO SELECT * FROM dbo.TopSales WHERE CompanyName = 'Ernst Handel' SELECT * FROM dbo.TopSales WHERE CompanyName = 'Ernst Handel'

Indexed Views Indexed Views Store the Result Sets in the Database Creating an Indexed View Guidelines for Creating Indexed Views Use when:  Performance gains outweigh maintenance costs  Underlying data is infrequently updated  Queries perform many joins and aggregations Restrictions on Creating Indexed Views

Partition Data Using Views You Can Use Views to Partition Data Across Multiple Servers or Instances of SQL Server How SQL Server Uses Views to Partition Data How Partitioned Views Improve Performance

Best Practices Use a Standard Naming Convention dbo Should Own All Views Verify Object Dependencies Before You Drop Objects Never Delete Entries In The syscomments Table Carefully Evaluate Creating Views Based On Views

Lab A: Implementing Views Exercise 1: Creating and Testing Views Exercise 2: Encrypting a View Definition Exercise 3: Modifying Data Through Views Exercise 4: Locating View Definitions