我有一个会改变的链接服务器.有些程序会像这样调用链接服务器:[10.10.100.50].dbo.SPROCEDURE_EXAMPLE
.我们也有触发器做这种工作.我们需要找到[10.10.100.50]
用于改变它的所有地方.
在SQL Server Management Studio Express中,我没有在Visual Studio中找到类似"在整个数据库中查找"的功能.一个特殊的系统选择可以帮助我找到我需要的东西吗?
这是我在我的系统上用来查找文本的程序的一部分....
DECLARE @Search varchar(255) SET @Search='[10.10.100.50]' SELECT DISTINCT o.name AS Object_Name,o.type_desc FROM sys.sql_modules m INNER JOIN sys.objects o ON m.object_id=o.object_id WHERE m.definition Like '%'+@Search+'%' ORDER BY 2,1
[迟到的答案,但希望有用]
使用系统表并不总能提供100%正确的结果,因为某些存储过程和/或视图可能会被加密,在这种情况下,您需要使用DAC连接来获取所需的数据.
我建议使用第三方工具,如ApexSQL Search,可以轻松处理加密对象.
如果对象被加密,Syscomments系统表将为text列提供null值.
你可以找到它
SELECT DISTINCT OBJECT_NAME(id) FROM syscomments WHERE [text] LIKE '%User%'
它将列出包含存储过程内的"User"等文本的不同存储过程名称.更多信息
-- Declare the text we want to search for DECLARE @Text nvarchar(4000); SET @Text = 'employee'; -- Get the schema name, table name, and table type for: -- Table names SELECT TABLE_SCHEMA AS 'Object Schema' ,TABLE_NAME AS 'Object Name' ,TABLE_TYPE AS 'Object Type' ,'Table Name' AS 'TEXT Location' FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%'+@Text+'%' UNION --Column names SELECT TABLE_SCHEMA AS 'Object Schema' ,COLUMN_NAME AS 'Object Name' ,'COLUMN' AS 'Object Type' ,'Column Name' AS 'TEXT Location' FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%'+@Text+'%' UNION -- Function or procedure bodies SELECT SPECIFIC_SCHEMA AS 'Object Schema' ,ROUTINE_NAME AS 'Object Name' ,ROUTINE_TYPE AS 'Object Type' ,ROUTINE_DEFINITION AS 'TEXT Location' FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_DEFINITION LIKE '%'+@Text+'%' AND (ROUTINE_TYPE = 'function' OR ROUTINE_TYPE = 'procedure');
这对你有用:
use [ANALYTICS] ---> put your DB name here GO SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_desc, sm.definition FROM sys.sql_modules AS sm JOIN sys.objects AS o ON sm.object_id = o.object_id where sm.definition like '%SEARCH_WORD_HERE%' collate SQL_Latin1_General_CP1_CI_AS ORDER BY o.type; GO