SQL Script To Search All Tables

Posted Sep 15, 2009 | by Jason Faulkner  

Today’s tip is specifically for developers, system administrators, tech support people, etc. who utilize Microsoft’s SQL Server. While SQL Server is incredibly powerful and the provided Management Studio (Express for the free edition) is an excellent tool, a function which is missing is the ability to search all tables in a database for a text value.

While this can be accomplished quite easily via a simple query if you  know the tables you want to search, but what about searching the entire database? If this sounds like something you need, check out this script. I have used it quite a bit and it works very well.

Basically, you just copy the procedure and run it in the database you want to search to create the store procedure. Then run the stored procedure like you would any other. Of course, this can take some time depending on the size of your database, but overall it accomplishes exactly what it says. The author has tested this on SQL 7 and 2000 and I have personally used this on SQL 2005, so I don’t see any reason this would not work on SQL 2008 as well.

Which Of These Traits Applies To YOUR Computing Life?...

One Response to “SQL Script To Search All Tables”

  1. David K. says:

    Ah, good old using SQL to build SQL. I’m always surprised by how many developers don’t know this trick.

Leave a Reply