SQL Script: Search all tables for a specific field

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%'
Chris Pietschmann
Chris Pietschmann
Microsoft MVP | App Innovation Leader | Azure, AI & DevOps Architect | HashiCorp Ambassador | Author
I'm a Practice Leader, App Innovation specialist, solution architect, developer, SRE, trainer, and author with 25+ years of experience helping enterprises turn AI, app modernization, cloud architecture, and DevOps into real business outcomes.