Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
SQL CREATE VIEW Statement
Next article icon

SQL CREATE VIEW Statement

Last Updated : 20 May, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The SQL CREATE VIEW statement is a very powerful feature in RDBMSs that allows users to create virtual tables based on the result set of a SQL query. Unlike regular tables, these views do not store data themselves rather they provide a way of dynamically retrieving and presenting data from one or many underlying tables.

This article explains how the SQL CREATE VIEW statement can be used to create, modify, and drop views, along with their pros and cons. It also provides practical examples of how database management can involve customized report generation, enforcing access control, and simplifying complex structures.

SQL CREATE VIEW Statement

The SQL CREATE VIEW statement is the central idea used to create a virtual table that does not store data itself but rather provides a dynamic representation of data obtained from one or more underlying tables. This arrangement lets users simplify intricate queries, improve security, and make abstracted data structures easy to access and manipulate.

Syntax:

The syntax to create a view in sql is as follows:

CREATE VIEW view_name AS

SELECT column1, column2, ...

FROM table_name

WHERE condition;

Explanation of Syntax:

  • CREATE VIEW view_name: This part of the statement specifies that a new view with the given name (view_name) will be created.
  • AS: This keyword is used to indicate that the following SELECT statement will define the structure and data for the view.
  • SELECT column1, column2, ...: Here, you specify the columns that you want the view to include. These can be columns from one or more tables or even expressions derived from those columns.
  • FROM table_name: This part of the statement specifies the table or tables whose data will populate your view.
  • WHERE condition: Optionally you may add a WHERE clause so as to give conditions under which data retrieved by this view should be filtered by. This is very helpful when creating views with subsets of data.

Examples of SQL CREATE VIEW Statement

The CREATE VIEW statement in SQL is used to create a virtual table based on the result of a query. Views help simplify complex queries and enhance security by restricting access to specific columns or rows.

Example 1: Creating a Simple View

Consider the table products having three columns product_id, product_name, and price. Suppose we have to create a view that contains only products whose prices are greater than $50.

Query:

CREATE VIEW expensive_products AS
SELECT product_id, product_name, price
FROM products
WHERE price > 100;

products Table:

products table
products table

expensive_products View:

product_idproduct_nameprice
1Laptop800
2Smartphone600
3Tablet120
5Monitor200

Explanation:

  • We develop a view called expensive_products.
  • The view obtains columns product_id, product_name, and price from table products.
  • We filter it so that it only includes rows with prices bigger than $100.

Example 2: Creating a Joined View

Assume that we have two tables employees and departments. We need to build a view combining information about both tables in order to show each employee’s name along with their department name:

Query:

CREATE VIEW employee_department_info AS
SELECT e.employee_id, e.first_name, e.last_name, d.department_name
FROM employees e
JOIN departments d ON e.department_id = d.department_id;

Employees table:

employees table
employees table

Departments table:

departments table
departments table

employee_department_info view:

output of the employee_department_info view
Output of the employee_department_info view

Explanation:

  • A view named employee_department_info is created by us.
  • Columns employee_id, first_name, last_name from employees table along with department_name from departments table are selected by this view.
  • An inner join between employees and departments on department_id is performed to get department name for each employee.

Now when querying the employee_department_info view we shall have a list of employees together with their corresponding department names.

Conclusion

In conclusion, the SQL CREATE VIEW statement is a useful resource for those in database development and administration because it creates virtual tables that provide simplified access to data stored in one or more underlying tables. The views encapsulate complex queries, control data access, and abstract the data structures enhancing the performance of Database Management Systems (DBMS), security, and manageability.

Therefore, by using views properly developers can avoid writing unnecessary code enhance query execution time, and finally make sure that their databases have a higher level of security when processing errors appear. View mastering is important in improving efficiency and effectiveness during database management tasks regardless of whether you are operating small-scale applications or significant enterprise databases.


Next Article
SQL CREATE VIEW Statement

R

roshan_wadhai
Improve
Article Tags :
  • SQL
  • Databases

Similar Reads

    MySQL CREATE VIEW Statement
    MySQL, an open-source relational database management system, offers a variety of features to manage and manipulate data efficiently. One of these features is the CREATE VIEW statement, which allows you to create a virtual table known as a view. A view provides a way to simplify complex queries, enha
    5 min read
    MySQL - ALTER VIEW Statement
    The ALTER VIEW statement in MySQL is a powerful tool that allows users to modify the definition of an existing view without the need to drop and recreate it. This statement is particularly useful for changing the query or structure of a view to better help the needs of the application or database de
    5 min read
    SQL CASE Statement
    The CASE statement in SQL is a versatile conditional expression that enables us to incorporate conditional logic directly within our queries. It allows you to return specific results based on certain conditions, enabling dynamic query outputs. Whether you need to create new columns, modify existing
    4 min read
    PostgreSQL - DROP VIEWS Statement
    A view in PostgreSQL can be seen as a virtual table that can contain all rows of a table or selected rows from one or more tables. Views allow us to see limited data instead of the complete information stored in a table. A view can be created from one or many base tables (the table from which the vi
    4 min read
    PL/SQL CREATE VIEW
    PL/SQL CREATE VIEW is a statement used to create a virtual table based on the result of a query. Views in PL/SQL allow users to access and manipulate data stored in one or more underlying tables as if it were a single table. In this article, We will learn about the PL/SQL CREATE VIEW by understandin
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences