I need to look up an ID in a very large database. The ID is:
0167a901-e343-4745-963c-404809b74dd9
The database has hundreds of tables, and millions of rows in the big tables.
I can narrow the date to within the last 2 or 3 months, but that’s about it. I’m looking for any clues as to how to narrow down searches like this.
One thing I’m curious about is whether using LIKE searches helps.
i.e does it help to do something like
select top 10 *
from BIG_TABLE
where DESIRED_ID like '016%'
Any tips/suggestions are greatly appreciated . The database is being accessed remotely so that’s part of the challenge
I have this script that I built several years ago for a similar purpose, albeit with text fields. It finds eligible columns, and then searches through those columns for the value. As you have a non-deterministic scope, you may not be able to do better than something like this.
You may want to tweak it a bit to include uniqueidentifier columns – if that is actually the datatype – or use an equal instead of a like search.
If this is something you are going to reuse periodically, you could feed it a list of common tables or columns to find these things in, so it doesn’t take as long to find things.
If that looks wonky, the script is executing a statement like this
…and just replacing the
[schema],[table_name],[column_name]and%yourValue%in a loop.It’s filtering on…
(n)char/(n)varchar/(n)textdata types (add or change, be cognizant of data type conversion)Lastly, output does not go to the results grid. Check the Messages window (where you see "N rows affected")