存储过程与参数绑定

发布于 2024-09-01 22:59:32 字数 172 浏览 1 评论 0原文

我在 Visual C++ 中使用 SQL Server 和 ODBC 来写入数据库。目前我在 SQL 查询中使用参数绑定(因为我只用 5 - 6 个查询填充数据库,检索数据也是如此)。我对存储过程了解不多,我想知道存储过程是否比参数绑定有多少性能提升,因为在参数绑定中,我们只准备一次查询,然后在程序中针对不同的变量值集执行它。

I am using SQL server and ODBC in visual c++ for writing to the database. Currently i am using parameter binding in SQL queries ( as i fill the database with only 5 - 6 queries and same is true for retrieving data). I dont know much about stored procedures and I am wondering how much if any performance increase stored procedures have over parameter binding as in parameter binding we prepare the query only once and just execute it later in the program for diferent set of values of variables.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寻找一个思念的角度 2024-09-08 22:59:33

由于以下几个原因,存储过程应该具有更高的性能:

  • 更少的网络流量 - 查询位于数据库上,您只需使用参数向数据库发送一个小命令,而不是每次都发送整个查询 查询
  • 在服务器上预编译,并且可以也可以由数据库缓存

另一个优点是您可以更改数据库上的查询,而无需重新编译代码。这是一个额外的抽象层,我发现它非常有用。

Stored procedures should be more performant for a few reasons:

  • Less network traffic - the query is on the DB and you just send a small command to the DB with params vs sending the entire query every time
  • The query is pre compiled on the server and can be cached as well by the DB

Another advantage is that you can alter the query on the DB without having to recompile the code. This is an additional layer of abstraction that I find very useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文