简体   繁体   中英

How to search for a specific string in all columns within all tables of a SQL Server database?

We want to search for a string (ie. "Hello World") in all our database that has about 120 tables. We thought about doing a dump like mysql dump but it came out in a weird bak format.

The search should be done in each column for each table. Is this possible with any type of script, or this is harder than it sounds to me?

No it possible and easy to write a script to do this.

Suggestions: I think you have to use some cursors and use some of these objects to write your script

  1. sys.databases
  2. INFORMATION_SCHEMA.TABLES or sys.tables
  3. INFORMATION_SCHEMA.COLUMNS or sys.columns

Once you have these things in place, searching Hello World under all columns would be more simple

Is this just for a one-off, or something you want to do regularly?

If it's a one-off, how about using the export data wizard to export the tables out to CSV files (assuming you're using SQL Server, although I'm sure most databases have equivalents).

Once you've done this you can just do a 'Find Files' in explorer to find all occurrences?

It's a bit dirty - but it'll work!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM