SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Find a string in database objects


Find a string in database objects

Author
Message
Laurent Michaud
Laurent Michaud
Valued Member
Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)Valued Member (54 reputation)

Group: General Forum Members
Points: 54 Visits: 38
Comments posted to this topic are about the item Find a string in database objects
Jason Akin
Jason Akin
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 87
I wasn't seeing any tables in my results. I think you need a left outer join to sys_columns because Object_Definition on Table
returns NULL
David Korb
David Korb
SSC Veteran
SSC Veteran (235 reputation)SSC Veteran (235 reputation)SSC Veteran (235 reputation)SSC Veteran (235 reputation)SSC Veteran (235 reputation)SSC Veteran (235 reputation)SSC Veteran (235 reputation)SSC Veteran (235 reputation)

Group: General Forum Members
Points: 235 Visits: 311
I think mine works better:
http://www.sqlservercentral.com/scripts/Search/64839/

It hits all databases and includes job steps.
Kevin Kennedy
Kevin Kennedy
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 275
Nice script and great tip on doing the left join to get table info.



SELECT
DISTINCT
TypeDescription,
SchemaName,
Name,
'...' + SUBSTRING(t.ObjectDefinition,
CHARINDEX(@chvStringToFind,
t.ObjectDefinition)
- @intNbCharToExtract,
LEN(@chvStringToFind)
+ ( @intNbCharToExtract * 2 )) + '...' AS Extract,
CreationDate,
ModificationDate
FROM (
SELECT DISTINCT
o.name AS Name,
SCHEMA_NAME (o.schema_id) AS SchemaName,
o.type_desc AS TypeDescription,
o.create_date AS CreationDate,
o.modify_date AS ModificationDate,
ISNULL(OBJECT_DEFINITION(object_id), c.name) AS ObjectDefinition
FROM sys.objects o WITH (NOLOCK)
LEFT OUTER JOIN syscolumns c
ON c.id = o.object_id
WHERE
--(
-- ( o.type IN ( 'AF', 'FN', 'IF', 'P', 'TF', 'TT', 'U', 'V', 'X' )
-- AND @chrObjectType IS NULL
-- )
-- OR o.type = @chrObjectType
--)
(o.type = @chrObjectType OR @chrObjectType IS NULL)
AND (OBJECT_DEFINITION(o.object_id) LIKE '%' + @chvStringToFind + '%'
OR
c.name LIKE '%' + @chvStringToFind + '%'
)
) AS t
ORDER BY
1,
2,
3,
4,
5,
6


Iwas Bornready
Iwas Bornready
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13652 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search