导出模式比较升级脚本到transact-sql与visual studio 2012 premium

时间:2014-01-24 23:53:34

标签: visual-studio-2012 schema-compare

我在使用Visual Studio 2012 Premium时很幸运。我给出的任务之一是在开发和系统测试数据库之间进行模式比较。这一切都很好,但是当我生成脚本移交给迁移团队时,我在标题处得到了这个:


/*
Deployment script for MyGloriousDatabase

This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/

GO
:setvar DatabaseName "MyGloriousDatabase"
:setvar DefaultFilePrefix "MyGloriousDatabase"
:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\"
:setvar DefaultLogPath "C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\"

GO
:on error exit
GO
/*
Detect SQLCMD mode and disable script execution if SQLCMD mode is not supported.
To re-enable the script after enabling SQLCMD mode, execute the following:
SET NOEXEC OFF; 
*/
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
    BEGIN
        PRINT N'SQLCMD mode must be enabled to successfully execute this script.';
        SET NOEXEC ON;
    END

GO
USE [$(DatabaseName)];
...

现在,将它修剪成一个.sql脚本并不难,只需在SSMS中运行即可。但我已经看到以前版本的Visual Studio有一个“导出到Transact-SQL”选项。这个选项隐藏在2012年吗?我能找到的最好的选择是注释掉SQLCMD线。

谢谢!

1 个答案:

答案 0 :(得分:6)

我没有看到选项来执行此Visual Studio 2013 Premium,但是生成的脚本可以通过SSMS中的Query-> SQLCMD Mode菜单项打开SQL命令模式在SSMS中运行。

请参阅:sql-server-setvar-error