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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:31:19+00:00 2026-05-13T15:31:19+00:00

Let’s say I have information in a table that is in the wrong database

  • 0

Let’s say I have information in a table that is in the wrong database (like Customer info in the Items database). I really want to move this information, but I need to figure out who’s using it. If I use this code to search for the table name, say CustomerContactNumbers, is there any possibility of things slipping by? I’m going to ignore any composed SQL that’s happening outside of the database, I can do a text search in source control for that (plus don’t you think they deserve to have their code broken in that case?). [Not my code, I lifted it from somewhere, probably here]:

declare @Search varchar(255) 
SET @Search='%CustomerContactNumbers%' 

SELECT DISTINCT 
    LEFT(so.name, 100) AS Object_Name, 
    "object_type"=left( 
          case so.type 
        when 'U' then 'Table - User' 
        when 'S' then 'Table - System' 
        when 'V' then 'Table - View' 
        when 'TR' then 'Trigger' 
        when 'P' then 'Stored Procedure' 
        when 'C' then 'Constraint - Check' 
        when 'D' then 'Default' 
        when 'K' then 'Key - Primary' 
        when 'F' then 'Key - Foreign' 
        when 'L' then 'Log'           
        when 'R' then 'Rule' 
        when 'RF' then 'Replication Filter stp' 
        else '<<UNKNOWN '''+so.type+'''>>' 
    end  -- case so.type 
        ,25) 
FROM syscomments sc  
    INNER JOIN sysobjects so  
        ON so.id = sc.id 
WHERE 
    text Like '%'+@Search+'%' 
ORDER BY  
    2,1 

Does that cover it?

  • 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-05-13T15:31:20+00:00Added an answer on May 13, 2026 at 3:31 pm

    You didn’t specify what version of SQL Server you are using. I am assuming 2000 but if you are on 2005 or later you should look into the sys.sql_modules catalog view and/or the OBJECT_DEFINITION() function. As a quick example:

    SELECT SCHEMA_NAME(schema_id) +'.'+ name
    FROM sys.objects
    WHERE OBJECT_DEFINITION(object_id) LIKE '%' + @Search + '%';
    
    -- or
    
    SELECT OBJECT_SCHEMA_NAME(object_id) +'.'+ OBJECT_NAME(object_id)
    FROM sys.sql_modules
    WHERE [definition] LIKE '%' + @Search + '%';
    

    Also you might want to check out the following StackOverflow thread about RedGate’s new and free SQL Search tool, and some alternative approaches:

    https://stackoverflow.com/questions/2187763/what-other-products-are-similar-to-redgates-sql-search/

    If you truly are stuck on 2000 then this article I wrote almost 10 years ago may still be relevant and helpful (including accommodating for the 4K chunk problem that Matt mentioned):

    http://databases.aspfaq.com/database/how-do-i-find-a-stored-procedure-containing-text.html

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

Sidebar

Ask A Question

Stats

  • Questions 404k
  • Answers 404k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I need to retrieve a list of the columns in… May 15, 2026 at 5:39 am
  • Editorial Team
    Editorial Team added an answer I think you want get_the_category() and get_category_link(): <?php // everything… May 15, 2026 at 5:39 am
  • Editorial Team
    Editorial Team added an answer I suspect the client (browser) is disconnecting during the writing… May 15, 2026 at 5:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.