视图与存储过程有什么区别? [英] Views vs Stored Procedures, whats the difference?

查看:78
本文介绍了视图与存储过程有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题的目的是从

应用程序访问这些技术。我开发了应用程序和数据库。使用

Microsoft C#.NET和Microsoft SQL Server 2000生产和2005测试

环境。


目的是什么一个视图,如果我可以从视图中复制vode

并将其放入存储过程?


我应该从存储过程访问视图吗?


我应该使用视图来获取信息吗?和存储过程

插入,更新和删除?


这两者之间有什么性能差异?


感谢您提供任何和所有信息。


SBProgrammer

The purpose for my questions is accessing these technologies from
applications. I develop both applications and databases. Working with
Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test
Environments.

What is the purpose of a view if I can just copy the vode from a view
and put it into a stored procedure?

Should I be accessing views from stored procedures?

Should I use views to get information? and Stored Procedures for
Inserts, Updates and Deletes?

What are the performance differences between the two?

Thank you for any and all information.

SBProgrammer

推荐答案

mooreit写道:
mooreit wrote:
我的问题的目的是从
应用程序访问这些技术。我开发了应用程序和数据库。使用
Microsoft C#.NET和Microsoft SQL Server 2000生产和2005测试
环境。

如果我可以从视图中复制vode,那么视图的目的是什么
并将其放入存储过程?

我是否应该从存储过程访问视图?

我应该使用视图来获取信息吗?
插入,更新和删除的存储过程?

两者之间的性能差异是什么?

感谢您提供任何和所有信息。

SBProgrammer
The purpose for my questions is accessing these technologies from
applications. I develop both applications and databases. Working with
Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test
Environments.

What is the purpose of a view if I can just copy the vode from a view
and put it into a stored procedure?

Should I be accessing views from stored procedures?

Should I use views to get information? and Stored Procedures for
Inserts, Updates and Deletes?

What are the performance differences between the two?

Thank you for any and all information.

SBProgrammer



视图和存储过程之间的区别正是

名称所说的。通过视图,您可以定义一个select-query,用于从一个或多个表(存储的

select-statement)中检索

特定信息。存储过程可以做更多:它可以运行多个sql命令
,具有control-of-flow语句并接受

参数。另外,giyf:
http:// www.google.be/search?q=view+vs+stored+procedure

Stevel


The difference between a view and a stored procedure is exactly what the
names say. With a view, you can define a select-query that retrieves
specific information from one or more tables (a stored
select-statement). A stored procedure can do much more: it can run
multiple sql-commands, has control-of-flow statements and accepts
parameters. Also, giyf:
http://www.google.be/search?q=view+vs+stored+procedure

Stevel


您好,


将视图视为虚拟桌子,它不是物理的,而是物化的

,如果你需要它。


您可以在视图上获得权限,但是如果

他们可以访问数据库,那么用户可以编写自己的查询,这通常是不推荐的 -

旧的Joe Bloggs在MS Access中的视图上运行选择而没有WHERE

子句!


如果您正在编写更好,更模块化的应用程序并且安全

方法是使用存储过程。


将您的逻辑封装到存储过程中并从您的

应用程序中调用它,make suire你不要在应用程序中使用动态sql,而是使用

命令对象,基本上不要在你的应用程序中这样做,因为你打开了自己的b

$ b dim strSQL as string


strSQL =" exec myproc @ parm1 =''" &安培; tbName.text& "''"


dbconn.Execute(strSQL)


从绩效的角度来看,无论如何都要保留计划,所以由于执行计划在缓存中,因此执行计划不再有效,因为视图中的执行计划将在缓存中,因此旧的

addage表示更好的处理

也可能参数化。


总之,如果你想构建一个好的,安全的模块化系统,那么使用

存储过程 - 最后一件事,它显着而且我正在谈论

显着更容易调整存储过程,我经常继续使用

网站,有时会找到带有app的地方没有使用存储的

程序 - 它就像把我的双手绑在背后,我只能玩

