可以有很多数据库视图吗? [英] Is it okay to have a lot of database views?

查看:99
本文介绍了可以有很多数据库视图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很少(每月/每季度)使用Microsoft SQL Server 2005数据库视图生成数百个Crystal Reports报表。这些视图是否在我一直没有从中读取CPU周期和RAM时一直在浪费它们?因为我很少从视图中读取内容,我应该使用存储过程,临时表还是短暂的普通表?

I infrequently (monthly/quarterly) generate hundreds of Crystal Reports reports using Microsoft SQL Server 2005 database views. Are those views wasting CPU cycles and RAM during all the time that I am not reading from them? Should I instead use stored procedures, temporary tables, or short-lived normal tables since I rarely read from my views?

我不是DBA,所以我不知道数据库服务器内部幕后发生的事情。

I'm not a DBA so I don't know what's going on behind the scenes inside the database server.

是否有太多的数据库视图?什么是最佳做法?

Is it possible to have too many database views? What's considered best practice?

推荐答案

在大多数情况下都没有关系。是的,SQL Server在解析SELECT * FROM table时将有更多选择(它必须在系统目录中查找 table),但对此进行了高度优化,并提供了足够的RAM(当今大多数服务器都这样做) ,则您不会注意到0到1,000个视图之间的差异。

For the most part, it doesn't matter. Yes, SQL Server will have more choices when it parses SELECT * FROM table (it'll have to look in the system catalogs for 'table') but it's highly optimized for that, and provided you have sufficient RAM (most servers nowadays do), you won't notice a difference between 0 and 1,000 views.

但是,从人们的角度出发,试图管理并弄清百种视图是什么这样做可能是不可能的,所以您可能在那里有很多重复的代码。如果某些业务规则更改嵌入在这些冗余视图中,会发生什么情况?

However, from a people-perspective, trying to manage and figure out what "hundreds" of views are doing is probably impossible, so you likely have a lot of duplicated code in there. What happens if some business rules change that are embedded in these redundant views?

视图的主要观点是将业务逻辑封装到伪表中(因此您可能会有一个人表,然后是一个名为 active_persons的视图,该视图具有一定的魔力)。为每个报告创建视图都是很愚蠢的,除非每个报告是如此孤立和独特,以至于无法重复使用。

The main point of views is to encapsulate business logic into a pseudo table (so you may have a person table, but then a view called "active_persons" which does some magic). Creating a view for each report is kind of silly unless each report is so isolated and unique that there is no ability to re-use.

这篇关于可以有很多数据库视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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