Module 7: Implementing Views

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

Module 3: Creating and Tuning Indexes. Planning Indexes Creating Indexes Optimizing Indexes.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
Module 8: Implementing Views. Overview Introduction Advantages Definition Modifying Data Through Views Optimizing Performance by Using Views.
Database Systems More SQL Database Design -- More SQL1.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
Introduction to Databases Chapter 8: Improving Data Access.
Database Design for DNN Developers Sebastian Leupold.
Views: Limiting Access to Data A view is a named select statement that is stored in a database as an object. It allows you to view a subset of rows or.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
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 11: Programming Across Multiple Servers. Overview Introducing Distributed Queries Setting Up a Linked Server Environment Working with Linked Servers.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
11 Copyright © Oracle Corporation, All rights reserved. Creating Views.
Database Programming Sections 11 & 12 – Creating, and Managing Views, Sequences, Indexes, and Synonymns.
Views Lesson 7.
CpSc 3220 The Language of SQL The Language of SQL Chapters
Module 4 Designing and Implementing Views. Module Overview Introduction to Views Creating and Managing Views Performance Considerations for Views.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Module 3 Designing and Implementing Tables. Module Overview Designing Tables Working with Schemas Creating and Altering Tables.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Module 4: Implementing Data Integrity
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Permissions Lesson 13. Skills Matrix Security Modes Maintaining data integrity involves creating users, controlling their access and limiting their ability.
Indexes and Views Unit 7.
Module 11 Authorizing Users to Access Resources. Module Overview Authorizing User Access to Objects Authorizing Users to Execute Code Configuring Permissions.
Module 7: Implementing Views. Overview Introducing Views Defining and Using Views Using Views to Optimize Performance.
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 
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Database Management Systems Chapter 5 SQL.
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
SQL Server 2012 Session: 1 Session: 12 Triggers Data Management Using Microsoft SQL Server.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Module 8: Using Programming Objects for Data Retrieval.
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
SQL Triggers, Functions & Stored Procedures Programming Operations.
SQL Basics Review Reviewing what we’ve learned so far…….
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
Module 9: Implementing Functions. Overview Creating and Using Functions Working with Functions Controlling Execution Context.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Module 5: Working with Subqueries. Writing Basic Subqueries Writing Correlated Subqueries Comparing Subqueries with Joins and Temporary Tables Using Common.
CSED421 Database Systems Lab View. Page 2  Virtual or logical table which is defined as SELECT query with joins  Act as table but not real data, only.
IFS180 Intro. to Data Management Chapter 10 - Unions.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Implementing Views Advanced Database Dr. AlaaEddin Almabhouh.
CpSc 3220 The Language of SQL
Module 4: Creating and Tuning Indexes
Module 5: Implementing Data Integrity by Using Constraints
Overview Implementing Triggers Implementing XML Schemas.
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
Chapter 4 Indexes.
CH 4 Indexes.
Chapter 2 Views.
Using Table Expressions
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Database systems Lecture 3 – SQL + CRUD
SQL Fundamentals in Three Hours
CH 4 Indexes.
Chapter 2 Views.
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
Database Management System
IST 318 Database Administration
So What are Views and Triggers anyway?
SQL-Views and External Schemas
Presentation transcript:

Module 7: Implementing Views

Overview Introduction to Views Creating and Managing Views Optimizing Performance by Using Views

Lesson 1: Introduction to Views What Is a View? Types of Views Advantages of Views

What Is a View? Employee (table) vEmployee (view) EmployeeID LastName FirstName Title … 287 Mensa-Annan Tete Mr. 288 Abbas Syed 289 Valdez Rachel NULL vEmployee (view) LastName FirstName Mensa-Annan Tete Abbas Syed Valdez Rachel

Types of Views Standard views Combine data from one or more base tables (or views) into a new virtual table Indexed views Materialize (persist) the view through the creation of a unique clustered index on the view Partitioned views Join horizontally partitioned data from one or more base tables across one or more servers

Advantages of Views Focus the data for a user Mask database complexity Simplify management of user permissions Improve performance Organize data for export to other applications

