Theme-Logo
  •   .Net
    •   C Sharp(C#)
    •   Web API
    •   Micro Services
    •   ASP.Net
    • ASP.Net MVC
    • .Net Core
  •   Database
    • SQL Server
    • Oracle
    • PostgreSQL
  •   jQuery
    • jQuery Tutorials
    • jQuery Plugins
    • jQuery UI
    • More on jquery
  •   Tutorials
    • Microservices Tutorials
    • DotNet Core Tutorials
    • PostgreSql Tutorials

View in SQL Server

A view is a virtual table whose contents are defined by a query. Like a table, a view consists of a set of named columns and rows of data. Unless indexed, a view does not exist as a stored set of data values in a database. The rows and columns of data come from tables referenced in the query defining the view and are produced dynamically when the view is referenced.

A view acts as a filter on the underlying tables referenced in the view. The query that defines the view can be from one or more tables or from other views in the current or other databases. Distributed queries can also be used to define views that use data from multiple heterogeneous sources. This is useful, for example, if you want to combine similarly structured data from different servers, each of which stores data for a different region of your organization.

Views are generally used to focus, simplify, and customize the perception each user has of the database. Views can be used as security mechanisms by letting users access data through the view, without granting the users permissions to directly access the underlying base tables of the view. Views can be used to provide a backward compatible interface to emulate a table that used to exist but whose schema has changed. Views can also be used when you copy data to and from SQL Server to improve performance and to partition data.

Types Of View in SQL Server

Besides the standard role of basic user-defined views, SQL Server provides the following types of views that serve special purposes in a database.

  • Indexed Views
  • An indexed view is a view that has been materialized. This means the view definition has been computed and the resulting data stored just like a table. You index a view by creating a unique clustered index on it. Indexed views can dramatically improve the performance of some types of queries. Indexed views work best for queries that aggregate many rows. They are not well-suited for underlying data sets that are frequently updated.
  • Partitioned Views
  • A partitioned view joins horizontally partitioned data from a set of member tables across one or more servers. This makes the data appear as if from one table. A view that joins member tables on the same instance of SQL Server is a local partitioned view.
  • System Views
  • System views expose catalog metadata. You can use system views to return information about the instance of SQL Server or the objects defined in the instance. For example, you can query the sys.databases catalog view to return information about the user-defined databases available in the instance.

    Create View in SQL Server

                                    CREATE VIEW DB_DNP.EmployeeHireDate  
                                    AS  
                                    SELECT p.FirstName, p.LastName, e.HireDate  
                                    FROM HumanResources.Employee AS e JOIN Person.Person AS  p  
                                    ON e.BusinessEntityID = p.BusinessEntityID ;   
                                    GO  
                                    -- Query the view  
                                    SELECT FirstName, LastName, HireDate  
                                    FROM DB_DNP.EmployeeHireDate  
                                    ORDER BY LastName;  
    
                                 

    Trending Post
    What is Anonymous methods in C#.
    Why Is It A Bad Idea To Throw Your Own Exceptions.
    How's The DLL Hell Problem Solved In .net?
    Interview Questions and Answers
    Describe the Async method of C#?
    Is it possible to serialise hashtables?
    Explain the differences between “out” and “ref” parameters in C#?
    How would you implement the Singleton design pattern in C#?
    What Are The Ways To Deploy An Assembly?
    What Are Advantages And Disadvantages Of Microsoft-provided Data Provider Classes In Ado.net?
    About us

    DotNet Palace is a community platform created and maintained by The articles are mainly focused on Microsoft stack technologies like C#, ASP.Net, MVC, .Net Core, SQL Server and Oracle, PostgreSQL, SQLite etc. To improve the site's content you can send your valuable suggestions at info.dotnetpalace@gmail.com

    Quick links
  • SOLID Principles
  • Questions
  • OOPS Principles
  • DotNet Palace Tutorials
  • Privacy Policy
  • Terms and Condition