为什么在C#中使用/需要PLSQL的存储过程 [英] Why use/need Store Procedures of PLSQL in C#

查看:149
本文介绍了为什么在C#中使用/需要PLSQL的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个报价单。 C#或任何语言都有很多功能(功能,方法)。为什么使用/需要存储程序/数据库的功能?

Hi,

I have one Quotation. So many function are available(function,methods) in C# or any language. Why use/need Store Procedures/function of database?

推荐答案

有很多原因:

1)它专注程序因此它们更容易在多个应用程序中使用。例如,如果公司使用从多个字段(可能在多个表中)构建的客户引用,则存储过程允许在一个位置完成,并从多个位置调用 - 因为它们都使用相同的DB ,它们都使用相同的SP,它使它更可靠。同样,它可以返回信息,好像它来自一个表,而实际上它是通过一组复杂的JOIN从几个中检索的。

2)它可以减少传输中的带宽和/或处理用途从数据库到应用程序的信息:如果处理全部在SQL内完成,那么它可以设计一个反映其使用方式的执行计划。如果你将相同的数据拉回到应用程序,那么你可能正在检索你不需要的信息并浪费时间。



这里有一个余额:有些东西是SP的好选择,其他东西最好在本地完成。这不是一个简单的使用它们(或者甚至将它们用于所有东西,因为有些人可能会告诉你!)。
There are a number of reasons:
1) It "focusses" procedures so they are easier to use in more than one application. For example, if a company uses a customer reference which is built from several fields, possibly in more than one table, then a Stored Procedure allows that to be done in one place, and called from several location - since they all use the same DB, they all use the same SP, and it makes it more reliable. Equally, it can return info as if it came from a single table whereas in reality it is retrieved from several via a complicated set of JOINs.
2) It can reduce bandwidth and / or processing use in transferring information from the DB to the application: if the processing is all done inside SQL then it can devise an execution plan that reflects the way it is being used. If you pull the same data back to the app, then you may well be retrieving information you don't need and wasting time that way.

There is a balance here: some things are good candidates for SP, others are best done locally. It's not a simple "use them for this" (or even "use them for everything" as some will probably tell you!).


我想补充一点,Linq无法更新视图。所以为此你也想用sp。是的,有一些技巧,但我更喜欢在这种情况下使用sp
I would like to add that Linq cannot update views. So for that you also would like to use sp. Yes, there are some tricks, but I prefer to use sp in this cases


作为Griffs评论的补充:

3)他们将你的业务逻辑与数据库,您可以在数据库中进行更改并更改SP以反映它们,并且业务逻辑永远不需要知道。

4)安全性,这是我所关心的最重要的原因。您可以拥有对存储过程的单独访问权限集,并为您的应用程序提供额外的用户,这些用户只能使用一组存储过程。因此,如果您的网页被黑客攻击,则限制了黑客在数据库中可以造成的损害。
As an addition to Griffs comments:
3) They decouple your business logic from the database, you can make changes in the database and change the SP to reflect them, and the business logic would never need to know.
4) Safety, this is as far as I'm concerned the single most important reason. You can have a separate set of access rights to the stored procedures and have an extra user for your applications that only can use a set of stored procedures. So if for example your webpage gets hacked you have limited what kind of damage the hacker can do in the database.


这篇关于为什么在C#中使用/需要PLSQL的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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