SQL Script To Search All Tables

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.

Free eBook!

Like what you read?

If so, please join over 28,000 people who receive our exclusive weekly newsletter and computer tips, and get FREE COPIES of 5 eBooks we created, as our gift to you for subscribing. Just enter your name and email below:

Post A Comment Using Facebook

  • David K.

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

What’s Your Preference?

Daily Alerts

Each day we send out a quick email to thousands of PCMECH readers to notify them of new posts. This email is just a short, plain email with titles and links to our latest posts. You can unsubscribe from this service at any time.

You can subscribe to it by leaving your email address in the following field and confirming your subscription when you get an email asking you to do so.

Enter your email address for
Daily Updates:

Weekly Newsletter

Running for over 6 years, the PCMECH weekly newsletter helps you keep tabs on the world of tech. Each issue includes news bits, an article, an exclusive rant as well as a download of the week. This newsletter is subscribed to by over 28,000 readers (many who also subscribe to the other option) - come join the community!

To subscribe to this weekly newsletter simply add your email address to the following field and then follow the confirmation prompts. You will be able to unsubscribe at any time.

Enter your email address for
Free Weekly Newsletter: