Views Lesson 7.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Characteristic Functions. Want: YearCodeQ1AmtQ2AmtQ3AmtQ4Amt 2001e (from fin_data table in Sybase Sample Database) Have: Yearquartercodeamount.
CMPT 354 Views and Indexes Spring 2012 Instructor: Hassan Khosravi.
Tables Lesson 6. Skills Matrix Tables Tables store data. Tables are relational –They store data organized as row and columns. –Data can be retrieved.
Concepts of Database Management Sixth Edition
PARTITIONING “ A de-normalization practice in which relations are split instead of merger ”
A Guide to MySQL 7. 2 Objectives Understand, define, and drop views Recognize the benefits of using views Use a view to update data Grant and revoke users’
A Guide to SQL, Seventh Edition. Objectives Understand, create, and drop views Recognize the benefits of using views Grant and revoke user’s database.
Chapter 9: Creating Database Conventions & Standards MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
MS Access: Database Concepts Instructor: Vicki Weidler.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Datasheets I: Create a table by entering data – You type, Access listens Lesson 18 By the end of this lesson you will be able to complete the following:
Performing Indexing and Full-Text Searching Lesson 21.
Functions Lesson 10. Skills Matrix Function A function is a piece of code or routine that accepts parameters and stored as an object in SQL Server. The.
1 © Prentice Hall, 2002 Physical Database Design Dr. Bijoy Bordoloi.
SQL Unit 5 Aggregation, GROUP BY, and HAVING Kirk Scott 1.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
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.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
Module 11: Programming Across Multiple Servers. Overview Introducing Distributed Queries Setting Up a Linked Server Environment Working with Linked Servers.
1 Intro to JOINs SQL INNER JOIN SQL OUTER JOIN SQL FULL JOIN SQL CROSS JOIN Intro to VIEWs Simple VIEWs Considerations about VIEWs VIEWs as filters ALTER.
SQL Server Indexes Indexes. Overview Indexes are used to help speed search results in a database. A careful use of indexes can greatly improve search.
© Pearson Education Limited, Chapter 15 Physical Database Design – Step 7 (Consider Introduction of Controlled Redundancy) Transparencies.
Using Special Operators (LIKE and IN)
Microsoft ® Office Access ™ 2007 Training Datasheets I: Create a table by entering data ICT Staff Development presents:
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Database Systems Microsoft Access Practical #3 Queries Nos 215.
M1G Introduction to Database Development 5. Doing more with queries.
Module 4 Designing and Implementing Views. Module Overview Introduction to Views Creating and Managing Views Performance Considerations for Views.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
1 CSE 2337 Introduction to Data Management Access Book – Ch 1.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Permissions Lesson 13. Skills Matrix Security Modes Maintaining data integrity involves creating users, controlling their access and limiting their ability.
Working with SQL Server Database Objects Faculty: Nguyen Ngoc Tu.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
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 - Structured Query Language)
SCALING AND PERFORMANCE CS 260 Database Systems. Overview  Increasing capacity  Database performance  Database indexes B+ Tree Index Bitmap Index 
Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at
Description and exemplification use of a Data Dictionary. A data dictionary is a catalogue of all data items in a system. The data dictionary stores details.
1 Information Retrieval and Use De-normalisation and Distributed database systems Geoff Leese September 2008, revised October 2009.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
There’s a particular style to it… Rob Hatton
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
1 Introduction to Database Systems, CS420 SQL Views and Indexes.
SQL Triggers, Functions & Stored Procedures Programming Operations.
Constraints Advanced Database Systems Dr. AlaaEddin Almabhouh.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
SQL Basics Review Reviewing what we’ve learned so far…….
1 Agenda TMA02 M876 Block 4. 2 Model of database development data requirements conceptual data model logical schema schema and database establishing requirements.
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.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Getting started with Accurately Storing Data
Databases: What they are and how they work
Implementing Views Advanced Database Dr. AlaaEddin Almabhouh.
Physical Changes That Don’t Change the Logical Design
Physical Database Design and Performance
Module 7: Implementing Views
Normalization Referential Integrity
Access: SQL Participation Project
Views 1.
Chapter 8 Views and Indexes
Responding to Data Manipulation Via Triggers
Presentation transcript:

Views Lesson 7

Skills Matrix

View A view can be queried just like a table. Microsoft describes a view as either a virtual table or a stored SELECT query, but you might prefer to think of it as similar to a filter. A view reveals data from one or more columns from one or more base tables, usually for limiting user data access to the totality of the base table. You use an indexed view which calculates aggregated data and for use when the cost of materializing the view proves less than the cost of aggregating data in a standard view.

View Yet another great reason to use views has to do with security. Permissions can be established on the view, which are independent of the base table(s) permissions.

View Not only can you use views to retrieve data, you can also modify data through them. Inserting records Updating records Deleting records

Modifying Data through a View If you use a view to modify data, the modification can affect only one base table at a time. You can’t modify data in a view that uses aggregate functions. Aggregates are functions that return a summary value of some kind, such as SUM( ) or AVG( ). If you try to modify such a view, you’ll get an error.

Modifying Data through a Views You saw earlier that views don’t necessarily present all the fields in a table. If you try to insert a record into a view that doesn’t show all fields, you could run into a problem. Some of the fields that aren’t shown in the view may not accept null values, but you can’t insert a value into those fields if they aren’t represented in the view. Because you can’t insert values in those fields, and they don’t allow null values, your insert will fail. You can still use such a view for UPDATEs and DELETEs, however.

Modifying Data through a Views To overcome these limitations, you need to use INSTEAD OF triggers.

Working with Indexed Views In reality, you’ll use queries that require a lot of calculation and data manipulation; such complex queries can take a toll on your system resources and thus slow it. Use indexed views to get around this bottleneck. Doing so does, however, slow data entry, as both the data itself and the materialized view must be updated.

Working with Indexed Views Using indexes on complex views has its benefits, the first being performance. Every time a view is queried, SQL Server must materialize the view. Materialization is the process of performing all the JOINs and calculations necessary to return a resultset to the user. If the view is complex (requiring a large number of calculations and JOINs), indexing it can speed up access because the resultset will never again need to be materialized,

Query Optimizer The Query Optimizer is the component in SQL Server that analyzes your queries, compares them with available indexes, and decides which index returns a result set the fastest. Once you’ve indexed a view, the Query Optimizer considers this view in all future queries no matter what you’re querying. This means queries on other tables may benefit from the index you create on the view.

Disadvantage of Indexing a View The disadvantage of indexing a view comes from the overhead it incurs on the system. First, indexed views take up disk space because they’re stored as separate objects in the database that look just like tables with a clustered index. Because clustered indexes store the actual data rather than just a pointer to the data in the base tables, they require extra disk space.

Disadvantage of Indexing a View When you update the underlying table or tables of the view, however, the indexed view must be immediately updated to reflect the changes to the base table. This means if you create an indexed view on a table and then make changes to the records in that table, SQL Server automatically updates the view at the same time.

Partitioned View A partitioned view displays horizontally divided data from a set of member tables across one or more servers, making the data appear as if from one table. The partitioned view uses the UNION ALL clause to combine the results of SELECT statements on all the member tables in a single result set.

Partitioned View SQL Server distinguishes between: Local partitioned views Distributed partitioned views In a local partitioned view, all participating tables and the view itself reside on the same instance of SQL Server. Use partitioned data locally by using partitioned tables rather than partitioned views. In a distributed partitioned view, at least one of the participating tables resides on a different (remote) server.

Summary You learned your view doesn’t actually contain any data—it’s just a filter through which you see the data in underlying tables. After that, you actually created a simple view based on a single table.

Summary Next you learned how to use a view to modify data. Don’t forget that modifying data through a view has a few caveats: You can’t modify more than one table at a time through a view. You can’t use views to modify aggregated data. If your view is based on a table that contains fields that don’t allow null values, yet your view doesn’t display those fields, then you won’t be able to insert new data. You can, however, update and delete data.

Summary Then you discovered you can index views. Doing so proves particularly useful if your view becomes complex; but be aware indexing can take a while to materialize. If you create an index on a view, SQL Server won’t need to populate the view every time someone queries it because the result set is stored in the database the same way a table with a clustered index is stored. Just remember that creating and maintaining indexed views has many caveats, so be absolutely sure you need them, and check the restrictions listed in Books Online.

Summary You can partition views in the same way you can partition tables and for the same reasons: store parts of your views on different spindles or even different servers.

Summary for Certification Examination Understand views. It sounds basic but you should know what views are. Views do not actually contain data; they are used to display the data stored in one or more columns in one or more base tables in a different format with different security controls. Know how to index a view. Views can be indexed to speed up query times, but they have a large number of restrictions. Review the list of considerations for indexing a view and make sure you are familiar with them.

Summary for Certification Examination Know how to make an updateable view. You can update the values in an underlying table used to create a view, but you need to consider a few issues. If you use a view to modify data, the modification can affect only one base table at a time. You can’t modify data in a view that uses aggregate functions such as Sum( ) or Avg( ). If you try to insert a record into a view that doesn’t show all fields, and if any of those missing fields do not accept null values, the insert fails. You can still use such a view for UPDATEs and DELETEs, though.

Summary for Certification Examination Know the advantages of partitioned views and when to use them.