为什么在数据库中创建视图? [英] Why do you create a View in a database?

查看:162
本文介绍了为什么在数据库中创建视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时和为什么有人决定他们需要在他们的数据库中创建一个视图?为什么不运行正常的存储过程或选择?

When and Why does some one decide that they need to create a View in their database? Why not just run a normal stored procedure or select?

推荐答案

视图提供了几个好处。

1。视图可以隐藏复杂性

如果您有一个查询需要连接多个表,或者有复杂的逻辑或计算, ,然后从视图中选择,就像您创建表格一样。

If you have a query that requires joining several tables, or has complex logic or calculations, you can code all that logic into a view, then select from the view just like you would a table.

2。视图可用作安全机制

视图可以从表中选择特定的列和/或行,并在视图基础表。这样只能显示用户需要查看的数据。

A view can select certain columns and/or rows from a table, and permissions set on the view instead of the underlying tables. This allows surfacing only the data that a user needs to see.

3。视图可以简化支持的旧代码

如果您需要重构一个会破坏大量代码的表,则可以使用一样的名字。该视图提供与原始表完全相同的模式,而实际模式已更改。这样可以保持引用表格的旧代码无法打开,让您可以随时更改旧代码。

If you need to refactor a table that would break a lot of code, you can replace the table with a view of the same name. The view provides the exact same schema as the original table, while the actual schema has changed. This keeps the legacy code that references the table from breaking, allowing you to change the legacy code at your leisure.

这些只是视图的一些例子有用。

These are just some of the many examples of how views can be useful.

这篇关于为什么在数据库中创建视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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