在SQL Server中使用视图的位置 [英] Where Views are used in sql server

查看:127
本文介绍了在SQL Server中使用视图的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想关于在SQL Server中视图的实际使用.在哪种情况下,我也可以选择项目的视图?在哪种情况下,也可以使用视图?您可以用一个实时示例来解释这一点吗?

据说大多数视图用于限制某些用户查看真实表的内容.

但是我有一个疑问……当我们创建一个Web应用程序时,该应用程序的数据库用户可能是单个用户.然后如何在Web应用程序中使用此视图.


Web应用程序的数据库用户应该是管理员,然后我们将限制哪个用户阻止查看原始表.



谢谢,
Velkumar.

Hi,

I want to about the real use of views in sql server. In which situation i can prefer views for my project also In which situation views are used?. Can you explain this with one real time example.

Most of them are said views are used to restrict some users to see the contents of real tables.

But I have a doubt... When we creating a web application the database user of this application may be a single user. Then how this views are used in web applications.


The database user of web application should be a administrator then we will restrict which user to prevent to see the original tables.



Thanks,
Velkumar.

推荐答案

嗨...

请考虑您的数据库具有许多表,并且可能存在这样的情况,即您需要通过使用JOINS一次从多个表中获取数据.
Hi...

Consider that your database has many number of tables and there may be a situation that you need data from many tables at a time by using JOINS.
select *
from a inner join b on a.col1 = b.col1
    inner join c on b.col2 = c.col2
    inner join d on c.col3 = d.col3
    inner join e on d.col4 = e.col4
    inner join f on e.col5 = f.col5
    inner join g on f.col6 = g.col6
where a.col1 = 10


现在可能发生了,您需要在许多地方(例如10个SP中)使用此数据.然后,您可以创建一个包含多个表中数据的视图,而不是在每个SP中使用JOINS.


Now it may happen that you need this data at many places, say in 10 SPs. Then instead of using JOINS in each SP, you can create a view which contains data from multiple tables.

create view View1 AS
select *
from a inner join b on a.col1 = b.col1
    inner join c on b.col2 = c.col2
    inner join d on c.col3 = d.col3
    inner join e on d.col4 = e.col4
    inner join f on e.col5 = f.col5
    inner join g on f.col6 = g.col6


然后根据情况从View中获取数据:


Then depending on situation, you can get data from View:

select * from View1 where col1 = 10


现在考虑在所有SP中,您需要在联接中再添加一张表.在这种情况下,无需修改所有SP,只需修改一个视图即可.

这只是一个简单的视图示例,但是使用它还有很多优点.


Now consider that in all the SPs u need to add one more table in the join. In that case instead of modifying all the SPs, you just need to modify one view.

This was just a simple example of view, but there are many more advantages of using it.


请参阅:
http://en.wikipedia.org/wiki/View_%28database%29 [ ^ ].

知道这个想法还不够吗?

无论如何,我认为答案的最主要部分是在对问题的评论中.想一想.

—SA
Please see:
http://en.wikipedia.org/wiki/View_%28database%29[^].

Isn''t it quite enough to get the idea?

Anyway, I think the most principle part of my answer is in my comment to the question. Just think about it.

—SA


我们在不知道列号的地方使用视图
那么我们使用视图将数据保留在其中..它不能用作永久表
We Use Views in the places where the no of columns are not known to us
then we use a view to keep data in it .. it can not be used as a permanent table


这篇关于在SQL Server中使用视图的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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