Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save softcraft-development/272281 to your computer and use it in GitHub Desktop.
Save softcraft-development/272281 to your computer and use it in GitHub Desktop.
Show the remote server data source for synonyms targeting linked servers in SQL Server 2005
select
sk.name as LocalSchemaName,
sn.name as SynonymName,
sn.base_object_name as FullTargetName,
substring( sn.base_object_name, 2, charindex(']', sn.base_object_name) - 2) as LinkedServerName,
sv.data_source as RemoteServerName,
substring(
sn.base_object_name,
charindex('[', sn.base_object_name, 2) + 1,
charindex(
']',
sn.base_object_name,
charindex('[', sn.base_object_name, 2)
) - charindex('[', sn.base_object_name, 2) - 1
) as RemoteDatabaseName
from sys.synonyms sn
inner join sys.schemas sk
on sn.schema_id = sk.schema_id
inner join sys.servers sv
on sv.name = substring( sn.base_object_name, 2, charindex(']', sn.base_object_name) - 2)
order by sk.name, sn.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment