How to search a string in databases of SQL Server

后端 未结 3 1496
栀梦
栀梦 2020-12-09 07:09

This Query can search any string value (table name, table data etc) from all the tables/views of any SQL Server database, when you will place any string at \"your te

3条回答
  •  独厮守ぢ
    2020-12-09 07:47

    search given string in the procedures/functions/triggers

    This is actually far easier.

    SELECT OBJECT_NAME(object_id), definition
      FROM sys.sql_modules
     WHERE definition LIKE '%'+@SearchStr+'%'
    

    One way to use it is to add it to the end of your TSQL code, i.e modify the last SELECT:

    SELECT ColumnName, ColumnValue
      FROM @Results
     UNION ALL
    SELECT OBJECT_NAME(object_id), definition
      FROM sys.sql_modules
     WHERE definition LIKE '%'+@SearchStr+'%'
    

    Personally, I'd just run them separately one after the other as separate statements.

提交回复
热议问题