Slides Rdbms 6

Embed Size (px)

Citation preview

  • 8/11/2019 Slides Rdbms 6

    1/36

  • 8/11/2019 Slides Rdbms 6

    2/36

  • 8/11/2019 Slides Rdbms 6

    3/36

  • 8/11/2019 Slides Rdbms 6

    4/36

  • 8/11/2019 Slides Rdbms 6

    5/36

  • 8/11/2019 Slides Rdbms 6

    6/36

  • 8/11/2019 Slides Rdbms 6

    7/36

    View:

    A view is a customized representation of data from one or more tables. The tables that the view isreferencing are known as base tables. A view can be considered as a stored query or a virtual table.Only the query is stored in the Oracle data dictionary; the actual data is not copied any-where. Thismeans that creating views does not take any storage space, other than the space in dictionary.

  • 8/11/2019 Slides Rdbms 6

    8/36

    For simple queries the results are generated row by row on the fly.

    For more complex views the DBMS must generate a temporary table representing the view and laterdiscard it.

  • 8/11/2019 Slides Rdbms 6

    9/36

    You must have permission on the table referred in the view to successfully create the view

    Can assign a new name to each column chosen in the viewOnly names can be different. The data type etc remain the same as the source table because, thevalues are after all going to be derived from that table

    If no names are specified for columns, the same name as used in the source table is used

  • 8/11/2019 Slides Rdbms 6

    10/36

    Note:

    We can assign names for the various columns in the view. This may be entirely different from whathas been used in the source table.If you use an asterisk (*) to select all columns from a table in the query to create a view, and you latermodify the table to add columns, you should re-create the view to reflect the new columns. When * is

    used, Oracle expands it to the column list and stores the definition in the database.

  • 8/11/2019 Slides Rdbms 6

    11/36

    Based on how the view is created. We will discuss them in detail in the following slides

  • 8/11/2019 Slides Rdbms 6

    12/36

    Here a horizontal subset of the source table is taken to create the view.

    Very useful when data belonging to different categories are present in the table.A private( virtual) table for each category can be created and given access to the person concerned

  • 8/11/2019 Slides Rdbms 6

    13/36

    Helps restricting access to sensitive information like salary, grade etc.

  • 8/11/2019 Slides Rdbms 6

    14/36

    SQL standard doesnt define any notion of horizontal or vertical views . It is for our ownunderstanding that we have given names for views which select only selected rows/columns from thesource table as horizontal/vertical views. There could be a combination of these two concepts wherea view selects a subset of rows and columns

  • 8/11/2019 Slides Rdbms 6

    15/36

  • 8/11/2019 Slides Rdbms 6

    16/36

    Using Join Views:

    A join view is a view with more than one base table in the top-level FROM clause. An updatable joinview ( or modifiable join view) is a view that can be used to update the base tables through the view.

  • 8/11/2019 Slides Rdbms 6

    17/36

  • 8/11/2019 Slides Rdbms 6

    18/36

    Depending on the commercial implementation being used, views may or may not be updateable. Insome cases, all views are not updateable. In some others a view is updateable if it is from one table,else it is not. In still others, a view is updateable if it is the result of a simple query; if it is defined bysome GROUP BY statements, for example, the view is not updateable.

    According to ANSI/ISO standards, A view is updatable if

    The DBMS is able to trace back the rows and columns of the view to the corresponding rows andcolumns of the source table.

    So a view is updatable if :

    DISTINCT is not specified in the query used to create the viewThe FROM clause specifies only one source table

    The select list doesnt contain expressions/calculated columnsThe WHERE clause doesnt include a subquery

    The query doesnt include a GROUP BY or HAVING

  • 8/11/2019 Slides Rdbms 6

    19/36

    if some other views depend on this view, then if you say

    DROP VIEW ViewSupplier CASCADE then this view plus all other views that are based on this vieware deleted.

    If you specify

    DROP VIEW ViewSupplier RESTRICT then this view cannot be deleted if other views depend on it.

  • 8/11/2019 Slides Rdbms 6

    20/36

  • 8/11/2019 Slides Rdbms 6

    21/36

    Security: only a limited set of rows/ columns are viewable by certain users.

    Query simplicity: A view can derive data from many tables. So, subsequently we can use querieson the view as single table queries rather than writing queries against the source tables as multi-tablequeries.Structural simplicity: views can show only a portion of the table which is relevant to the user there

    by keeping it simple.

  • 8/11/2019 Slides Rdbms 6

    22/36

    Performance: views based on joins are merely virtual tables. Every time a query is placed againstthe view, the query representing creation of the view has to be executed . So, complex joins mayhave to be performed every time a query is placed against the view.

    Restrictions: Not all views are updateable.

  • 8/11/2019 Slides Rdbms 6

    23/36

  • 8/11/2019 Slides Rdbms 6

    24/36

  • 8/11/2019 Slides Rdbms 6

    25/36

  • 8/11/2019 Slides Rdbms 6

    26/36

  • 8/11/2019 Slides Rdbms 6

    27/36

  • 8/11/2019 Slides Rdbms 6

    28/36

    Privileges on a specific table or a view created based on a table.

    Granting a privilege to the special user PUBLIC implicitly grants that privilege to any user whoconnects to the database.

  • 8/11/2019 Slides Rdbms 6

    29/36

  • 8/11/2019 Slides Rdbms 6

    30/36

    Object privileges can be granted WITH GRANT OPTION, which gives the grantee permission togrant those privileges to any other user, or to PUBLIC.

  • 8/11/2019 Slides Rdbms 6

    31/36

  • 8/11/2019 Slides Rdbms 6

    32/36

  • 8/11/2019 Slides Rdbms 6

    33/36

  • 8/11/2019 Slides Rdbms 6

    34/36

  • 8/11/2019 Slides Rdbms 6

    35/36

  • 8/11/2019 Slides Rdbms 6

    36/36