Lesson 2: Creating and Managing Views Syntax for Creating Views Demonstration: Creating a View Syntax for Altering and Dropping Views How Ownership Chains Affect Views Sources of Information About Views View Encryption Considerations for Modifying Data in a View Practice: Creating a View

Syntax for Creating Views Use CREATE VIEW Transact-SQL statement: Restrictions: Cannot nest more than 32 levels deep Cannot contain more than 1,024 columns Cannot use COMPUTE, COMPUTE BY, or INTO Cannot use ORDER BY without TOP CREATE VIEW [ schema_name.] view_name [ (column [ ,...n ] ) ] [WITH [ENCRYPTION] [SCHEMABINDING] [VIEW_METADATA] ] AS select_statement [ ; ] [ WITH CHECK OPTION ]

Demonstration: Creating a View In this demonstration, you will see how to: Create a view Query a view Generate a script for a view

Syntax for Altering and Dropping Views Alter by using the ALTER VIEW Transact-SQL statement: Drop by using the DROP VIEW Transact-SQL statement: ALTER VIEW [ schema_name.]view_name [ (column [ ,...n ] ) ] [WITH [ENCRYPTION] [SCHEMABINDING] [VIEW_METADATA] ] AS select_statement [ ; ] [ WITH CHECK OPTION ] DROP VIEW [ schema_name.]view_name [ ...,n ] [ ; ]

How Ownership Chains Affect Views 2 View Owner: Mary Access view 1 User: John Dependency 3 View Owner: Mary Dependency 4 Table Owner: Tim

Sources of Information About Views SQL Server Management Studio Transact-SQL Source Information Object Explorer List of views in database Access to columns, triggers, indexes, and statistics defined on views View Properties dialog box Properties of individual views Source Information sys.views List of views in database sp_helptext Definition of non-encrypted views sys.sql_dependencies Objects (including views) that depend on other objects

View Encryption Use the WITH ENCRYPTION option on CREATE VIEW Transact-SQL statement Encrypts view definition in sys.syscomments table Protects view creation logic CREATE VIEW [HumanResources].[vEmployee] WITH ENCRYPTION AS SELECT e.[EmployeeID],c.[Title],c.[FirstName],c.[MiddleName] ,c.[LastName],c.[Suffix],e.[Title] AS [JobTitle] ,c.[Phone],c.[EmailAddress] FROM [HumanResources].[Employee] e INNER JOIN [Person].[Contact] c ON c.[ContactID] = e.[ContactID] Use WITH ENCRYPTION on ALTER VIEW statements to retain encryption

Considerations for Modifying Data in a View Views do not maintain a separate copy of data (indexed views are an exception) Updates to views modify base tables Restrictions: Cannot affect more than one base table Cannot modify columns derived from aggregate functions or calculations Cannot modify columns affected by GROUP BY, HAVING, or DISTINCT clauses Updates to views are restricted by using the WITH CHECK OPTION

Practice: Creating a View In this practice, you will create a view

Lesson 3: Optimizing Performance by Using Views Performance Considerations for Views What Is an Indexed View? What Is a Partitioned View?

Performance Considerations for Views Views introduce performance overhead because views are resolved dynamically Nested views introduce risk of performance problems Review definition of unencrypted nested views Use SQL Server Profiler to review performance Indexed views and partitioned views can improve performance

What Is an Indexed View? A view with a unique clustered index Materializes view, improving performance Allows query optimizer to use view in query resolution Use when: Performance gains outweigh maintenance overhead Underlying data is modified infrequently Queries perform a significant number of joins and aggregations CREATE UNIQUE CLUSTERED INDEX [IX_vStateProvinceCountryRegion] ON [Person].[vStateProvinceCountryRegion] ( [StateProvinceID] ASC, [CountryRegionCode] ASC)

What Is a Partitioned View? Joins horizontally partitioned data from a set of tables across one or more servers SQLServerNorth.Sales.Sale SQLServerSouth.Sales.Sale CREATE VIEW vSales AS SELECT * FROM SQLServerNorth.Sales.Sale UNION ALL SELECT * FROM SQLServerSouth.Sales.Sale vSales

Lab: Implementing Views Exercise 1: Creating Views Exercise 2: Creating Indexed Views Exercise 3: Creating Partitioned Views