Views

Learn how to create and use views in T-SQL.

We'll cover the following

In T-SQL, a SELECT query can be reused multiple times without having to write it down on every occasion. We can save a SELECT query for future use as a view.

Views can be thought of as virtual tables. But unlike tables, when we select from a view, a SELECT query that was saved as the view is executed to retrieve the data dynamically.

Syntax

To create a view, we use the CREATE VIEW command:

CREATE VIEW ViewName
AS
[SELECT query];

We use a view like we would use a regular table:

SELECT * FROM ViewName;

As soon as we select from a view, the inner SELECT query is executed, and data is retrieved.

Using a view

Let’s consider this table with student names and grades.

Get hands-on with 1400+ tech skills courses.