A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/sql/sql-create-view-statement/ below:

SQL CREATE VIEW Statement - GeeksforGeeks

SQL CREATE VIEW Statement

Last Updated : 23 Jul, 2025

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:

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

expensive_products View:

product_id product_name price 1 Laptop 800 2 Smartphone 600 3 Tablet 120 5 Monitor 200

Explanation:

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

Departments table:

departments table

employee_department_info view:

Output of the employee_department_info view

Explanation:

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.



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4