有没有办法在存储过程中搜索文本?例如,我想知道某个表是否被任何存储过程引用。在SQL Management Studio 2005中搜索
回答
用途:
SELECT OBJECT_NAME(m.object_id), m.*
FROM SYS.SQL_MODULES m
WHERE m.definition like N'%text_youre_looking_for%'
SYSCOMMENTS
和INFORMATION_SCHEMA.routines
有NVARCHAR(4000)列。所以如果在位置3998使用“text_youre_looking_for”,它将不会被找到。 SYSCOMMENTS
确实有多行,但是截断了INFORMATION_SCHEMA.routines
。
SELECT
OBJECT_SCHEMA_NAME(object_id) + '.' + OBJECT_NAME(object_id)
FROM
sys.sql_modules
WHERE
definition like '%whatever%'
syscomments中是传统和分裂定义为nvarchar的这样4000块冒着没有找到你想要的东西。这同样适用于INFORMATION_SCHEMA.ROUTINES
+1,'OBJECT_SCHEMA_NAME()'比联接到sys.objects然后sys.schemas更好! – 2010-10-21 19:24:55
您可以编写脚本并搜索脚本。
我的同事最近向我推荐了这个。它正如其他人注意到一些类似的搜索,但有一点更增加。
DECLARE
@chvStringToFind varchar(256), /* String to find */
@chrObjectType char(2),--=null, /* Only look for objects of this type */
@intNbCharToExtract int
--=50 /* Number of characters to extract before and after the string to find */
--exec DBA_FindStringInDB @chvStringToFind='sp_helpdia', @chrObjectType=null, @intNbCharToExtract=50
SET @chvStringToFind = 'EnterSearchTextHere' -- Change this to search
SET @chrObjectType = NULL
SET @intNbCharToExtract = 50
SELECT t.Name, t.TypeDescription, t.CreationDate, t.ModificationDate,
'...' + SUBSTRING
(
t.ObjectDefinition,
CHARINDEX(@chvStringToFind, t.ObjectDefinition) - @intNbCharToExtract,
LEN(@chvStringToFind) + (@intNbCharToExtract*2)
) + '...' AS Extract
FROM
(
SELECT o.name AS Name,
o.type_desc AS TypeDescription,
o.create_date AS CreationDate, o.modify_date AS ModificationDate,
OBJECT_DEFINITION(object_id) AS ObjectDefinition
FROM sys.objects o
WHERE
((o.type IN ('AF', 'FN', 'IF', 'P', 'TF', 'TT', 'U', 'V', 'X') AND @chrObjectType IS NULL) OR o.type = @chrObjectType)
AND OBJECT_DEFINITION(o.object_id) LIKE '%' + @chvStringToFind + '%'
) AS t
ORDER BY TypeDescription, Name
红门有一个名为Sql Search是我比较喜欢的免费工具。它保留了一个索引,以便在第一次搜索后,它非常快速(甚至第一个非常好)。它可以搜索procs中的文本以及表格和视图定义等。有一些过滤功能可以使它更容易使用。搜索结果以非常有用的方式显示,并突出显示对象的全文和搜索文本。
太棒了,我知道他们有一个,但不知道我不知道它是免费的。 – Prabhu 2010-10-21 20:00:51
+1优秀的公司工具 - 强烈推荐!不能再活下去了..... – 2010-10-21 20:35:10
- 1. 2005 SQL Server Management Studio
- 2. SQL Server Management Studio中2005 - 备份位置
- 3. SQL Server Management Studio 2005的SVN客户端
- 4. 在SQL Server Management Studio Express中连接到SQL Server 2005数据库
- 5. SQL在SQL Server Management Studio中
- 6. SQL 2005 XML搜索
- 7. 如何在SQL Server 2005 Management Studio中创建SQL Server 2005存储过程模板?
- 8. 如何在SQL Management Studio 2005中创建脚本?
- 9. 仅在SQL Server 2005 Management Studio选项卡中显示文件名
- 10. 在SQL Server Management Studio 2005中禁用“保存”提示
- 11. SQL列搜索问题(SQL Server 2005中)
- 12. SQL Server Management Studio
- 13. SQL 2005 - 搜索字符串
- 14. SQL Server Management Studio命令行?
- 15. 从SQL Server 2016到SQL Server Management Studio 2005的ETL
- 16. 我可以让SQL 2008 Management Studio验证SQL 2005的代码吗?
- 17. SQL Server Management Studio 2012仍在使用服务器2005实例
- 18. 外部工具开发SQL Server Management Studio中2005
- 19. SQL Server Management Studio中2005和源代码控制
- 20. SQL Server Management Studio中2005年的“记住密码”不工作
- 21. sql server management studio 2008
- 22. SQL Server Management Studio ZEROFILL
- 23. 我们可以在Sql Management Studio 2005中使用Sql server 2008新增功能吗?
- 24. 的SQL Server 2014 Management Studio中
- 25. 的SQL Server 2014 Management Studio中
- 26. 在SQL Server 2005中搜索特殊字符2005
- 27. 在sql server 2005中全文搜索和xml内容2005
- 28. 错误:未能加载包'Microsoft SQL Management Studio包'。在SQL Server Management Studio中
- 29. 用于SQL Server 2000的SQL Sever Management Studio
- 30. Visual Studio 2005快速文件搜索
感谢您为我设置直线。 – JNK 2010-10-21 19:16:51
@JNK:为了记录,我没有让你失望。 – 2010-10-21 19:17:24
@OMG - 没有biggie,我发布了一个错误的答案:) – JNK 2010-10-21 19:17:55