Let's say I have information in a table that is in the wrong database (like Customer info in the Items database). I really want to move this information, but I need to figure out who's using it. If I use this code to search for the table name, say CustomerContactNumbers, is there any possibility of things slipping by? I'm going to ignore any composed SQL that's happening outside of the database, I can do a text search in source control for that (plus don't you think they deserve to have their code broken in that case?). [Not my code, I lifted it from somewhere, probably here]:
declare @Search varchar(255)
SET @Search='%CustomerContactNumbers%'
SELECT DISTINCT
LEFT(so.name, 100) AS Object_Name,
"object_type"=left(
case so.type
when 'U' then 'Table - User'
when 'S' then 'Table - System'
when 'V' then 'Table - View'
when 'TR' then 'Trigger'
when 'P' then 'Stored Procedure'
when 'C' then 'Constraint - Check'
when 'D' then 'Default'
when 'K' then 'Key - Primary'
when 'F' then 'Key - Foreign'
when 'L' then 'Log'
when 'R' then 'Rule'
when 'RF' then 'Replication Filter stp'
else '<<UNKNOWN '''+so.type+'''>>'
end -- case so.type
,25)
FROM syscomments sc
INNER JOIN sysobjects so
ON so.id = sc.id
WHERE
text Like '%'+@Search+'%'
ORDER BY
2,1
Does that cover it?