If the goal is simply to deploy the stored procedure in each client database, something like this script should work.
-- put the entire stored procedure code in a variable -- have it start with "PROC" so we can easily either create or alter the -- procedure based on whether it already exists or not DECLARE @sp_code NVARCHAR(MAX) = ' PROC [dbo].[usp_some_proc] AS SELECT DB_NAME() ' -- get a list of databases to install the stored procedure to SELECT [name] INTO
Maybe you can do something stain by pulling the procedure definition out of sys.sql_modules, but there may be some complications when doing CREATE vs. ALTER.
source share