---
title: "View in SQL"  
description: "A view is a SQL statement which is stored in the database with a name. A view is actually a formation of a table in the form of a predefined Structure"  
author: "Jayden Bell"  
published: 2016-07-05  
updated: 2018-03-16  
canonical: https://www.mindstick.com/blog/11175/view-in-sql  
category: "mysql"  
tags: ["database", "sql server", "sql"]  
reading_time: 4 minutes  

---

# View in SQL

A view is a SQL statement which is stored in the database with a name. A

view is actually a formation of a table in the form of a predefined

**[Structured Query Language](https://www.mindstick.com/blog/11168/introduction-to-sql) (SQL)** query.\

A view can select rows or contain all rows of a table. A view is created from

one or many tables which depends [SQL query](https://www.mindstick.com/forum/529/rename-table-name-and-column-name-using-sql-query) to create a view. A view

contains columns and rows, like a real table. The columns in a view are

columns from one or more real tables.

**Views are [virtual tables](https://www.mindstick.com/forum/158401/what-are-some-advanced-features-of-sqlite-such-as-virtual-tables-or-user-defined-functions), which enables users to do the following:·**

- [Structure data](https://answers.mindstick.com/qa/95258/how-do-i-remove-structure-data-errors-from-google-webmaster-tools) is a way that classes of users or users find natural or intuitive.
- Summarize data from tables which is used to generate reports.
- [Restrict access](https://www.mindstick.com/forum/160896/implement-row-level-security-in-sql-server-to-restrict-access-to-data-to-users) to the value such that a user can see and update exactly what they need and no more.

## Following is the syntax to create a view table:

SQL CREATE VIEW

## Syntax

```
CREATE VIEW name_of_view ASSELECT name_of_columnFROM name_of_tableWHERE condition
```

SQL CREATE VIEW example

Code [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp)

| ID | NAME | AGE | ADDRESS | MARKS |
| --- | --- | --- | --- | --- |
| 1 2 3 4 5 6 | Neha Ragini Shreya Kopal Rohan Avi | 18 19 17 18 18 19 | Mumbai Ahmedabad Pune Allahabad Banaras Kanpur | 35 45 23 24 43 36 |

```
CREATE VIEW [Student list] ASSELECT studentID, studentNameFROM studentWHERE Discontinued=No
```

\

In the above example, The view "student List" lists of all students from the

"student" table.

**Now, you can query student in similar way as you query an actual table.**

**Following is the example:**

```
SELECT * FROM student;
```

| Id | Name |
| --- | --- |
| 1 2 3 4 5 6 | Neha Ragini Shreya Kopal Rohan Avi |

SQL Updating a View

## Following is the syntax of updating a view:

**Syntax**

```
CREATE OR REPLACE VIEW name_of_view ASSELECT name_of_columnFROM name_of tableWHERE condition
```

Following is the example of updating a view:

**Code implementation**

```
UPDATE student SET AGE = 20WHERE name='Neha';
```

**Code output**

| ID | NAME | AGE | ADDRESS | MARKS |
| --- | --- | --- | --- | --- |
| 1 2 3 4 5 6 | Neha Ragini Shreya Kopal Rohan Avi | 20 19 17 18 18 19 | Mumbai Ahmedabad Pune Allahabad Banaras Kanpur | 35 45 23 24 43 36 |

**Deleting Rows into a View:**

Rows can be deleted from a view. The same rules are applied to DELETE

command that apply to the UPDATE command. Following is the example

to delete a row in a view:

**Code implementation**

```
DELETE FROM student      WHERE age = 20;
```

**Code output**

| ID | NAME | AGE | ADDRESS | MARKS |
| --- | --- | --- | --- | --- |
| 2 3 4 5 6 | Ragini Shreya Kopal Rohan Avi | 19 17 18 18 19 | Ahmedabad Pune Allahabad Banaras Kanpur | 45 23 24 43 36 |

As from the above example, we can see that record of “Neha” is deleted.

**Inserting Rows into a View:**

In a view rows can be inserted. The same rules are applied to INSERT

command that apply to the UPDATE command.

Here we cannot insert rows in [student table](https://www.mindstick.com/forum/157561/what-is-the-stored-procedure-create-a-procedure-to-find-the-record-by-stu_id-from-the-student-table) because we have not included

[NOT NULL](https://www.mindstick.com/interview/1933/what-is-not-null-constraint) columns in view, otherwise you can insert rows in a similar way

as you insert them in a table.

**Dropping Views:**

If view is no longer needed you can drop the view. Following is the syntax

for dropping views as given below:

```
DROP view name of view;
```

Following is the example of dropping view:

```
DROP view student;
```

Student view will be deleted.

---

Original Source: https://www.mindstick.com/blog/11175/view-in-sql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
