What is a view in SQL?

101 Views

What is a view in SQL?

SQL | View

View in SQL is a kind of virtual table. It does not physical exists in our database but have rows and column as there we have in real database table. we can create a view by selecting fields from one or tables present in the database. A View can have all the rows of a table or specific rows based on certain condition.

 

The CREATE VIEW statement of SQL is used for creating Views.

Syntax:

CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

view_name: Name for the View
table_name: Name of the table
condition: Condition to select rows

Example:

 CREATE VIEW Employee AS
SELECT ID, NAME, SALARY
FROM employee
WHERE salary < 10000;
    +----+----------+----------+
    | ID | NAME     | SALARY   |
    +----+----------+----------+
    |  1 | Kamal    |  3000.00 |
    |  2 | Roshan   |  3000.00 |
    |  3 | Shyam    |  2000.00 |
    |  4 | Sagar    |  6500.00 |
    |  5 | Komal    |  8500.00 |
    +----+----------+----------+

 

Tags:-
SQL
MySQL

Today spacial posts