0% found this document useful (0 votes)
8 views20 pages

Database_Views_Enhanced_Presentation

Views are virtual tables in databases that display data from other tables without storing it, enhancing abstraction and security. There are three main types of views: Simple, Complex, and Materialized, each serving different purposes and functionalities. Views can simplify SQL queries, but they have limitations such as potential performance issues and restrictions on updates.

Uploaded by

aslamaslamkhan53
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views20 pages

Database_Views_Enhanced_Presentation

Views are virtual tables in databases that display data from other tables without storing it, enhancing abstraction and security. There are three main types of views: Simple, Complex, and Materialized, each serving different purposes and functionalities. Views can simplify SQL queries, but they have limitations such as potential performance issues and restrictions on updates.

Uploaded by

aslamaslamkhan53
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Views in Database

Definition, Uses, Types, Examples,


Creation and Deletion
What is a View?
• - A view is a virtual table based on SQL query
results.
• - It doesn’t store data but shows data from
other tables.
• - Useful for abstraction and simplification.
Example: Basic View
• CREATE VIEW high_salary AS
• SELECT name, salary FROM employees WHERE
salary > 50000;
Why Use Views?
• - Simplifies complex SQL.
• - Enhances data security.
• - Offers different perspectives on data.
• - Supports logical independence.
Use Case Example
• - Manager needs only name and salary:
• CREATE VIEW manager_view AS
• SELECT name, salary FROM employees;
Types of Views - Overview
• - Simple View
• - Complex View
• - Materialized View
Simple View
• - Based on a single table
• - No group functions or joins

• Example:
• CREATE VIEW emp_names AS
• SELECT name FROM employees;
Complex View
• - Based on multiple tables
• - Can include functions, joins, groupings

• Example:
• CREATE VIEW dept_salary AS
• SELECT d.name, AVG(e.salary) FROM
employees e JOIN departments d ON
e.dept_id = d.id GROUP BY d.name;
Materialized View
• - Stores data physically for better
performance.
• - Needs to be refreshed.

• Example:
• CREATE MATERIALIZED VIEW mat_view AS
SELECT * FROM sales;
Creating Views - Syntax
• CREATE VIEW view_name AS
• SELECT columns FROM table WHERE
condition;
Creating Views - Example
• CREATE VIEW active_users AS
• SELECT username, last_login FROM users
WHERE status = 'active';
Using Views in Queries
• SELECT * FROM high_salary;
• SELECT name FROM emp_names WHERE
name LIKE 'A%';
Updating Data Through Views
• - Views can be updatable if based on a single
table without joins or aggregation.

• Example:
• UPDATE high_salary SET salary = salary + 5000
WHERE name = 'Ali';
Limitations of Views
• - Cannot always update
• - Cannot include certain clauses
• - Performance overhead in complex views
Dropping a View
• Syntax:
• DROP VIEW view_name;

• Example:
• DROP VIEW high_salary;
Advantages of Views
• - Simplifies access
• - Provides security
• - Reduces data complexity
• - Enables reusability of queries
Disadvantages of Views
• - Performance issues
• - Not always updatable
• - Maintenance of complex views can be hard
Best Practices
• - Name views clearly
• - Use views for security and abstraction
• - Keep views simple when possible
Real-Life Application Example
• - In a banking system, views can be used to
show account summary, filter active accounts,
or hide sensitive columns.
Summary
• - Views = Virtual Tables
• - Help in abstraction, security, and simplicity
• - Various types: Simple, Complex, Materialized
• - Create/Use/Drop views with SQL

You might also like