top of page
Writer's picturecompnomics

Understanding Views in Oracle SQL


What is a View?

A view in SQL is a virtual table that presents a subset of data from one or more underlying base tables. It doesn't store actual data but rather provides a dynamic view of the data based on the defined query. Views are often used to simplify complex queries, provide data security, and enhance data consistency.

Need for Views

  • Data Abstraction: Views can hide the complexity of underlying queries, making it easier for users to interact with the data.

  • Data Security: By carefully defining views, you can restrict access to specific columns or rows, ensuring data confidentiality.

  • Data Consistency: Views can help enforce data consistency by ensuring that data is always accessed through a defined query.

  • Query Simplification: Views can simplify complex queries by combining multiple tables or filtering data.


Creating Views

The basic syntax to create a view in Oracle SQL is:

CREATE VIEW view_name AS
SELECT column_name1, column_name2, ...
FROM table_name1, table_name2, ...
WHERE condition;

Example:

To create a view named STUDENT_DETAILS that displays only the STUDENT_IDSTUDENT_NAME, and ADDRESS columns:

CREATE VIEW STUDENT_DETAILS AS
SELECT STUDENT_ID, STUDENT_NAME, ADDRESS
FROM STUDENTS;

Types of Views

  • Simple Views: Created from a single base table.

  • Complex Views: Created from multiple base tables using joins.

  • Materialized Views: Pre-computed views that store the results of a query.

  • Fast Refresh Views: Materialized views that are refreshed periodically.


Deleting Views

To delete a view, use the following syntax:

DROP VIEW view_name;

Example:

To delete the STUDENT_DETAILS view:

DROP VIEW STUDENT_DETAILS;

Advantages of Views

  • Improved Data Security: Views can restrict access to sensitive data.

  • Simplified Queries: Views can simplify complex queries.

  • Data Consistency: Views can help ensure data consistency.

  • Enhanced Productivity: Views can increase developer productivity.


Limitations of Views

  • Performance Overhead: Complex views can impact performance, especially if they involve large datasets.

  • Dependency on Base Tables: If the underlying base tables change, the view may need to be updated.

  • Limited Functionality: Views cannot be used for DML operations (insert, update, delete) directly.


Rules for Deleting and Updating Views

  • Deleting Views: You can directly delete a view using the DROP VIEW statement.

  • Updating Views: You cannot directly update a view. Instead, you must update the underlying base tables.

  • DML Operations: Views are generally read-only. To perform DML operations, you need to create updatable views or use stored procedures.


By understanding the concepts of views and their advantages and limitations, you can effectively use them to enhance your database design and improve data management.

13 views0 comments

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page