SQL SQL中视图的目的是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2381195/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the purpose of views in SQL?
提问by Johan Alkst?l
Possible Duplicate:
What are views good for?
可能的重复:
视图有什么用?
I'm trying to figure out what the purpose of views in an SQL database is?
我想弄清楚 SQL 数据库中视图的目的是什么?
Why, when and how would I create and use views?
为什么、何时以及如何创建和使用视图?
回答by Yada
Many different perspectives of the same table.
Can hide certain columns in a table. For example you may want to allow employees to see other employees' phone number column, but only certain employees to be able to access an employee's salary column!
Can provide huge time savings in writing queries by already having a group of frequently accessed tables joined together in a view.
Views allow you to use functions and manipulate data in ways that meet your requirements. For example, you store a person's birth date, but you like to calculate this to determine their age.
同一张桌子有很多不同的视角。
可以隐藏表格中的某些列。例如,您可能希望允许员工查看其他员工的电话号码列,但只有某些员工才能访问员工的工资列!
通过在视图中将一组经常访问的表连接在一起,可以在编写查询时节省大量时间。
视图允许您以符合您要求的方式使用函数和操作数据。例如,您存储了一个人的出生日期,但您喜欢计算此日期以确定他们的年龄。
回答by ChaosPandion
It can be used to simplify complex joins that you use repeatedly across your DB.
它可用于简化您在数据库中重复使用的复杂连接。
CREATE view [dbo].[V_MyComplexJoin]
As
Select TableA.A, TableB.B
From TableA
Inner Join TableB On TableA.BID = TableB.ID