Very new to SQL Sever here... I understand the concept of joining tables, etc. but what is the easiest way to determine which columns are shared?
Say for instance we ha
This could well indicate a fundamental design issue but to find column names shared by both tables a couple of options would be
SELECT name
FROM sys.columns
WHERE object_id IN (object_id('dbo.Table1'),
object_id('dbo.Table2'))
GROUP BY name
HAVING COUNT(*) = 2
Or
SELECT name
FROM sys.columns
WHERE object_id = object_id('dbo.Table1')
INTERSECT
SELECT name
FROM sys.columns
WHERE object_id = object_id('dbo.Table2')