用于存储过程的 SQL 表和列解析器

发布于 2024-07-09 17:15:32 字数 352 浏览 7 评论 0原文

是否有一个应用程序可以解析一组给定的存储过程(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 技术交流群。

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

发布评论

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

评论(6

小女人ら 2024-07-16 17:15:32

不是一个具体的解决方案 - 而是一个思路。

将 sysdepends 视为一种潜在的解决方案 - 但众所周知,它在包含所有依赖对象信息方面不可靠。

但是 Lex/Yacc 派生的东西怎么样? 有一些商业解析器,例如

http://www.sqlparser.com/download.php

未寻找开源实现但我想我会寻找那条路线。 我是这样开始搜索的:

http://www.google.com /search?hl=en&q=sql+lex+yacc+parse

ANSI SQL 的 BNF 语法可以在这里找到:

http://savage.net.au/SQL/

通过选择 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.

http://www.sqlparser.com/download.php

Not looked for open-source implementation but I think I would look for that route. Here's how I started my search:

http://www.google.com/search?hl=en&q=sql+lex+yacc+parse

BNF syntax for ANSI SQL can be found here:

http://savage.net.au/SQL/

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)

旧时模样 2024-07-16 17:15:32

您可以使用 SHOWPLAN_ALL 设置并解析输出。

You can use SHOWPLAN_ALL setting and parse the output.

浅浅淡淡 2024-07-16 17:15:32

决定使用正则表达式创建一个小型应用程序来满足我当前的需求。

谢谢大家的回复。

Decided to create an small application using Regex to satisfy my current needs.

Thank you all for your responses.

各自安好 2024-07-16 17:15:32

sp_depends 非常适合我。
它显示了哪些表或 SP 可能会受到我的更改的影响

sp_depends Worked perfectly for me.
It showed what table or SP might be affected by my changes

年少掌心 2024-07-16 17:15:32

sp_depends 应该有帮助

sp_depends should help

り繁华旳梦境 2024-07-16 17:15:32

您可以以编程方式调用存储过程(在开发环境中)并获取结果列。 也许您有一个命名约定,以避免调用插入和更新过程。 您还必须找到设置正确参数的方法。

注意:我认为 100% 可靠的解决方案在技术上是不可能的,因为存储过程的工作方式不同。

看这个例子:

[...]
@MyDate datetime

AS

    IF (day(@MyDate) = 1)
    BEGIN
        SELECT * FROM MyFirstTable
        RETURN
    END

    IF (@MyDate > getdate())
        SELECT MyID, MyText FROM MySecondTable WHERE ADate > @MyDate
    ELSE
        EXEC Other_StoredProcedure @MyType, @MyDate

所以有两个问题:结果列可能不同,并且您必须递归地遵循其他存储过程。

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:

[...]
@MyDate datetime

AS

    IF (day(@MyDate) = 1)
    BEGIN
        SELECT * FROM MyFirstTable
        RETURN
    END

    IF (@MyDate > getdate())
        SELECT MyID, MyText FROM MySecondTable WHERE ADate > @MyDate
    ELSE
        EXEC Other_StoredProcedure @MyType, @MyDate

So there are two problems: the resulting columns could differ and you'll have to follow recursively other stored procedures.

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