Skip to content
Advertisement

How to get the actual script of a stored procedure in another server?

I use SQL Server 2017. I have linked a serverdatabase to another my main database. So, if I execute the query below, it works and brings me the correct data:

What I want to do is to get the actual script of a stored procedure from the linked database. Assume I have the stored procedure: sp_GetNumbers, then I can receive its content if I execute the code below in the linked server itself:

However I couldn’t manage to do it from my main database. I’ve tried below but does not work.

My question is: How can I get the script of a Stored Procedure in SQL server B ([myOtherServer].[myOtherDatabase]) by running a query in SQL server A ([myMainServer].[myMainDatabase])?

Advertisement

Answer

The object functions are context specific so that won’t work, but you could use the system views. Something like this:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement