码迷,mamicode.com
首页 > 数据库 > 详细

sql server 查找包含字符串的对象

时间:2016-10-12 13:54:39      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

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 查找包含字符串的对象

标签:

原文地址:http://www.cnblogs.com/davidhou/p/5952225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!