什么时候以及为什么有些人决定他们需要在他们的数据库中创建一个视图?为什么不运行一个普通的存储过程或选择?
当前回答
这并没有确切地回答你的问题,但我认为值得一提的是物化视图。我的经验主要是使用Oracle,但是SQL-Server应该是相当相似的。
We used something similar in our architecture to address XML performance problems. Our systems are designed with a lot of data stored as XML on a row and applications might need to query particular values within it. Handling lots of XMLTypes and running XPaths across large number of rows has a large impact on performance so we use a form of materialized views to extract the desired XML nodes out into a relational table anytime the base table changes. This effectively provides a physical snapshot of the query at a point in time as opposed to standard views which would run their query on demand.
其他回答
当我想要查看一个表的快照和/或视图(以只读方式)时
这样做的原因不止一个。有时可以使通用连接查询变得简单,因为可以只查询表名而不是执行所有的连接。
另一个原因是将数据限制为不同的用户。例如:
表1:列- USER_ID;用户名;SSN
管理用户可以在实际表上有私权,但你不想访问的用户,比如SSN,你创建一个视图
CREATE VIEW USERNAMES AS SELECT user_id, username FROM Table1;
然后给他们访问视图而不是表的私权。
视图是查询的封装。转换为视图的查询往往比较复杂,因此将它们保存为视图以供重用是有好处的。
一般来说,我使用视图是为了让生活更简单,从存储在多个表中的实体中获得扩展细节(消除代码中的大量连接以增强可读性),有时还可以在多个数据库中共享数据,甚至可以使插入更容易阅读。
这并没有确切地回答你的问题,但我认为值得一提的是物化视图。我的经验主要是使用Oracle,但是SQL-Server应该是相当相似的。
We used something similar in our architecture to address XML performance problems. Our systems are designed with a lot of data stored as XML on a row and applications might need to query particular values within it. Handling lots of XMLTypes and running XPaths across large number of rows has a large impact on performance so we use a form of materialized views to extract the desired XML nodes out into a relational table anytime the base table changes. This effectively provides a physical snapshot of the query at a point in time as opposed to standard views which would run their query on demand.
推荐文章
- 如何在Ruby On Rails中使用NuoDB手动执行SQL命令
- 查询JSON类型内的数组元素
- 确定记录是否存在的最快方法
- 获得PostgreSQL数据库中当前连接数的正确查询
- 在SQL选择语句Order By 1的目的是什么?
- MySQL数据库表中的最大记录数
- 从现有模式生成表关系图(SQL Server)
- 我如何循环通过一组记录在SQL Server?
- HyperLogLog算法是如何工作的?
- 数据库和模式的区别
- 如何在SQL Server中一次更改多个列
- 如何从命令行通过mysql运行一个查询?
- 外键约束可能导致循环或多条级联路径?
- 使用LIMIT/OFFSET运行查询,还可以获得总行数
- 当恢复sql时,psql无效命令\N