logo

Views in Relational Algebra & SQL

Introduction to Views

In some cases, it is not desirable for all users to see the entire logical model, i.e., all the actual relations stored in the database.

Consider a person who needs to know a customer's loan number but has no need to see the loan amount. This person should see a relation described, in the relational algebra, by a view.

Any relation that is made visible to a user as a "virtual relation" is called a view.

Views provide limited access to the database and present a tailored schema.

Views do not contain data of their own.

Views do not exist physically.

Uses of Views:

They help in query processing, such as simplifying commands for the user and storing complex queries.

They restrict access to the database.

They hide data complexity.

Database modifications (like insert, delete, and update operations) on views affect the actual relations in the database upon which the view is based (also true in SQL).

Views are stored in the data dictionary in the table called USER_VIEWS.

View Definition

A view is defined using the CREATE VIEW statement:

Where is any legal relational algebra query expression, and v represents the view name.

Example in SQL:

Once a view is defined, the view name can be used to refer to the virtual relation that the view generates.

Example:

View definition is not the same as creating a new relation by evaluating the query expression. Rather, a view definition saves an expression to be substituted into queries using the view. This means that wherever the view loan_customer is used, it is actually replaced by the equivalent query expression at runtime.

View in Relational Algebra:

Creating a view (loan-customer) consisting of all loan customers and their loan numbers:

We can find all loan customers and their loan numbers using this view.

Note: Wherever the view loan_customer is used, it is actually replaced by the equivalent query expression at runtime. This query is evaluated, and the entire answer is returned.

View in SQL: Example 1

Creating a view loan-customer from multiple tables:

We can find all loan customers and their loan numbers:

View in SQL: Example

Creating a view student-view from a single table:

To see the student_view:

Drop View

A view can be deleted using the DROP VIEW statement:

Next ❯ ❮ Previous
discription of faastop website
logo