索引或索引视图;而存储过程我可以更有效地重写SQL



希望有所帮助。


Tony。


-

Tony Rogerson

SQL Server MVP
http://sqlserverfaq.com - 免费视频教程

" mooreit" <毫米*** @ yahoo.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
Hi,

Think of a view as a ''virtual table'', its not physical but is materialised
when you need it.

You can permission on the view, but users can write their own queries if
they are given access to the database which is often not recommended - its
the old Joe Bloggs running a select on the view in MS Access without a WHERE
clause!

If you are writing applications a better and more modular and secure
approach is to use stored procedures.

Encapsulate your logic into the stored procedure and call that from your
application, make suire you don''t use dynamic sql in the app, instead use
the command object, basically don''t do this in your app because you open
yourself up to sql injection...

dim strSQL as string

strSQL = "exec myproc @parm1=''" & tbName.text & "''"

dbconn.Execute( strSQL )

From a performance point of view, plans are kept now anyway so the old
addage that procs are better because of the execution plan being in cache is
no longer valid, because the execution plan from the view will be in cache
as well, probably parameterised as well.

In summary, if you want to build a good, secure modular system then use
stored procedures - one last thing, its significantly and i''m talking
significantly easier to performance tune a stored procedure, i often go on
site and sometimes find places with an app that has not used stored
procedures - its like tying my hands behind my back, i can only play with
indexes or index views; whereas a stored procedure i can rewrite the SQL
more efficiently.

Hope that helps.

Tony.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"mooreit" <mm***@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
我的问题的目的是从
应用程序访问这些技术。我开发了应用程序和数据库。使用
Microsoft C#.NET和Microsoft SQL Server 2000生产和2005测试
环境。

如果我可以从视图中复制vode,那么视图的目的是什么
并将其放入存储过程?

我是否应该从存储过程访问视图?

我应该使用视图来获取信息吗?
插入,更新和删除的存储过程?

两者之间的性能差异是什么?

感谢您提供任何和所有信息。

SBProgrammer
The purpose for my questions is accessing these technologies from
applications. I develop both applications and databases. Working with
Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test
Environments.

What is the purpose of a view if I can just copy the vode from a view
and put it into a stored procedure?

Should I be accessing views from stored procedures?

Should I use views to get information? and Stored Procedures for
Inserts, Updates and Deletes?

What are the performance differences between the two?

Thank you for any and all information.

SBProgrammer



2006年1月27日06:19:03 -0800,mooreit写道:
On 27 Jan 2006 06:19:03 -0800, mooreit wrote:
我的问题的目的是从
应用程序访问这些技术。我开发了应用程序和数据库。使用
Microsoft C#.NET和Microsoft SQL Server 2000生产和2005测试
环境。

如果我可以从视图中复制vode,那么视图的目的是什么
并将其放入存储过程?

我是否应该从存储过程访问视图?

我应该使用视图来获取信息吗?
插入,更新和删除的存储过程?

两者之间的性能差异是什么?

感谢您提供任何和所有信息。

SBProgrammer
The purpose for my questions is accessing these technologies from
applications. I develop both applications and databases. Working with
Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test
Environments.

What is the purpose of a view if I can just copy the vode from a view
and put it into a stored procedure?

Should I be accessing views from stored procedures?

Should I use views to get information? and Stored Procedures for
Inserts, Updates and Deletes?

What are the performance differences between the two?

Thank you for any and all information.

SBProgrammer




SBProgrammer,


天前。这是Google上文章的链接(警告 - 长URL,

可能会换行)

http://groups.google.com/group/micro...cc4092b8603807


-

Hugo Kornelis,SQL Server MVP



Hi SBProgrammer,

I wrote about the differences between stored procedures and views ten
days ago. Here''s a link to the article on Google (warning - long URL,
might wrap)

http://groups.google.com/group/micro...cc4092b8603807

--
Hugo Kornelis, SQL Server MVP


这篇关于视图与存储过程有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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