What are the downsides of using SqlServer Views?

后端 未结 10 1277
情歌与酒
情歌与酒 2020-12-29 05:04

What are the downsides of using SqlServer Views?

I create views frequently to show my data in a denormalized form.

I find it much easier and therefore fas

相关标签:
10条回答
  • 2020-12-29 06:01

    The efficiency of a view depends in large part on the underlying tables. The view really is a just an organized an consistent way to look at query results. If the query used to form the view is good, and uses proper indexes on the underlying tables, then the view shouldn't negatively impact performance.

    In SQL Server you can also create materialized or indexed views (since SQL Server 2000), which increase speed somewhat.

    0 讨论(0)
  • 2020-12-29 06:02

    When I started I always though views added performance overhead, however experience paints a different story (the view mechanism itself has negligible overhead).

    It all depends on what the underlying query is. Check out indexed views here or here , ultimately you should test the performance both ways to obtain a clear performance profile

    0 讨论(0)
  • 2020-12-29 06:04

    What are Various Limitations of the Views in SQL Server?

    Top 11 Limitations of Views

    • Views do not support COUNT (); however, it can support COUNT_BIG ()
    • ORDER BY clause does not work in View
    • Regular queries or Stored Procedures give us flexibility when we need another column; we can add a column to regular queries right away. If we want to do the same with Views, then we will have to modify them first
    • Index created on view not used often
    • Once the view is created and if the basic table has any column added or removed, it is not usually reflected in the view till it is refreshed
    • UNION Operation is not allowed in Indexed View
    • We cannot create an Index on a nested View situation means we cannot create index on a view which is built from another view.
    • SELF JOIN Not Allowed in Indexed View
    • Outer Join Not Allowed in Indexed Views
    • Cross Database Queries Not Allowed in Indexed View

    Source SQL MVP Pinal Dave

    http://blog.sqlauthority.com/2010/10/03/sql-server-the-limitations-of-the-views-eleven-and-more/

    0 讨论(0)
  • 2020-12-29 06:06

    When comes to Views there are advantages and disadvantages.

    Advantages:

    1. They are virtual tables and not stored in the database as a distinct object. All that is stored is the SELECT statement.
    2. It can be used as a security measure by restricting what the user can see.
    3. It can make commonly used complex queries easier to read by encapsulating them into a view. This is a double edged sword though - see disadvantages #3.

    Disadvantages:

    1. It does not have an optimized execution plan cached so it will not be as fast as a stored procedure.
    2. Since it is basically just an abstraction of a SELECT it is marginally slower than doing a pure SELECT.
    3. It can hide complexity and lead to gotchas. (Gotcha: ORDER BY not honored).

    My personal opinion is to not use Views but to instead use stored procedures as they provide the security and encapsulation of Views but also come with improved performance.

    0 讨论(0)
提交回复
热议问题