Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:10:37+00:00 2026-06-08T16:10:37+00:00

I need to look up an ID in a very large database. The ID

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:10:38+00:00Added an answer on June 8, 2026 at 4:10 pm

    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.

    /*This script will find any text value in the database*/
    /*Output will be directed to the Messages window. Don't forget to look there!!!*/
    
    SET NOCOUNT ON
    DECLARE @valuetosearchfor varchar(128), @objectOwner varchar(64)
    SET @valuetosearchfor = '%putYourGuidHere%' --should be formatted as a like search 
    SET @objectOwner = 'dbo'
    
    DECLARE @potentialcolumns TABLE (id int IDENTITY, sql varchar(4000))
    
    INSERT INTO @potentialcolumns (sql)
    SELECT 
        ('if exists (select 1 from [' +
        [tabs].[table_schema] + '].[' +
        [tabs].[table_name] + 
        '] (NOLOCK) where [' + 
        [cols].[column_name] + 
        '] like ''' + @valuetosearchfor + ''' ) print ''SELECT * FROM [' +
        [tabs].[table_schema] + '].[' +
        [tabs].[table_name] + 
        '] (NOLOCK) WHERE [' + 
        [cols].[column_name] + 
        '] LIKE ''''' + @valuetosearchfor + '''''' +
        '''') as 'sql'
    FROM information_schema.columns cols
        INNER JOIN information_schema.tables tabs
            ON cols.TABLE_CATALOG = tabs.TABLE_CATALOG
                AND cols.TABLE_SCHEMA = tabs.TABLE_SCHEMA
                AND cols.TABLE_NAME = tabs.TABLE_NAME
    WHERE cols.data_type IN ('char', 'varchar', 'nvchar', 'nvarchar','text','ntext')
        AND tabs.table_schema = @objectOwner
        AND tabs.TABLE_TYPE = 'BASE TABLE'
        AND (cols.CHARACTER_MAXIMUM_LENGTH >= (LEN(@valueToSearchFor) - 2) OR cols.CHARACTER_MAXIMUM_LENGTH = -1)
    ORDER BY tabs.table_catalog, tabs.table_name, cols.ordinal_position
    
    DECLARE @count int
    SET @count = (SELECT MAX(id) FROM @potentialcolumns)
    PRINT 'Found ' + CAST(@count as varchar) + ' potential columns.'
    PRINT 'Beginning scan...'
    PRINT ''
    PRINT 'These columns contain the values being searched for...'
    PRINT ''
    DECLARE @iterator int, @sql varchar(4000)
    SET @iterator = 1
    WHILE @iterator <= (SELECT Max(id) FROM @potentialcolumns)
    BEGIN
        SET @sql = (SELECT [sql] FROM @potentialcolumns where [id] = @iterator)
        IF (@sql IS NOT NULL) and (RTRIM(LTRIM(@sql)) <> '')
        BEGIN
            --SELECT @sql --use when checking sql output
            EXEC (@sql)
        END
        SET @iterator = @iterator + 1
    END
    
    PRINT ''
    PRINT 'Scan completed'
    

    If that looks wonky, the script is executing a statement like this

    if exists (select 1 from [schema].[table_name] (NOLOCK) 
                        where [column_name] LIKE '%yourValue%')
    begin
       print select * from [schema].[table_name] (NOLOCK) 
                        where [column_name] LIKE '%yourValue%'
    end
    

    …and just replacing the [schema], [table_name], [column_name] and %yourValue% in a loop.

    It’s filtering on…

    • tables in a specific schema (filter can be removed)
    • only tables, not views (can be adjusted)
    • only columns that will hold the search value
    • the (n)char/(n)varchar/(n)text data 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")

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple of very large tables (over 400,000 rows) that look like
I have stored procedure in my database and i need to look up a
I need a tool that will look at a Microsoft SQL Server database and
I need to pre-compress some very large html/xml/json files (large data dumps) using either
I'm in need of a distributed file system that must scale to very large
I have a very large ASP.NET project that i need to make good with
I have a substantial database... not a very large one - around 1gb of
I need to look up a value in a table where a table can
I need to look up all households with orders. I don't care about the
i need to look xsd file for generate code so i need this document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.