SQL Server – How to Identify the Object Behind a Database Synonym

sql serversynonymst-sql

I have a script which uses a synonym. I have to alter that code and the problem is I can't understand which object that synonym refers to. Is there a way to find out? I am using the original database instance where that synonym has been created.

PS I am using MS SQL Server.

Thanks for your time.

Best Answer

This seems to work for me:

SELECT
    [Schema] = Sch.name
  , Object   = Syn.name
  , Syn.base_object_name
FROM sys.synonyms          AS Syn
    INNER JOIN sys.schemas AS Sch
        ON Sch.schema_id = Syn.schema_id;