sql server 查找包含字符串的对象
Posted 阳光白云--davidhou
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql server 查找包含字符串的对象相关的知识,希望对你有一定的参考价值。
sql server 查找包含字符串的对象
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 ‘%要匹配的内容%‘ --collate SQL_Latin1_General_CP1_CI_AS ORDER BY o.type; GO select OBJECT_NAME(id) AS object_name,text from syscomments where text like ‘%要匹配的内容%‘ -- Declare the text we want to search for DECLARE @Text nvarchar(4000); SET @Text = ‘要匹配的内容‘; -- 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‘);
以上是关于sql server 查找包含字符串的对象的主要内容,如果未能解决你的问题,请参考以下文章
为啥当 WHERE 子句包含参数化值时 SQL Server 使用索引扫描而不是索引查找
SQL server 如何查找库中两个表中是不是包含相同的信息?