【问题标题】:Change Azure SQL Server Collation更改 Azure SQL Server 排序规则
【发布时间】:2016-11-17 07:39:41
【问题描述】:

我们正在尝试将我们的数据库放入 sql azure 中,但遇到了问题。我们有一个排序规则 Latin1_General_CI_AI 的存储过程,其中有一些与 sys.objects 的连接,它似乎具有 SQL_Latin1_General_CP1_CI_AS 排序规则.当我们尝试创建存储过程时,我们得到了错误

无法解决等于操作中“SQL_Latin1_General_CP1_CI_AS”和“Latin1_General_CI_AI”之间的排序规则冲突。

我们能够通过在 sys.object 连接的末尾添加 COLLATE SQL_Latin1_General_CP1_CI_AS 来创建存储过程,但是我们有多个使用 sys.object 的地方,并且我也读过临时表可能有同样的问题。

所以我的问题是,有没有办法更改“服务器”上的排序规则,创建新的 SQL Server(逻辑服务器) 时我什么也看不到。这样可以省去我们到处强制排序的麻烦。

【问题讨论】:

  • 如果您想更改数据库的排序规则,您应该创建一个工单。支持团队会在合理的时间内为您完成。

标签: azure-sql-database collation


【解决方案1】:

以下是 Microsoft 技术支持引导我使用 sqlpackage 导出、修改和创建新数据库的基于命令行的过程。此方法有效,而使用 SSMS 的等效过程导致错误 842。

  1. 导出:sqlpackage.exe /Action:Export /ssn:{database-server}.database.windows.net /sdn:{database} /su:{user-name} /sp:{password} /tf:{local-bacpac-path}

  2. .bacpac 文件重命名为以.zip 结尾。

  3. 从压缩包中提取model.xmlOrigin.xml

  4. model.xml 中,编辑DataSchemaModel/Model/Element[Type="SqlDatabaseOptions"]/Property[Name="Collation"]

  5. 将下面的脚本保存到 hash.ps1 并从 PowerShell 运行 hash.ps1。出现提示时,指定model.xml 的路径。打印model.xml 的哈希的脚本。

  6. Origin.xml 中,使用新哈希更新DacOrigin/Checksums/Checksum[Uri="/model.xml"]

  7. 使用更新的 model.xmlOrigin.xml 文件更新 zip。

  8. 将 zip 文件重命名为再次以 .bacpac 结尾。

  9. 导入:sqlpackage.exe /Action:Import /tsn:{database-server}.database.windows.net /tdn:{database} /tu:{user-name} /tp:{password} /sf:{local-bacpac-path} /p:DatabaseEdition=Standard /p:DatabaseServiceObjective=S1

    使用与您的工作负载相匹配的数据库版本和服务目标来代替 StandardS1


hash.ps1

$modelXmlPath = Read-Host "model.xml file path"
$hasher = [System.Security.Cryptography.HashAlgorithm]::Create("System.Security.Cryptography.SHA256CryptoServiceProvider")
$fileStream = New-Object System.IO.FileStream -ArgumentList @($modelXmlPath, [System.IO.FileMode]::Open)
$hash = $hasher.ComputeHash($fileStream)
$hashString = ""
Foreach ($b in $hash) { $hashString += $b.ToString("X2") }
$fileStream.Close()
$hashString

【讨论】:

    【解决方案2】:

    我可以使用 bacpac 做到这一点。

    1. 使用 Management Studio 中的“导出数据层应用程序”导出数据库
    2. 制作一份 bacpac 副本
    3. 通过将扩展名更改为 .zip 来重命名副本
    4. 打开 zip 并打开 model.xml 文件(使用 7-zip 打开 zip 然后双击在记事本中打开 xml。编辑并保存)
    5. 更改属性名称="Collat​​ion" 值="Latin1_General_CS_AS"
    6. 将 zip 重命名为 bacpac
    7. bacpac 确实包含一个校验和,用于验证包。这需要更新。幸运的是,有一个 dacchksum.exe 实用程序的 git 副本。只需针对新的 bacpac 运行即可获得校验和值。
    8. 将 bacpac 重命名为 zip
    9. 在 zip 中,打开 origin.xml 并更新校验和
    10. 将 zip 重命名为 bacpac
    11. 再次尝试导入!

    【讨论】:

    • 只是对第 7 步的说明,使用“计算”​​而不是“存储”,它可以完美运行!
    • 而不是压缩和使用 dacchksum.exe 运行这个脚本 $modelXmlPath = "path2model\model.xml" $hasher = [System.Security.Cryptography.HashAlgorithm]::Create("System.Security. Cryptography.SHA256CryptoServiceProvider") $fileStream = new-object System.IO.FileStream ` -ArgumentList @($modelXmlPath, [System.IO.FileMode]::Open) $hash = $hasher.ComputeHash($fileStream) $hashString = " " Foreach ($b in $hash) { $hashString += $b.ToString("X2") } $fileStream.Close() $hashString 更新 Orgin.xml 并压缩 blogs.msdn.microsoft.com/azuresqldbsupport/2017/08/16/…
    【解决方案3】:

    目前,无法更改现有 Azure SQL 数据库的排序规则。但是,您可以在创建数据库时指定排序规则。 如果您通过 Azure 门户进行创建,您将在“创建”对话框中看到“整理”选项。在此处查看一些详细信息:https://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started/#create-a-new-azure-sql-database

    【讨论】:

      猜你喜欢
      • 2011-03-28
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-25
      • 2015-04-03
      • 2011-11-14
      相关资源
      最近更新 更多