Home:ALL Converter>Finding a table (with data) that references a specific column

Finding a table (with data) that references a specific column

Ask Time:2016-09-09T04:23:27         Author:Brad Renshaw

Json Formatter

I have a database that has a lot of tables with no data in them. I am wanting to find all of the tables that reference a specific column, but I want to make sure that the tables that show up have data and aren't empty. So far I have been able to show which tables have data using

select 
t.name TableName, i.rows Records
from sysobjects t, sysindexes i
where t.xtype = 'U' and i.id = t.id and i.indid in (0,1) AND rows > 0 
order by TableName;

I have also been able to show which tables reference the specific column that I am wanting by using:

SELECT * 
FROM INFORMATION_SCHEMA.COLUMNS 
WHERE COLUMN_NAME = 'COLUMN_NAME' 

I just don't know how to combine the two.

Author:Brad Renshaw,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39399580/finding-a-table-with-data-that-references-a-specific-column
yy