zoukankan      html  css  js  c++  java
  • 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');
  • 相关阅读:
    WKT转换工具terraformers
    关于微信公众号投票结果的通告
    个人博客03
    个人博客02
    个人博客01
    四则运算2
    学习进度条
    构建之法阅读笔记01
    错误随笔
    软件工程概论第一节
  • 原文地址:https://www.cnblogs.com/davidhou/p/5952225.html
Copyright © 2011-2022 走看看