views:

32

answers:

3

I have a stored procedure in a test instance of a sql server (named sql2008test\sql2008_test) and it is located in one database. I would like to use this procedure also in production instance (named sql2008prod\sql2008_prod). Should I copy this procedure into this prod instance or can I modify my procedure somehow to query data from prod instance? The procedure is shown below.

CREATE PROCEDURE dbo.PROC_getDbInfo
AS
    SET NOCOUNT ON

    TRUNCATE TABLE dbo.dbinfo
    EXECUTE sp_msforeachdb 'insert into dbo.dbinfo 
            select  ''?'' as name,
                    type_desc, 
                    physical_name, 
                    state_desc, 
                    size * 1.0/128 as size_in_mb, 
                    max_size, 
                    growth * 1.0/128 as growth_in_mb, 
                    is_percent_growth,
                    is_read_only    
    from [?].sys.database_files'


    SELECT  @@SERVERNAME as instance_name,
        f.name,
        d.create_date,
        d.compatibility_level,
        d.collation_name,
        d.user_access_desc,
        d.state_desc,
        d.recovery_model_desc,
        d.page_verify_option_desc,
        d.log_reuse_wait_desc,
        f.type_desc, 
        f.physical_name, 
        f.state_desc, 
        f.size_in_mb, 
        f.max_size, 
        f.growth_in_mb, 
        f.is_percent_growth,
        f.is_read_only  
    FROM dbo.dbinfo AS f INNER JOIN
            sys.databases AS d
                ON f.name = d.name
    ORDER BY f.name
GO
A: 

Use Server Objects>Linked Servers so you can select between different instances.

MahmutHAKTAN
Well, it seems that I cannot do this, because I'm not in the sysadmin role.
atricapilla
+1  A: 

Run the creation script on your production instance (of course, going through any release processes you have). You could set up linked servers, if you can access your production server from your test instance, but I wouldn't head down that route without a good reason.

BTW, you still have the extra GO statements in that script meaning the sproc will ONLY be created with SET NOCOUNT ON in and won't do anything.

AdaTheDev
Sorry, edited, I copied the wrong old one to this post.
atricapilla
A: 

Copy your procedure into Production db.

Muhammad Kashif Nadeem
Yes, that is one option, but it would be easier to manage these procedures if there is only one place where procedures are located.
atricapilla