2017-02-20 67 views

回答

0

这取决于您正在使用哪个版本的SSMS。

如果您使用的是使用Visual Studio shell的版本,那么它已经集成到SSMS中,您只需启用它即可。 This来自Sql Server团队的博客文章解释如何。

如果您使用的是以前的版本,那么您必须下载并安装提供程序。 This提供了完整的细节。在SSMS

0

启用源代码控制集成若要在SSMS TFS集成,请按照下列步骤操作:

1)如果正在运行关闭SSMS。

2)在您的SSMS机器上安装Visual Studio 2015。如果您还没有Visual Studio,Community Edition将正常工作。这是一个大的下载,但如果您的唯一目的是在SSMS中启用源代码管理,则可以通过在Visual Studio安装期间取消选择所有语言来节省一些空间。 3)编辑在C:\ Program Files(x86)\ Microsoft SQL Server \ 130 \ Tools \ Binn \ ManagementStudio \ ssms.pkgundef中找到的ssms.pkgundef文件。

在此文件的顶部有一系列与TFS源代码管理功能相关的程序包组合在一起。这些软件包必须从pkgundef文件中删除。这可以通过删除部分或使用'//'注释每行来完成。这里是一个例子,该部分应该看起来如果注释掉:// TFS SCC配置条目。 TFS条目阻止来自加载的团队资源管理器。

// Microsoft.VisualStudio.TeamFoundation.Lab 
//[$RootKey$\Packages\{17c5d08a-602c-4dfb-82b5-8e0f7f50c9d7}] 
// GitHub Package 
//[$RootKey$\Packages\{c3d3dc68-c977-411f-b3e8-03b0dccf7dfc}] 
// Team Foundation Server Provider Package 
//[$RootKey$\Packages\{5BF14E63-E267-4787-B20B-B814FD043B38}] 
// Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.WitPcwPackage 
//[$RootKey$\Packages\{6238f138-0c0c-49ec-b24b-215ee59d84f0}] 
// Microsoft.VisualStudio.TeamFoundation.Build.BuildPackage 
//[$RootKey$\Packages\{739f34b3-9ba6-4356-9178-ac3ea81bdf47}] 
// Microsoft.VisualStudio.TeamFoundation.WorkItemTracking 
//[$RootKey$\Packages\{ca39e596-31ed-4b34-aa36-5f0240457a7e}] 
// Microsoft.VisualStudio.TeamFoundation 
//[$RootKey$\Packages\{b80b010d-188c-4b19-b483-6c20d52071ae}] 
// Microsoft.TeamFoundation.Git.Provider.SccProviderPackage 
//[$RootKey$\Packages\{7fe30a77-37f9-4cf2-83dd-96b207028e1b}] 
// Microsoft.VisualStudio.TeamFoundation.VersionControl.SccPcwPluginPackage 
//[$RootKey$\Packages\{1b4f495a-280a-3ba4-8db0-9c9b735e98ce}] 
// Microsoft.VisualStudio.TeamFoundation.VersionControl.HatPackage 
//[$RootKey$\Packages\{4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}] 
// Visual SourceSafe Provider Package 
//[$RootKey$\Packages\{AA8EB8CD-7A51-11D0-92C3-00A0C9138C45}] 
// Visual SourceSafe Provider Stub Package 
    [$RootKey$\Packages\{53544C4D-B03D-4209-A7D0-D9DD13A4019B}] 
// Microsoft.VisualStudio.TeamFoundation.Initialization.InitializationPackage 
    [$RootKey$\Packages\{75DF55D4-EC28-47FC-88AC-BE56203C9012}] 
// Team Foundation Server Provider Stub Package 
    [$RootKey$\Packages\{D79B7E0A-F994-4D4D-8FAE-CAE147279E21}] 
// Microsoft.VisualStudio.Services.SccDisplayInformationPackage 
    [$RootKey$\Packages\{D7BB9305-5804-4F92-9CFE-119F4CB0563B}] 
// Microsoft.VisualStudio.TeamFoundation.Lab.LabPcwPluginPackage 
    [$RootKey$\Packages\{e0910062-da1f-411c-b152-a3fc6392ee1f}] 
    [$RootKey$\ToolsOptionsPages\Source Control] 
    [$RootKey$\AutoLoadPackages\{11b8e6d7-c08b-4385-b321-321078cdd1f8}] 
// TFS SCC Configuration entries. 

