SQL VIEWS
A VIEW is a virtual table based on the result of a SQL SELECT query.
Syntax:Â Â Â Â
          CREATE VIEW view_name AS                                                                                     SELECT column1, column2, …                                                                                   FROM  table_name                                                                                           WHERE condition;
Let’s understand the views with an example. For demonstration purposes, we will be using the table emp.
     Table EMP
     Table Project
Example:
  Objective: In this example, we will create a view that will retrieve records from the Emp Table where the location is Texas.Â
           CREATE VIEW VW_Texas_Records AS                                                                               SELECT * FROM Tbl_EMP                                                                                       WHERE Location = ‘Texas’;
  View Query:
           SELECT * FROM VW_Texas_Records
  Output:
Example:
  Objective: In this example, we will use SQL joins to create views.Â
           CREATE VIEW VW_ProjectDetail AS                                                                                SELECT e.FirstName, e.LastName , e.Emailaddress, P.Project                                                             FROM Tbl_Emp as e INNER JOIN Tbl_Project as p                                                                     on e.Ecode = p.Ecode;
  View Query:
           SELECT * FROM VW_ProjectDetail;
  Output:
Drop View
Example:Â Â Â Â
         DROP VIEW VW_Texas_RecordsÂ
Alter View
Example:
  Objective: In this example, we will modify the existing view to add a condition where the department is IT.Â
           ALTER VIEW VW_Texas_Records AS                                                                               SELECT * FROM Tbl_EMP                                                                                       WHERE Location = ‘Texas’ and Department = ‘IT’;
  View Query:
           SELECT * FROM VW_Texas_Records
  Output: