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 134419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:36:35+00:00 2026-05-11T06:36:35+00:00

I am lost in a big database and I am not able to find

  • 0

I am lost in a big database and I am not able to find where the data I get comes from. I was wondering if it is possible with SQL Server 2005 to search for a string in all tables, rows and columns of a database?

Does anybody has an idea if it is possible and how?

  • 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. 2026-05-11T06:36:36+00:00Added an answer on May 11, 2026 at 6:36 am

    This code should do it in SQL 2005, but a few caveats:

    1. It is RIDICULOUSLY slow. I tested it on a small database that I have with only a handful of tables and it took many minutes to complete. If your database is so big that you can’t understand it then this will probably be unusable anyway.

    2. I wrote this off the cuff. I didn’t put in any error handling and there might be some other sloppiness especially since I don’t use cursors often. For example, I think there’s a way to refresh the columns cursor instead of closing/deallocating/recreating it every time.

    If you can’t understand the database or don’t know where stuff is coming from, then you should probably find someone who does. Even if you can find where the data is, it might be duplicated somewhere or there might be other aspects of the database that you don’t understand. If no one in your company understands the database then you’re in a pretty big mess.

    DECLARE     @search_string  VARCHAR(100),     @table_name     SYSNAME,     @table_schema   SYSNAME,     @column_name    SYSNAME,     @sql_string     VARCHAR(2000)  SET @search_string = 'Test'  DECLARE tables_cur CURSOR FOR SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'  OPEN tables_cur  FETCH NEXT FROM tables_cur INTO @table_schema, @table_name  WHILE (@@FETCH_STATUS = 0) BEGIN     DECLARE columns_cur CURSOR FOR SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = @table_schema AND TABLE_NAME = @table_name AND COLLATION_NAME IS NOT NULL  -- Only strings have this and they always have it      OPEN columns_cur      FETCH NEXT FROM columns_cur INTO @column_name     WHILE (@@FETCH_STATUS = 0)     BEGIN         SET @sql_string = 'IF EXISTS (SELECT * FROM ' + QUOTENAME(@table_schema) + '.' + QUOTENAME(@table_name) + ' WHERE ' + QUOTENAME(@column_name) + ' LIKE ''%' + @search_string + '%'') PRINT ''' + QUOTENAME(@table_schema) + '.' + QUOTENAME(@table_name) + ', ' + QUOTENAME(@column_name) + ''''          EXECUTE(@sql_string)          FETCH NEXT FROM columns_cur INTO @column_name     END      CLOSE columns_cur      DEALLOCATE columns_cur      FETCH NEXT FROM tables_cur INTO @table_schema, @table_name END  CLOSE tables_cur  DEALLOCATE tables_cur 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SQL Server 2005. I have a site that people can vote
I've had a big problem in replicating a simple SQL Server 2008 R2 Express
I find fwrite fails when I am trying to write somewhat big data as
I lost the source code from one project I did on the company I'm
I have a big database (~4GB), with 2 large tables (~3M records) having ~180K
I want to access facebook's database. I want to have some SQL-like access, let's
This is possible a problem what i lost more time to think how to
Big question update before continue: Is Items.SortDescription getting fired INotifyPropertyChanged events? From the code
I've created, as an homework, a big project which simulate a mailbox server (only
I have just 'inherited' a Java-project and not coming from a Java-background I am

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.