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
SSC Journeyman
SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)

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

Group: General Forum Members
Points: 162 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 Eights!
SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)SSC Eights! (969 reputation)

Group: General Forum Members
Points: 969 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
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 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
One Orange Chip
One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)One Orange Chip (29K reputation)

Group: General Forum Members
Points: 29504 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