What are the downsides of using SqlServer Views?

后端 未结 10 1281
情歌与酒
情歌与酒 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: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.

提交回复
热议问题