Solved

Where_Am_I  Script

Posted on 2004-09-22
5
293 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

746 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

11 Experts available now in Live!

Get 1:1 Help Now