在配置新的SQL Server 2019时设置兼容性级别。在运行管道时,可以设置此功能吗?
我们最近通过提供新的VM迁移到SQL Server 2019。我们想将向后兼容性设置为真实,因为我们的旧服务器在SQL Server 2012中。
在SQL Server安装过程中运行管道时,是否有任何可用的角色或标志可以将向后兼容设置为TRUE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用SQL SQL Server设置兼容性级别,
使用
compatible_level
设置来提供向后兼容性。设置SQL Server的兼容性级别设置通常用于单个数据库而不是整个服务器。可以使用这样的SQL命令来完成此操作:110
是SQL Server 2012的兼容性级别。它将使数据库相当紧密地运行到SQL Server默认情况下的表现,但是会有一个或两个微妙的差异。 Alter数据库(transact-sql)兼容性级别网页。创建数据库时,服务器主要仅复制模型数据库。因此,如果要更改该服务器上创建的所有数据库的兼容性级别,则需要在模型数据库上设置兼容性级别。
但这不是推荐的方法。
Ansible使用Ansible运行SQL
使用win_shell和Indoke-SQLCMD
没有内置的方式来管理SQL Server数据库。周围有各种各样的工作。一种是使用
win_shell:
选项运行一个称为Indoke-sqlcommand
运行SQL,类似的东西:这是假设您拥有
sqlps
或sqlserver
PowerShell模块已安装。也许也可以使用命令行命令,但我将其作为练习。它可能已经安装了可能更有可能。使用Microsoft.sql.server角色
另一种方法是使用开源
microsoft.sql .Server
Ansible角色。 Microsoft发表了一篇名为部署SQL Server - Ansible方法!具有更完整的描述。但简短地可以如下完成。该角色具有
MSSQL_INPUT_SQL_FILE:
属性,该属性允许设置SQL文件。该文件将包含您要在安装时运行的任何SQL脚本。有关命令,请参见使用上面的SQL部分的设置兼容性级别。可以这样使用:请注意,SQL通常不是 idempotent 。因此,通常建议在创建事物之前检查事物是否存在。但是有限制,一旦删除数据,就不会恢复。幸运的是,数据库兼容性级别是可以多次应用的几件事之一。
Setting the compatibility level using SQL
SQL Server uses a
COMPATIBILITY_LEVEL
setting to provide backwards compatibility. Setting the compatibility level setting of SQL Server is normally applied for an individual database rather than the whole server. This can be done using an SQL Command like this:110
is the compatibility level for SQL Server 2012. It will make the database run fairly closely to how SQL Server 2012 behaves by default, but there will be one or two subtle differences. There is a full list of compatibility levels in the ALTER DATABASE (Transact-SQL) compatibility level web page.When creating a database the server largely just copies the model database. So if you want to change the compatibility level for all databases created on that server going forwards you need to set the compatibility level on the model database like this.
But this is not a recommended approach.
Running SQL using ansible
using win_shell and invoke-sqlcmd
Ansible does not have a built in way to manage SQL Server databases. There are various work arounds. One is to use the
win_shell:
option to run a PowerShell command calledinvoke-sqlcommand
that runs the SQL, something like this:This assumes you have the
SQLPS
orSqlServer
PowerShell module installed. It is probably also possible to use the sqlcmd command line command, but I'll leave that as an exercise. It is probably slightly more likely to already be installed.Using the microsoft.sql.server role
Another way is to use the open source
microsoft.sql.server
ansible role. Microsoft have published an article called Deploy SQL Server – The Ansible way! that has a fuller description. But briefly it can be done as follows.The role has an
mssql_input_sql_file:
attribute that allows the setting of an SQL file. The file would contain any SQL Script you want to run on install. See the Setting the compatibility level using SQL section above for the commands. This can be used like this:Note that SQL is not generally idempotent. As such it is normally advisable to check if things exist before creating them. But there are limits, once you delete data there is no reverting that. Fortunately the database compatibility level is one of the few things that can be applied multiple times.