可重用的 SQL Server 存储过程;筑巢;全局变量
我想制作一些可重用的、有点动态的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是在存储过程之间共享数据的方法的非常全面的列表:
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
我会将全局变量的概念放入查找表中。这是你唯一拥有的等价物。
此外,您可以考虑寻找更多的
用户定义函数
,因为它们比 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