In this article, we want to discuss a nice function to Search String Value in all Columns of a Table in SQL Server. Before we get started, if you want to know about random number generators, please go through the following article: Random Number Generator Script – SQL Query.

One of the common questions in various SQL Server user forums is how to find information in all columns of the table or in all tables of the database for a particular column. This article expands on the solution from that original blog post and also examines several other interesting common scenarios.

Searching a String Value in all Columns of a Table

To test this procedure you can pass string name to search, table schema, and table name like so:

Searching String in all Columns in all Tables of a Database

We may want to run the above script for all tables in the database. In this case, we can use a cursor loop against all tables in the database with the following code:

Search String Value in all Columns of a Table in SQL Server

The article was published on September 11, 2014 @ 4:51 AM

Leave a Comment