[英]What is the best way to find DML references to objects in SQL Server?
Something I have always struggled with is finding DML references to tables in SQL server at the company I work.我一直在努力解决的问题是在我工作的公司中找到对 SQL 服务器中表的 DML 引用。 We have our code held in TFS source control and deployed to a shared development environment so I can search using either file searching or t-sql code.
我们将代码保存在 TFS 源代码管理中并部署到共享开发环境中,因此我可以使用文件搜索或 t-sql 代码进行搜索。 The challenge I have is that I can easily find all references to a table name but I can't find a good way to filter further to a particular statement like UPDATE/INSERT/MERGE.
我面临的挑战是我可以轻松找到对表名的所有引用,但我找不到进一步过滤到特定语句(如 UPDATE/INSERT/MERGE)的好方法。
A large challenge in this is that the company I work at has a lot of dynamic SQL so I think the best method will be some form of text searching.一个很大的挑战是我工作的公司有很多动态 SQL,所以我认为最好的方法是某种形式的文本搜索。 The other challenge is that coding is written as each developer sees fit so an UPDATE statement will not be written in any 'standard' way throughout the code base - ie the table name could be on the same line as the DML statement or on a separate line.
另一个挑战是编码是按照每个开发人员认为合适的方式编写的,因此不会在整个代码库中以任何“标准”方式编写 UPDATE 语句 - 即表名可以与 DML 语句在同一行或单独的线。
I have been able to use some basic regular expression searching in Visual Studio to find instances where the keyword is on the same line as the table name but I don't know how to search for it being 'close'.我已经能够在 Visual Studio 中使用一些基本的正则表达式搜索来查找关键字与表名在同一行的实例,但我不知道如何搜索它是“关闭”。
Has anybody else faced this issue and found a good way to search for this information?有没有其他人遇到过这个问题并找到了搜索这些信息的好方法? What I would love is a tool where you put in a t-sql reserved keyword and an object name and the tool shows you all references.
我想要的是一个工具,您可以在其中输入 t-sql 保留关键字和对象名称,并且该工具会向您显示所有引用。
One way to at least see all the code across Views, SP, Functions, etc is to run this:至少查看视图、SP、函数等所有代码的一种方法是运行以下命令:
--will show you all source code from procs, views, functions etc
select *
from syscomments
--or better to join it on sysobjects and display only view source code for example
select o.id,o.name,c.text
from syscomments c
inner join sysobjects o on o.id = c.id
where o.[Type] = 'V'
I found once I have all of this, I can then do easy searching in Excel or via Notepad++.我发现一旦我拥有了所有这些,我就可以在 Excel 或 Notepad++ 中轻松搜索。
I hope that helped.我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.