一旦完成,启动SSMS和“Team”菜单应该在SSMS菜单栏中可见。该菜单和相关功能是标准的Visual Studio功能。这可以连接到TFS服务器或Git服务器。

3

直接来自SSMS的SQL数据库版本可以使用各种第三方加载项来完成。例如ApexSQL Source Control具有无缝的SSMS集成,它不仅可以用于TFS,而且以下SC系统可以直接使用:Git,Subversion,Mercurial,Perforce。 Team Foundation Server支持包括在线版本Visual Studio Team Services。

this article所述,ApexSQL源代码管理加载项引入了一个名为“操作中心”选项卡的IDE,它允许您维护源代码管理存储库,而无需首先编写数据库对象脚本。通常,只要完成将数据库链接到源代码管理存储库后,“操作中心”选项卡即会自动打开,但仍可以通过键盘组合键Ctrl + Alt + A或通过右键单击源控制链接的数据库并导航到行动中心选项。

0

我的解决方案只是版本历史记录。我有一个预定的powershell脚本,可以生成指定对象(存储过程,函数,表和视图)的定义。然后它使用git来更新GitLab存储库。如果文件内容有变化,Git将只会更新,因此每次生成所有脚本都可以。

function SQL-Script-Database 
{ 
    <# 
    .SYNOPSIS 
    Script all database objects for the given database. 

    .DESCRIPTION 
    This function scripts all database objects (i.e.: tables, views, stored 
    procedures, and user defined functions) for the specified database on the 
    the given server. It creates a subdirectory per object type under 
    the path specified. 

    .PARAMETER savePath 
    The root path where to save object definitions. 

    .PARAMETER database 
    The database to script (default = $global:DatabaseName) 

    .PARAMETER DatabaseServer 
    The database server to be used (default: $global:DatabaseServer). 

    #> 

    param (
     [parameter(Mandatory = $true)][string] $savePath, 
     [parameter(Mandatory = $false)][string] $database = $global:DatabaseName, 
     [parameter(Mandatory = $false)][string] $DatabaseServer = $global:DatabaseServer 
    ) 

    try 
    { 
     if (!$DatabaseServer) 
      { throw "`$DatabaseServer or `$InstanceName variable is not properly initialized" } 

     [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null 

     $s = New-Object Microsoft.SqlServer.Management.Smo.Server($DatabaseServer) 
     $db = $s.databases[$database] 

     $objects = $db.Tables 
     $objects += $db.Views 
     $objects += $db.StoredProcedures 
     $objects += $db.UserDefinedFunctions 

     $scripter = New-Object ('Microsoft.SqlServer.Management.Smo.Scripter') ($s) 

     $scripter.Options.AnsiFile = $true 
     $scripter.Options.IncludeHeaders = $false 
     $scripter.Options.ScriptOwner = $false 
     $scripter.Options.AppendToFile = $false 
     $scripter.Options.AllowSystemobjects = $false 
     $scripter.Options.ScriptDrops = $false 
     $scripter.Options.WithDependencies = $false 
     $scripter.Options.SchemaQualify = $false 
     $scripter.Options.SchemaQualifyForeignKeysReferences = $false 
     $scripter.Options.ScriptBatchTerminator = $false 

     $scripter.Options.Indexes = $true 
     $scripter.Options.ClusteredIndexes = $true 
     $scripter.Options.NonClusteredIndexes = $true 
     $scripter.Options.NoCollation = $true 

     $scripter.Options.DriAll = $true 
     $scripter.Options.DriIncludeSystemNames = $false 

     $scripter.Options.ToFileOnly = $true 
     $scripter.Options.Permissions = $true 

     foreach ($o in $objects | where {!($_.IsSystemObject)}) 
     { 
      $typeFolder=$o.GetType().Name 

      if (!(Test-Path -Path "$savepath\$typeFolder")) 
       { New-Item -Type Directory -name "$typeFolder"-path "$savePath" | Out-Null } 

      $file = $o -replace "\[|\]" 
      $file = $file.Replace("dbo.", "") 

      $scripter.Options.FileName = "$savePath\$typeFolder\$file.sql" 
      $scripter.Script($o) 
     } 
    } 

    catch 
    { 
     Write-Error "`t`t$($MyInvocation.InvocationName): $_" 
    } 
} 

# repeat line for each database/server to be pushed to version control 
SQL-Script-Database C:\Users\UserName\DbObjDef\FolderName DatabaseName ServerName 

cd C:\Users\UserName\DbObjDef 
git add . 
git commit -m "nightly diff" 
git push -u origin master 
相关问题