How to find all SQL tables with a column name
Views (4574)
Often I need to find all the tables in Dynamics GP that have a particular column or search for all columns where I only have a partial column name. Over the years I have seen lots of different code to accomplish this, so this is nothing new. But I am asked about this enough that I thought I would share the code I use:
SELECT
TABLE_NAME, COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME in
(SELECT name
FROM sysobjects
WHERE xtype = 'U')
and COLUMN_NAME like '%xxxx%' -- replace with yours
ORDER BY COLUMN_NAME, TABLE_NAME
Just replace the xxxx with what you are looking for and run.
Filed under: SQL Server Tagged: SQL code
This was originally posted here.

Like
Report
*This post is locked for comments