Solved

Where_Am_I  Script

Posted on 2004-09-22
5
294 Views
Last Modified: 2012-06-22
I used to have a script that I ran in Query Analyzer called Where_Am_I.  It would allow me to search a database for any reference to string that I passed as a parameter.  i.e. Where_Am_I  'UserName'  might return a list of all the tables that contain a field called UserName and all stored procedures that have a reference to this field.

I was hoping someone might have a sql script like that they can provide.

Thanks.
0
Comment
Question by:mtgcpc
  • 2
5 Comments
 
LVL 1

Expert Comment

by:E-Squared
ID: 12128098
CREATE PROCEDURE FindObjects(@KeyWord as varchar(100))
AS
SELECT
      *
      FROM sysobjects O
            INNER JOIN syscomments C on O.ID = C.ID
      WHERE C.text like '%' + @KeyWord + '%'

GO

FindObjects 'YourStringToFind'

-----------------------

This method has the flaw that any token which is split by an 8000-byte boundary will not be found. Do you want a version that does not have this limitation?
0
 
LVL 1

Accepted Solution

by:
SirParadox earned 125 total points
ID: 12128855
I have two Procedures I use regulary tl and sl
 tl for table lookup
 sl for procedure - function - trigger search

tl 'IpAddresses'
Sl 'SCOPE_IDENTITY()'

...


CREATE PROCEDURE sl
        @text varchar(64)
      , @Notcontain1 varchar(255) = NULL
      , @Notcontain2 varchar(255) = NULL
      , @Contain1 varchar(255) = NULL
      , @Contain2 varchar(255) = NULL
AS

SELECT 'SELECT text FROM syscomments WHERE ID=' + cast(sysobjects.ID as varchar) + space(10-len(sysobjects.ID)) + ' -- ' + xtype + ' ' + sysobjects.name FROM sysobjects WHERE ID IN (SELECT DISTINCT ID FROM syscomments WHERE
      TEXT like '%' + @text + '%'
            AND (@Notcontain1 IS NULL OR text not like '%' + @Notcontain1 + '%'  )
            AND (@Notcontain2 IS NULL OR text not like '%' + @Notcontain2 + '%'  )
            AND (@Contain1 IS NULL OR text  like '%' + @Contain1 + '%'  )
            AND (@Contain2 IS NULL OR text  like '%' + @Contain2 + '%'  )
      AND Name Not Like 'zzz%' )
ORDER BY sysobjects.Xtype, sysobjects.name
GO

CREATE PROCEDURE tl
@table varchar(64)
AS
      SELECT 'SELECT * FROM ' + cast(name as varchar(128)) from sysobjects where xtype='U' and (name like '%' + @table + '%') ORDER BY NAME
GO
0
 
LVL 1

Expert Comment

by:SirParadox
ID: 12375352
I'm still here, but I guess the Asker is awol
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now