In this article, we want to discuss about 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 generator, 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
Search String Value in all Columns of a Table in SQL Server

Leave a Reply