Archive for the ‘Tools’ Tag
SQL Server – Finding tables for column name
Needed to know which tables in the database I was working on had any FK columns I needed to consider. Here is a nice query to help.
USE [database-name]
GO
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 '%Service%'
ORDER BY Schema_Name, Table_Name;
Leave a comment