用于存储过程的 SQL 表和列解析器
是否有一个应用程序可以解析一组给定的存储过程(SQL Server 2000)并获取其中使用的所有表和关联列。 存储过程可以包含来自不同数据库的表。
输出应该是这样的 表A A列 C栏 表B
列 D E栏 F栏 columnG
我使用Database Edition GDR编写了一个小应用程序任何有兴趣的人可以参考http://tsqlparsergdr.codeplex.com
Is there an application , which can parse a given set of stored procedures (SQL Server 2000) and gets all tables and associated columns that are being used in it.
The stored procedure can have tables from different databases.
Output should be like
TableA
columnA
columnC
columnD
TableB
columnE
columnF
columnG
I have written an small application using Database Edition GDR Any one interested can refer to http://tsqlparsergdr.codeplex.com
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不是一个具体的解决方案 - 而是一个思路。
将 sysdepends 视为一种潜在的解决方案 - 但众所周知,它在包含所有依赖对象信息方面不可靠。
但是 Lex/Yacc 派生的东西怎么样? 有一些商业解析器,例如
未寻找开源实现但我想我会寻找那条路线。 我是这样开始搜索的:
ANSI SQL 的 BNF 语法可以在这里找到:
通过选择 lex 实现,这似乎这是一个相对直接的工程问题。 (尽管如果您想支持 MS SQL 扩展,则需要一些繁重的工作)
Not a concrete solution - but a line of thought.
Considered sysdepends as a potential solution - but it is notoriously unreliable at containing all the dependent object information.
but how about something Lex/Yacc derived? There are a few commercial parsers e.g.
Not looked for open-source implementation but I think I would look for that route. Here's how I started my search:
BNF syntax for ANSI SQL can be found here:
With a lex implementation of choice, this seems a relatively straight forward engineering problem from here. (albeit with some heavylifting if you want to support MS SQL extensions)
您可以使用 SHOWPLAN_ALL 设置并解析输出。
You can use SHOWPLAN_ALL setting and parse the output.
决定使用正则表达式创建一个小型应用程序来满足我当前的需求。
谢谢大家的回复。
Decided to create an small application using Regex to satisfy my current needs.
Thank you all for your responses.
sp_depends 非常适合我。
它显示了哪些表或 SP 可能会受到我的更改的影响
sp_depends Worked perfectly for me.
It showed what table or SP might be affected by my changes
sp_depends 应该有帮助
sp_depends should help
您可以以编程方式调用存储过程(在开发环境中)并获取结果列。 也许您有一个命名约定,以避免调用插入和更新过程。 您还必须找到设置正确参数的方法。
注意:我认为 100% 可靠的解决方案在技术上是不可能的,因为存储过程的工作方式不同。
看这个例子:
所以有两个问题:结果列可能不同,并且您必须递归地遵循其他存储过程。
You could call the stored procedures programmatically (in a development environment) and get the resulting columns. Maybe you have a naming convention in order to avoid calling insert and update procedure. You'll have to find way to set the right parameters too.
Note: I think a 100% reliable solution is technically impossible, because of the way stored procedure (can) work.
Look at this example:
So there are two problems: the resulting columns could differ and you'll have to follow recursively other stored procedures.