使用 SqlServer 视图的缺点是什么? [英] What are the downsides of using SqlServer Views?

查看:82
本文介绍了使用 SqlServer 视图的缺点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 SqlServer 视图的缺点是什么?

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 faster, less error prone, and more self documenting, to query one of these joins rather than to generate complex queries with complicated joins between many tables. Especially when I am analyzing the same data (many same fields, same table joins) from different angles.

但是创建和使用这些视图是否需要成本?

But is there a cost to creating and using these views?

我是否在减慢(或加快)查询处理速度?

Am I slowing down (or speeding up?) query processing?

推荐答案

Views 有优点也有缺点.

When comes to Views there are advantages and disadvantages.

优点:

  1. 它们是虚拟表,不作为不同的对象存储在数据库中.存储的只是 SELECT 语句.
  2. 通过限制用户可以看到的内容,它可以用作一种安全措施.
  3. 通过将常用的复杂查询封装到视图中,可以使它们更易于阅读.不过,这是一把双刃剑 - 请参阅缺点 #3.

缺点:

  1. 它没有缓存优化的执行计划,因此它不会像存储过程那样快.
  2. 因为它基本上只是一个 SELECT 的抽象,所以它比做一个纯 SELECT 稍微慢一些.
  3. 它可以隐藏复杂性并导致问题.(陷阱:ORDER BY 不兑现).

我个人的观点是不要使用视图,而是使用存储过程,因为它们提供了视图的安全性和封装性,同时也提高了性能.

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.

这篇关于使用 SqlServer 视图的缺点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