Question

How can I determine column metadata from a table synonym in a SQL Server 2005 database? I have a synonym called 'ProjectSyn' for a table called 'Project', but I can find no column metadata for the synonym.

My guess is to somewhere determine the 'base table' for the synonym, then query for column metadata for that table. Is this a correct approach, and if not, what would be?

Was it helpful?

Solution

Something like this? (edited)

select c.*
from
   sys.columns c
   inner join sys.synonyms s on c.object_id = object_id(s.base_object_name)
where
   s.name = 'ProjectSyn'

OTHER TIPS

This is my solution which works with synonyms of different databases:

SELECT TOP 0 * INTO #TEMP1 FROM YourTable 
SELECT
    [column_name] = c.name,
    [data_type] = t.name,
    [character_maximum_length] = c.max_length
FROM tempdb.sys.columns c
inner join tempdb.sys.types t on t.system_type_id = c.system_type_id
WHERE [object_id] = object_id('tempdb..#TEMP1');
DROP TABLE #TEMP1

Yes, I think getting the base object and then retrieve the columns, is your only option.

To get the base object name for a synonym, just query the view sys.synonyms

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top