Is there a way to search for one value (in my case it is a UID of the type char(64)) inside any column of any table inside one MS-SQL database?
I'm sitting in front of a huge database without any idea how the tables had to be linked together. To find that out I'd like to list all tables and there columns that contain a certain value in any row. Is that possible?
One way could be to just dump the entire database into a text file and than use any text-editor to search for the value - but this would be pure pain if the database is too huge.
Thanks for the question as this is a really useful topic. I will use this myself also now for reasons including the one you put forward. :-)
http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm
Andrew
-Edit, here's the actual T-SQL, in case of link rot:
I expanded the code, because it's not told me the '
record number
', and I must to refind it.There is a nice script available on http://www.reddyss.com/SQLDownloads.aspx
To be able to use it on any database you can create it like in: http://nickstips.wordpress.com/2010/10/18/sql-making-a-stored-procedure-available-to-all-databases/
Not sure if there is other way.
To use it then use something like this:
Late one but hopefully useful…
I had the same issue several months ago but I managed to solve this using third party tools.
All tools mentioned below are 100% free.
I’ve used ApexSQL Search with good success for searching both objects and data in tables. It comes with several other features such as relationship diagrams and such…
I was a bit slow on large (40GB TFS Database) databases though…
Apart from this there is also SSMS Tools pack that offers a lot of other features that are quite useful even though these are not directly related to searching text.
I found a fairly robust solution at https://gallery.technet.microsoft.com/scriptcenter/c0c57332-8624-48c0-b4c3-5b31fe641c58 , which I thought was worth pointing out. It searches columns of these types: varchar, char, nvarchar, nchar, text. It works great and supports specific table-searching as well as multiple search-terms.
Source: http://fullparam.wordpress.com/2012/09/07/fck-it-i-am-going-to-search-all-tables-all-collumns/
I have a solution from a while ago that I kept improving. Also searches within XML columns if told to do so, or searches integer values if providing a integer only string.