简体   繁体   English

迁移缺少的存储过程

[英]Migrate Missing Stored Procedures

I have 914 stored procedures that I need to shuffle between two databases. 我有914个存储过程,需要在两个数据库之间进行重组。

62 stored procedures on Server1 that are not on Server2, and 790 that are on Server2 that are not on Server1. Server1上不存在Server2上的62个存储过程,Server2上不存在Server1的790个存储过程。

I know exactly what stored procedures are missing, as I ran this query to find them: 当我运行此查询以查找它们时,我确切知道缺少哪些存储过程:

DECLARE @Routine varchar (20) = 'Procedure' --'Function'
    --,@What VARCHAR(200) = '%Survey%'

select SPECIFIC_CATALOG
    ,SPECIFIC_NAME
    ,SPECIFIC_SCHEMA
    --,@@servername AS [Server Name]
    ,'[Server1]' AS [Server Name]
    ,ROUTINE_TYPE
    ,ROUTINE_DEFINITION
    ,CREATED
    ,LAST_ALTERED 

 from [Server1].Database1.information_schema.routines 
where routine_type = @Routine
--AND SPECIFIC_NAME LIKE @What
AND specific_name NOT IN (SELECT SPECIFIC_NAME

                            from [Server2.Database1.information_schema.routines 
                            where routine_type = @Routine
                                --AND SPECIFIC_NAME LIKE @What
                                ) 

UNION all
select SPECIFIC_CATALOG
    ,SPECIFIC_NAME
    ,SPECIFIC_SCHEMA
    --,@@servername AS [Server Name]
    ,'[Server2]' AS [Server Name]
    ,ROUTINE_TYPE
    ,ROUTINE_DEFINITION
    ,CREATED
    ,LAST_ALTERED 
 from [Server2].Database1.information_schema.routines 
where routine_type = @Routine
--AND SPECIFIC_NAME LIKE @What
AND specific_name NOT IN (SELECT SPECIFIC_NAME

                            from [Server1].Database1.information_schema.routines 
                            where routine_type = @Routine
                                --AND SPECIFIC_NAME LIKE @What
                                )

Is there a way to modify this to take the result set and have it automatically move the stored procedures to the server where they are not? 有没有一种方法可以修改它以获取结果集,并让它自动将存储过程移到没有存储过程的服务器上?

I do not need to migrate "every" stored procedure on Server1 or Server2, just the ones that are missing. 我不需要迁移Server1或Server2上的“每个”存储过程,只需迁移那些丢失的存储过程即可。

you should be able to create a SQL Server Database Project in the Visual Studio IDE that comes with SQL Server 2008 您应该能够在SQL Server 2008附带的Visual Studio IDE中创建SQL Server数据库项目

once you create the project and the connection, you can do a database compare. 创建项目和连接后,就可以进行数据库比较。

When the compare is complete, it will show you the differences in the databases and by default will already pre setup to execute to want to copy over what is missing from one to the other, and if there are things you do not want, and you can actually pick and choose with a checkboxes which you would like to have copied and executed over to the T. Just make sure you tell the comparison options you only care about objects, not logins, and other odds and ends that come with SQL Server. 比较完成后,它将向您显示数据库中的差异,并且默认情况下将预先设置要执行的内容,以便将缺少的内容复制到另一个,如果有不需要的内容,并且您可以实际上选择要复制并执行到T的复选框。只需确保告诉比较选项,您只关心对象,而不关注登录以及SQL Server附带的其他零碎对象。

This is what I would do in your situation. 这就是我在您的情况下会做的。 Although going T-SQL it is not impossible either. 尽管使用T-SQL,但也不是没有可能。 I only answering this because this option and Visual Studio IDE does come with the install of SQL Server 2008, and there is no coding involved. 我之所以仅回答这个问题,是因为该选项和Visual Studio IDE确实随SQL Server 2008的安装一起提供,并且不涉及任何编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM