Here we will explain to what is a View in SQL Server .how to create a view in SQL Server when we need to create a view in SQL server. How to retrieve all records from a view in SQL Server . How to hide the complexity of queries by using a view in SQL Server with Example.
A view is like a virtual table. The Data is exposes is not stored in the view object itself. View are composed of sql queries that references tables and other view . but they are referenced just like tables in queries. Views serve two major purposes in sql server. They can use to hide the complexity of queries. And they can used as a security device to limit the rows and columns of a table that a user can query . Views are expanded, meaning that their logic is incorporated into the execution plan for queries when you use them in queries and DML statements. SQL Server may not be able to use indexes on the base tables when the view is expanded, resulting in less-than optimal performance when querying views in some situations.
To overcome the query performance issues with views, SQL Server also has the ability to create a special type of view known as an indexed view. An indexed view is a view that SQL Server persisted to the database like a table. When you create an indexed view, SQL Server allocates storage for it and allows you to query it like any other table. There are, however, restrictions on inserting, updating, and deleting from an indexed view. For instance, you cannot perform data modifications on an indexed view if more than one of the view’s base tables will be affected. You also cannot perform data modifications on an indexed view if the view contains aggregate functions or a DISTINCT clause. You can also create indexes on an indexed view to improve query performance. The downside to an indexed view is increased overhead when you modify data in the view’s base tables, since the view must be updated as well.
here I am going to create a view in sql server.
Create View StudentView
select * from STUDENT
Here we are going to use view to retrive all records
select * from StudentView
I hope it will help full for you.