|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, April 26, 2013 12:28 PM
Points: 30,
Visits: 110
|
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Tuesday, March 29, 2011 2:59 PM
Points: 473,
Visits: 606
|
|
There is one problem with your script: it will not find all instances of the text in SPs, Views or functions that are larger then 4000 characters and the searchabe text is close to the 4000 character position. Because SQL Server will split the code between multiple syscomments records you may end up with 'Joshua' in one syscomments record and 'A Walker' in another.
In order to prevent this you could use something similar
SELECT DISTINCT name FROM syscomments SC INNER JOIN sysobjects SO ON SC.id = SO.id WHERE SC.text LIKE '%' + @FieldName + '%'
UNION
SELECT DISTINCT name FROM syscomments AS L1 INNER JOIN sysobjects SO ON L1.id = SO.id INNER JOIN syscomments AS L2 ON L1.id = L2.id AND L1.colid = L2.colid - 1 WHERE RIGHT(L1.text, 50) + LEFT(L2.text, 50) LIKE '%' + @FieldName + '%'
This is what I use when looking for a text in the SQL code. It only works for one database but so far I did not have a need to search all databases on a server.
--------------------------------------------- Nothing is impossible. It is just a matter of time and money.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Today @ 9:59 AM
Points: 16,
Visits: 508
|
|
| Don't forget to clean up and drop the #Results table if running as a script not a procedure.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Today @ 12:09 AM
Points: 334,
Visits: 83
|
|
This script crash when a database is offline:
A simple where condition should is missing: SELECT [NAME] FROM Master.dbo.sysdatabases WHERE [NAME] NOT IN ('MASTER', 'TEMPDB', 'MSDB', 'MODEL') AND Status & 512 = 0
Regards, Yenidai
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, April 26, 2013 12:28 PM
Points: 30,
Visits: 110
|
|
Excellent suggestions all... and all situations I never ran into ... Except maybe the length issue and I wasn't aware I was running into that issue...
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Tuesday, March 29, 2011 2:59 PM
Points: 473,
Visits: 606
|
|
jwalker8680 (4/23/2009)
Except maybe the length issue and I wasn't aware I was running into that issue... 
Lucky you. I found out the hard way.
--------------------------------------------- Nothing is impossible. It is just a matter of time and money.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 10:39 AM
Points: 70,
Visits: 135
|
|
Any suggestions on how to ignore results where the searched for text only occurs as part of a comment?
Remember this when a developer tells you it will just be temporary. Temporary = Permanent.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Saturday, October 10, 2009 4:46 AM
Points: 1,
Visits: 0
|
|
Hi,
There is an article posted on my Blog site where you can search for specific text in all sql server objects easily and the query is also very simple.
Search Text in all SQL Server Object
Cheers...
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Today @ 6:40 AM
Points: 41,
Visits: 1,093
|
|
Red Gate SQL search will do this and much more as well as being totally free.
http://www.red-gate.com/products/sql-development/sql-search/
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: 2 days ago @ 12:26 PM
Points: 1,258,
Visits: 341
|
|
| Josha, what is the main difference from this version and the version your wrote in July 2007 and updated in May 2009 that also performs a string search?
|
|
|
|