Pages

Social Icons

Wednesday 30 January 2013

Find a string in whole database of SQL-Server

Hi,

I want to search a string in my database, Is there any way to do this?

Ans : yes, we can do this using Red Gate Search tool.

Can we do the same using SQL Query?

Now this is a tricky one but we can do this using a simple SQL-Query.


SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS ObjectName, obj.type, obj.type_desc, sm.definition
FROM sys.sql_modules AS sm
JOIN sys.objects AS obj ON sm.object_id = obj.object_id
WHERE sm.definition LIKE '%YOUR_WORD%'

Thx,
RS


1 comment: