synonym in SQL server 2005

5 pts.
Tags:
SQL Server
SQL Server 2005
How can one get the information about the object type of synonym that is whether the synonym belongs to function, stored procedure, table or view using a query. Sys.synonyms table contains information about synonyms present in a particular database but it does not tell for which object the synonym is created?

Answer Wiki

Thanks. We'll let you know when a new response is added.

You have to use the base_object_name column to figure it out.

This code should do the trick.

select *, object_name(object_id(substring(base_object_name, charindex('.', base_object_name)+1, len(base_object_name))))
from sys.synonyms

You can now use sys.objects to get the base object type.

Something like this:

SELECT o.name,o.type_desc
FROM sys.objects o JOIN sys.synonyms s
ON object_name(object_id(substring(s.base_object_name, charindex('.', s.base_object_name)+1, len(s.base_object_name)))) = o.name
WHERE s.name = 'your_synonym

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following