Open In App

What is a View? How it is Related to Data Independence in DBMS?

Last Updated : 11 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In DBMS, View is a virtual table that is created using specific rows of one more table. View does not create a new table with these entries, it only presents the selected rows together. Views are used to hide sensitive information from users. Views are used to display the information that is needed by the user, all other information that is sensitive or useless is hidden and not displayed in the view.

How to create the view?

A view can be created using the following Syntax

CREATE VIEW view_name AS SELECT column1, column2, ...FROM table_name WHERE condition.

Syntax for accessing the view is

SELECT * FROM view_name;

Example

Let's create a Table of students with three attributes i.e. Roll_No, Marks, and Phone_Number. The query for this will be:

CREATE TABLE Students (
Roll_No INT PRIMARY KEY,
Marks INT,
Phone_Number VARCHAR(15)
);Let's insert a few records into the table. The query for this will be
    INSERT INTO Students (Roll_No, Marks, Phone_Number)
    VALUES
    (1, 85, '1234567890'),
    (2, 90, '0987654321'),
    (3, 78, '1122334455'),
    (4, 92, '5566778899'),
    (5, 87, '6677889900');

    We will display the table with the following query
    SELECT * from Students;
    • The table will look like below


    table
    Table Students


    • Now we want to display the result but we do not want to expose the Phone_Number. So here we will create a view displaying Roll_No and Marks only.
    • The query for this will be as below:
    CREATE VIEW Results AS
    SELECT Roll_No, Marks
    FROM Students;
    • To display the view, the query will be
    SELECT * FROM Results;
    • The view will look like below:
    Screenshot-2024-05-26-202121
    View Results

    Data Independence in DBMS

    Data independence is used for the separation of the data from various application that needs the same data. In other words, it helps to change the database schema at one level of the system without affecting the database schema at other levels of the system. It is used to provide a clear separation of data between multiple applications.

    Data independence is of mainly 2 types

    1. Logical Data Independence

    • As the name suggests, the logical schema of the data is modified and it does not affect the physical structure of the data. The view of the data will be retained as it is but the logical level of retrieving the data will be modified.
    • It refers to adding new fields, changing the data types redefining the relations between the entities, and many more. For example, adding a new column to the table or combining/merging the 2 tables.

    2. Physical Data Independence

    • It mainly refers to the changing the physical level of data but the logical level schema is retained as it is.
    • There is change only in how data will be displayed but the logic of retrieving or accessing the data will be retained as it is.
    • Changing file indexes, changing the structures of files, or using different storage devices can be included in physical data independence.

    How View is related to data independence in DBMS

    Views help in obtaining data freedom from a Database Management System (DBMS) when acting as an abstraction layer between the physical storage of data by the users or applications that touch this data. This is how views enhance both physical and logical data independence:

    1. Logical Data Independence

    Abstraction of Complex Queries:

    • Views are an interface that makes it easier for users to understand complicated queries. We can adjust view definitions without changing the applications utilizing them once the fundamental schema is altered (such as modification to table structures or addition/deletion of some columns).
    • For instance, new columns can be introduced to the tables or the current ones rearranged, but this will only require updating the view definitions, leaving the applications intact as originally developed without any modifications.

    Uniform Interface:

    • Views give you a way to retrieve data that won't be affected by changes in the underlying schema of a database; therefore we can say that this makes them constant.
    • Illustration: In case your application reads data via a view and then your database administrator chooses to create two new tables from that one (all in the name of making the system better), the view may be modified to include such action. The user has no idea that the view is accessed by the application despite the structural change

    2. Physical Data Independence

    Hiding Physical Storage Details:

    • The data's physical storage details can be hidden from views, and physical storage details of the data can be abstracted by views. Change in the way actual data retrieval and storage mechanisms (e.g., indexing, file storage format) are done does not necessarily mean that users and applications will stop accessing the data through views.
    • Example: If the indexing strategy for performance is modified by the database administrator, changes may occur in the underlying tables but not the view, thus maintaining an interface for applications.

    Helping Changes in Physical Storage:

    • A physical transformation like moving information among storage drives or varying the physical organization of data (eg partitioning tables) does not have any effect on views. Views keep a level of generalization that protects users from such changes.
    • Example: Switching from heap storage to clustered storage format for tables doesn’t influence a view thus the applications using it remain as they were.

    Conclusion

    To summarize, views are powerful tools in DBMS that provide a method for displaying specific records in one or more tables without needing a separate table. Security problems are avoided with them. Data integrity is thereby maintained by them since there is a simplified interface from which information can be easily accessed that people need. Another way that they ensure data consistency is by decoupling between the type of data stored in the database and how it is stored


    Next Article
    Article Tags :

    Similar Reads