How to find a string inside a entire database?

前端 未结 9 1312
一整个雨季
一整个雨季 2020-12-13 06:04

I have one specific string, such as \"123abcd\" for example but I don\'t know the name of the table or even the name of the column inside the table on my SQL Server Database

相关标签:
9条回答
  • 2020-12-13 06:55

    I usually use information_Schema.columns and information_schema.tables, although like @yuck said, sys.tables and sys.columns are shorter to type.

    In a loop, concatenate these

    @sql = @sql + 'select' + column_name + 
    ' from ' + table_name + 
    ' where ' + column_name ' like ''%''+value+''%' UNION
    

    Then execute the resulting sql.

    0 讨论(0)
  • 2020-12-13 06:55

    Common Resource Grep (crgrep) will search for string matches in tables/columns by name or content and supports a number of DBs, including SQLServer, Oracle and others. Full wild-carding and other useful options.

    It's opensource (I'm the author).

    http://sourceforge.net/projects/crgrep/

    0 讨论(0)
  • 2020-12-13 06:57

    I think you have to options:

    1. Build a dynamic SQL using sys.tables and sys.columns to perform the search (example here).

    2. Use any program that have this function. An example of this is SQL Workbench (free).

    0 讨论(0)
提交回复
热议问题