简体   繁体   English

在 SQL Server 中查找对对象的 DML 引用的最佳方法是什么?

[英]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.

相关问题 在SQL表中存储分类引用的最佳方法是什么? - What is the best way to store categorical references in SQL tables? 在Visual Studio 2010中管理“非SQL Server” SQL对象的最佳方法是什么? - What is the best way to manage “non-SQL Server” SQL objects within Visual Studio 2010? 在 SQL 服务器中对结果进行分页的最佳方法是什么 - What is the best way to paginate results in SQL Server 在SQL Server 2008中查找SQL锁的最佳方法 - Best way to find SQL Locks in SQL Server 2008 SQL Server - 可重用的DML查询 - SQL Server - Reusable DML query SQL Server 2008将硬编码对架构名称的引用转换为变量的最佳方法 - Sql server 2008 best way to turn hard coded references to schema name into a variable 在 sql server 数据库中找到可用空间的最佳方法? - Best way to find free space in sql server databases? 在SQL Server 2008中匿名化ID值的最佳方法是什么 - What is the best way to anonymize ID values in sql server 2008 将外键与SQL Server中的详细信息表关联的最佳方法是什么? - What is the best way to associate the foreign key to the details table in SQL Server? 在 SQL Server 中探索表之间链接的最佳方式是什么? - What's the best way of exploring links between tables in SQL Server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM