In SQLServer, a View is a virtual table that is the result set of an SQL query. Views simplify queries and they also hide the complexity of joins and other operations. The values in a view table can only be obtained from the based table. We
cannot modify the contents of a View.
They are also used to restrict access to certain columns or rows of a table and implements security mechanism. Its name must be unique.
Syntax:
Example to create a View in SQL Server:
In this example, we're creating a view called Emp that shows the Name and Empid of an employee. The view is based on the Employee table but only shows the Empid column and the Name column. Once the view is created, it can be used just like a regular table in SQL queries:
SELECT * FROM [Emp] WHERE Empid = 'E01';
This query will return the the Empid and Name of employee whose Empid equals '"E01" Note that views are read-only, so you cannot modify the data in the view directly. If you want to modify the underlying data, you'll need to modify the source table(s) instead.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
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.
In SQL Server, a View is a virtual table that is the result set of an SQL query. Views simplify queries and they also hide the complexity of joins and other operations. The values in a view table can only be obtained from the based table. We cannot modify the contents of a View.
They are also used to restrict access to certain columns or rows of a table and implements security mechanism. Its name must be unique.
Syntax:
Example to create a View in SQL Server:
In this example, we're creating a view called Emp that shows the Name and Empid of an employee. The view is based on the Employee table but only shows the Empid column and the Name column. Once the view is created, it can be used just like a regular table in SQL queries:
This query will return the the Empid and Name of employee whose Empid equals '"E01" Note that views are read-only, so you cannot modify the data in the view directly. If you want to modify the underlying data, you'll need to modify the source table(s) instead.