可重用的 SQL Server 存储过程;筑巢;全局变量

发布于 2024-08-21 18:15:30 字数 403 浏览 2 评论 0原文

我想制作一些可重用的、有点动态的 TSQL 代码,可以在许多其他存储过程中调用,但我正在努力解决如何使用 SQL Server 实现这一点。

环境是许多分布式源系统数据库,它们将拥有自己的包装存储过程,该存储过程将从公共 ETLManagement DB 调用其中一些模块化存储过程。包装存储过程将调用其中一些公共/可重用存储过程(以对某些动态定义的控制表执行操作),然后调用 INSERT INTO 语句(由源系统拥有和定义),然后再调用一些公共/可重用存储过程。 -可用的存储过程。

一个主要障碍是我似乎无法在嵌套存储过程中声明变量,如何声明所有源系统存储过程都可以读取的全局变量?

我什至是使用普通存储过程的最佳方法,还是有更好的方法?

(请原谅我对 TSQL 编程的天真,到目前为止我一直在使用其他工具进行 ETL。)

I want to make some re-useable, somewhat-dynamic TSQL code that can be called within many other stored procs, but I'm struggling with how to implement this with SQL Server.

The environment is that many distributed source systems databases which will have their own wrapper stored procedure which will call a few of these modular stored procs from an common ETLManagement DB. The wrapper sproc will call a few of these commom/re-usable sprocs (to perform operations on some dynamically defined control tables), then an INSERT INTO statment(owned and defined by the source system), and then a couple more commom/re-usable sprocs.

One main roadblock is that I can't seem to declare variables in that nested sproc, how do I declare global variables that all the source system sprocs can read from?

Am I even going about this the best way with common sproc, or is there a better way?

(Forgive my naivete of TSQL programming, I've been doing ETL with other tools till now.)

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

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

发布评论

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

评论(2

缘字诀 2024-08-28 18:15:30

这是在存储过程之间共享数据的方法的非常全面的列表:

http://www.sommarskog.se /share_data.html

this is a very comprehensive list of ways to share data between stored procedures:

http://www.sommarskog.se/share_data.html

洛阳烟雨空心柳 2024-08-28 18:15:30

我会将全局变量的概念放入查找表中。这是你唯一拥有的等价物。

此外,您可以考虑寻找更多的用户定义函数,因为它们比 SPROC 可以用在更多的地方。本文是关于优点/缺点的一个很好的参考:

http://www. informit.com/articles/article.aspx?p=31724

坦率地说,如果您对真正的全局变量感兴趣,您可能需要考虑升级到 SQL Server Integration Services 包。考虑到您的要求,这可能更适合您。

http://msdn.microsoft.com/en-us/library/ms141026。 ASPX

I would put the concept of global variables into a lookup table. It's the only equiv you have.

In addition, you may consider looking more User Defined Functions as they can be used in so many more places than a SPROC. This article is a good reference to the pros/cons:

http://www.informit.com/articles/article.aspx?p=31724

Frankly, if you're interested in having true Global Variables you might want to consider moving up to SQL Server Integration Services packages. It may be more your cup of tea given your requirements.

http://msdn.microsoft.com/en-us/library/ms141026.aspx

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