这是使用嵌入式 SQL 而不是存储过程的有效好处吗? [英] Is this a valid benefit of using embedded SQL over stored procedures?

查看:25
本文介绍了这是使用嵌入式 SQL 而不是存储过程的有效好处吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个我没听说过的关于 SP 的论点.火焰人,小心点,

Here's an argument for SPs that I haven't heard. Flamers, be gentle with the down tick,

由于每次访问数据库服务器都会产生相关的开销,我建议将 SQL 放在 SP 中而不是嵌入代码中的一个可能原因是,您可以在不影响性能的情况下进行更改.

Since there is overhead associated with each trip to the database server, I would suggest that a POSSIBLE reason for placing your SQL in SPs over embedded code is that you are more insulated to change without taking a performance hit.

例如.假设您需要执行返回标量整数的查询 A.

For example. Let's say you need to perform Query A that returns a scalar integer.

然后,后来,需求发生变化,您决定标量的结果是 > x,然后,只有这样,您才需要执行另一个查询.如果您在 SP 中执行第一个查询,您可以轻松检查第一个查询的结果并在同一个 SP 中有条件地执行第二个 SQL.

Then, later, the requirements change and you decide that it the results of the scalar is > x that then, and only then, you need to perform another query. If you performed the first query in a SP, you could easily check the result of the first query and conditionally execute the 2nd SQL in the same SP.

在不执行单独查询或不必要查询的情况下,您如何在嵌入式 SQL 中有效地执行此操作?

How would you do this efficiently in embedded SQL w/o perform a separate query or an unnecessary query?

这是一个例子:

--This SP may return 1 or two queries. 

SELECT @CustCount = COUNT(*) FROM CUSTOMER 

IF @CustCount > 10 
   SELECT * FROM PRODUCT 

这可以/在嵌入式 SQL 中执行此操作的最佳方法是什么?

Can this/what is the best way to do this in embedded SQL?

推荐答案

一篇很有说服力的文章

SQL 和存储过程将在您的数据期间一直存在.

SQL and stored procedures will be there for the duration of your data.

客户端语言来来去去,您每次都必须重新实现嵌入式 SQL.

Client languages come and go, and you'll have to re-implement your embedded SQL every time.

这篇关于这是使用嵌入式 SQL 而不是存储过程的有效好处吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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