0% found this document useful (0 votes)
0 views7 pages

SQL Create View, Replace View, Drop View Statements

Uploaded by

matias bahiru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views7 pages

SQL Create View, Replace View, Drop View Statements

Uploaded by

matias bahiru
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

7/15/25, 9:39 AM SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements

 Tutorials  Exercises  Services   Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

SQL Views
❮ Previous Next ❯

SQL CREATE VIEW Statement


In SQL, a view is a virtual table based on the result-set of an SQL statement.

A view contains rows and columns, just like a real table. The fields in a view are fields
from one or more real tables in the database.

You can add SQL statements and functions to a view and present the data as if the data
were coming from one single table.

A view is created with the CREATE VIEW statement.

CREATE VIEW Syntax

CREATE VIEW view_name AS


SELECT column1, column2, ...
FROM table_name
WHERE condition;

Note: A view always shows up-to-date data! The database engine recreates the view,
every time a user queries it.

https://www.w3schools.com/sql/sql_view.asp 1/7
7/15/25, 9:39 AM SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements

SQL Tutorials
 CREATE  VIEW
Exercises  Examples
Services   Sign In

HTML CSS
The following JAVASCRIPT
SQL SQLthat PYTHON
creates a view JAVA
shows all customers PHP HOW TO
from Brazil: W3.CSS C

Example Get your own SQL Server

CREATE VIEW [Brazil Customers] AS


SELECT CustomerName, ContactName
FROM Customers
WHERE Country = 'Brazil';

We can query the view above as follows:

Example
SELECT * FROM [Brazil Customers];

The following SQL creates a view that selects every product in the "Products" table with
a price higher than the average price:

Example

CREATE VIEW [Products Above Average Price] AS


SELECT ProductName, Price
FROM Products
WHERE Price > (SELECT AVG(Price) FROM Products);

We can query the view above as follows:

Example

https://www.w3schools.com/sql/sql_view.asp 2/7
7/15/25, 9:39 AM SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements

SELECTTutorials
* FROM [Products Above Average Price];
 Exercises  Services   Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

SQL Updating a View


A view can be updated with the CREATE OR REPLACE VIEW statement.

SQL CREATE OR REPLACE VIEW Syntax

CREATE OR REPLACE VIEW view_name AS


SELECT column1, column2, ...
FROM table_name
WHERE condition;

The following SQL adds the "City" column to the "Brazil Customers" view:

Example
CREATE OR REPLACE VIEW [Brazil Customers] AS
SELECT CustomerName, ContactName, City
FROM Customers
WHERE Country = 'Brazil';

SQL Dropping a View


A view is deleted with the DROP VIEW statement.

SQL DROP VIEW Syntax

https://www.w3schools.com/sql/sql_view.asp 3/7
7/15/25, 9:39 AM SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements

DROP VIEW
Tutorials  Exercises 
view_name;
Services   Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

The following SQL drops the "Brazil Customers" view:

Example
DROP VIEW [Brazil Customers];

?
Exercise
What is an SQL view?

A real table stored in the database

A virtual table based on the result-set of an SQL statement

A function that modifies data in the database

A temporary table used for backup purposes

Submit Answer »

❮ Previous Next ❯

Track your progress - it's free!


Sign Up Log in

https://www.w3schools.com/sql/sql_view.asp 4/7
7/15/25, 9:39 AM SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements

 Tutorials  Exercises  Services   Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

COLOR PICKER



 PLUS SPACES

https://www.w3schools.com/sql/sql_view.asp 5/7
7/15/25, 9:39 AM SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements

 Tutorials  Exercises 
GET CERTIFIED
Services 
FOR TEACHERS
 Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C

FOR BUSINESS CONTACT US

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    
https://www.w3schools.com/sql/sql_view.asp 6/7
7/15/25, 9:39 AM SQL CREATE VIEW, REPLACE VIEW, DROP VIEW Statements

FORUM ABOUT ACADEMY


 Tutorials  Exercises  Services  
W3Schools is optimized for learning and training. Examples might be simplified to improve
Sign In

reading and learning.


HTML
 CSS
Tutorials,JAVASCRIPT SQL
references, and examples PYTHON
are JAVA to PHP
constantly reviewed HOW
avoid errors, butTO W3.CSS
we cannot C
warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use,
cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

https://www.w3schools.com/sql/sql_view.asp 7/7

You might also like