SQL Script: Search all tables for a specific field

Oct 29, 2004  • Database

DECLARE @NAME_TO_SEARCH_FOR nvarchar(50)

SET @NAME_TO_SEARCH_FOR = '%photo%'

SELECT sysobjects.name AS Table_Name, syscolumns.name AS Column_Name
FROM syscolumns INNER JOIN sysobjects ON syscolumns.id = sysobjects.id
WHERE syscolumns.name LIKE @NAME_TO_SEARCH_FOR AND sysobjects.Type Like 'U%'