简体   繁体   English

如何运行原始 SQL 来部署数据库更改

[英]How to run raw SQL to deploy database changes

We intend to create DACPAC files using SQL database projects and distribute them automatically to several environments, DEV/QA/PROD, using Azure Pipeline.我们打算使用 SQL 数据库项目创建 DACPAC 文件,并使用 Azure Pipeline 将它们自动分发到多个环境、DEV/QA/PROD。 I can make changes to the schema for a table, view, function, or procedure, but I'm not sure how we can update specific data in a table.我可以更改表、视图、函数或过程的架构,但我不确定如何更新表中的特定数据。 I am sure this is very common use case but unfortunately I am having hard time implementing it.我确信这是非常常见的用例,但不幸的是我很难实现它。

Any idea how can I automate creating/updating/deleting a row for a table?知道如何自动创建/更新/删除表格的行吗?

E.g.: update myTable set myColumn = 5 where someColumn = 'condition'

In your database project you can add a Post Deployment Script在您的数据库项目中,您可以添加部署后脚本

Do not.不要。 Seriously.严重地。 I found DACPAC always to be WAY too limiting for serious operations.我发现 DACPAC 对于严肃的操作来说总是太局限了。 Look how the SQL is generated and - realize how little control you have.查看 SQL 是如何生成的,并意识到您的控制力有多么小。

The standard approach is to have deployment scripts that you generate and that do the changes in the database, plus a table in the db tracking which have executed (possibly with a checksum so you do not need t change the name to update them).标准方法是让您生成部署脚本并在数据库中进行更改,并在数据库中跟踪已执行的表(可能带有校验和,因此您无需更改名称即可更新它们)。

You can easily generate them partially by schema compare (and then generate the change script), but those also allow you to do things like data scrubbing and multi step transformations that DACPAC by design cannot efficiently and easily do.您可以通过模式比较轻松地部分生成它们(然后生成更改脚本),但是这些还允许您执行数据清理和多步转换等 DACPAC 在设计上无法高效且轻松地执行的操作。

There are plenty of frameworks for this around.有很多框架可以解决这个问题。 They generally belong in the category of developer tools.它们通常属于开发人员工具的范畴。

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

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