为什么使用数据库视图? [英] Why is database view used?
本文介绍了为什么使用数据库视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
我看到使用意见的几个理由:
- 提供一个更简单的界面:只查询视图,而不是十几个表,进行连接和所有
- 提供一个不会更改(或更少):
- 即使您更改了表的结构,您也可以修改视图所以它仍然返回相同的事情
- 这意味着你的应用程序的代码不需要改变:它仍然可以工作,因为它正在使用视图,而不是直接访问表
- 只提供表格中某些字段的界面
- 不需要为了让用户看到一些数据,他们不会使用
- 或访问一些他们不应该使用的数据
- 有些数据库引擎(我认为MS SQL Server支持),某些类型的视图可以有索引
- 哪个是性能好的:如果您有一些复杂的查询,将其存储为视图,并在该视图上定义所需的索引
Is using "view" in db design right method or we should handle it code side? What are the advantages or disadvantages?
解决方案
I see a couple of reasons to use views :
- Provide a simpler interface : just query the view, and not a dozen tables, doing joins and all
- Provide an interface that doesnt change (or less often) :
- Even if you change the structure of the tables, you might be able to modify your view so it still returns the same thing
- Which means no change is needed in your application's code : it'll still work, as it's using the view, and not directly accessing the tables
- Only provide an interface to some fields of the tables
- No need for the users to see some data they won't use
- Or to access some data they should not use
- With some database engines (I think MS SQL Server supports that), some type of views can have indexes
- Which is a good thing for performances : if you have some complex query, store it as a view, and define the required indexes on that view
这篇关于为什么使用数据库视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文