SQL View
DSE003 – DATABASE MANAGEMENT SYSTEM
HASANKA WIJESINGHE M I T , B . S c
What is SQL View?
 A virtual table created by a query by selecting fields
from one or more existing tables.
 Simplifies complex queries, enhances security, and
provides a convenient way to represent data.
Restrictions When Creating a View
Views cannot have ORDER BY clauses unless using the
LIMIT clause.
Views cannot contain subqueries in the FROM clause.
Restrictions When Creating a View
Views cannot have ORDER BY clauses unless using the
LIMIT clause.
Views cannot contain subqueries in the FROM clause.
Views cannot modify data (no INSERT, UPDATE, or DELETE
operations).
Syntax for Creating a View
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Syntax for Creating a View (Example)
CREATE VIEW employee_view AS
SELECT employee_id, first_name, last_name
FROM employees
WHERE department_id = 1;
Retrieve crated view
Syntax:
SELECT * FROM [view name];
Example:
SELECT * FROM employee_view;
Advantages of Using View
Simplifies Complex Queries: Abstracts complex joins and
calculations.
Enhances Security: Limits direct access to tables, providing
controlled data access.
Improves Performance: Can optimize and cache query
results.
Data Abstraction: Presents data in a way that makes sense
to users, hiding complexity.
Disadvantages of Using View
Performance Overhead: Views might impact performance,
especially with large datasets.
Limited Functionality: Restrictions on operations (no
modifications) limit their use.
Dependency: Changes in underlying tables might affect
views, requiring adjustments.
Complexity: Managing multiple views can become
complex, especially in large databases.
Exercise
Use companyDB:
1. Create a view to retrieve the department name with the
manager’s name and the manager's appointed date.
2. Create a view to retrieve dependent details with
employee name.
Hasanka Wijesinghe 13
Q & A
Hasanka Wijesinghe 14
Thank You!

Lec 09 SQL - 3.pptx

  • 1.
    SQL View DSE003 –DATABASE MANAGEMENT SYSTEM HASANKA WIJESINGHE M I T , B . S c
  • 2.
    What is SQLView?  A virtual table created by a query by selecting fields from one or more existing tables.  Simplifies complex queries, enhances security, and provides a convenient way to represent data.
  • 4.
    Restrictions When Creatinga View Views cannot have ORDER BY clauses unless using the LIMIT clause. Views cannot contain subqueries in the FROM clause.
  • 6.
    Restrictions When Creatinga View Views cannot have ORDER BY clauses unless using the LIMIT clause. Views cannot contain subqueries in the FROM clause. Views cannot modify data (no INSERT, UPDATE, or DELETE operations).
  • 7.
    Syntax for Creatinga View CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;
  • 8.
    Syntax for Creatinga View (Example) CREATE VIEW employee_view AS SELECT employee_id, first_name, last_name FROM employees WHERE department_id = 1;
  • 9.
    Retrieve crated view Syntax: SELECT* FROM [view name]; Example: SELECT * FROM employee_view;
  • 10.
    Advantages of UsingView Simplifies Complex Queries: Abstracts complex joins and calculations. Enhances Security: Limits direct access to tables, providing controlled data access. Improves Performance: Can optimize and cache query results. Data Abstraction: Presents data in a way that makes sense to users, hiding complexity.
  • 11.
    Disadvantages of UsingView Performance Overhead: Views might impact performance, especially with large datasets. Limited Functionality: Restrictions on operations (no modifications) limit their use. Dependency: Changes in underlying tables might affect views, requiring adjustments. Complexity: Managing multiple views can become complex, especially in large databases.
  • 12.
    Exercise Use companyDB: 1. Createa view to retrieve the department name with the manager’s name and the manager's appointed date. 2. Create a view to retrieve dependent details with employee name.
  • 13.
  • 14.