SQL Views | SQL Tutorial and Query Example

Text copied!

SQL Views


  • Here's the basic syntax for creating a view in SQL :
    Here's an example of creating a simple view in SQL :

    1. Let's assume you have a database with two tables : [i]. Person [ii]. Departments

    Selecting View :

    5. Now, you can query this view as if it were a table.

    CREATE VIEW view_name 
    AS
    SELECT column1, column2, column3, ...
    FROM table_name;
            
    Deleting View :

    7. To drop (delete) a view in SQL, run below SQL statement.

    SQL Views
    CREATE VIEW Employees_view 
    AS
    SELECT e.[Name], e.GroupName, d.Department_Name
    FROM [Person] e
    JOIN [Departments] d ON d.Department_id = e.Department_id;
            
    SQL Views
    SELECT * FROM Employees_view;
            
    SQL Views
    DROP VIEW Employees_view;
            
    SQL Views

    Frequently Asked Questions :

    Views in SQL are virtual tables that display a subset of data from one or more tables.
    A SQL view is a virtual table based on the result-set of an SQL statement, while a table contains actual data.
    Benefits of views in SQL include data abstraction, security, simplified querying, and logical data independence.
    Views in SQL are used to provide a simplified and customized view of data, enhance security, and facilitate complex queries.