I'm using a piece of code (via Excel VBA) which seems to be in several spots around the internet. The intention is to find all tables which contain a certain field/column.
This is my SQL string:
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE 'MyCol'
ORDER BY schema_name, table_name;
This works perfectly for most tables, but not views. Is there a way to look within views as well?
If anyone has any ideas, I'd really appreciate feedback. I hope this all makes sense as I am fairly new to SQL, but I have been doing VBA for a long time. Thanks so much in advance!