DEV Community

Punitha
Punitha

Posted on

SQL Views

What is a View?

  • A View is a virtual table created from one or more existing tables using an SQL query.

  • It does not store data separately.

  • Instead, it displays data from the original table whenever it is queried.

Why Use a View?

  • Simplify complex SQL queries

  • Show only the required columns

  • Hide sensitive information (salary or password)

  • Improve security

  • Make reports easier to create

How Does a View Work?

Student Table
     |
CREATE VIEW
     |
Student_View
     |
SELECT * FROM Student_View;
Enter fullscreen mode Exit fullscreen mode

Syntax:

Create View

CREATE VIEW Student_View AS
SELECT Student_ID, Name, Marks
FROM Student;
Enter fullscreen mode Exit fullscreen mode

Retrieve Data

SELECT * FROM Student_View;
Enter fullscreen mode Exit fullscreen mode

Advantages of Views:

  • Easy to use

  • Improves security

  • Makes reports simple

  • Reuses SQL queries

Top comments (0)