简体   繁体   English

Azure SQL服务器如何同步数据库结构但不同步数据本身?

[英]How to synchronize database structure but not synchronize data itself in Azure SQL Server?

For example, table T has 3 columns, id , name , city .例如,表 T 有 3 列, idnamecity Now, I add a new column country in the testing environment.现在,我在测试环境中添加了一个新列country I want to sync this change (database structure or scheme) instead of executing this script again in the staging and production environments.我想同步此更改(数据库结构或方案),而不是在登台和生产环境中再次执行此脚本。

I would probably suggest that this isn't the pattern I would go with.我可能会建议这不是我将使用 go 的模式。 Linking your environments together like that is bound to cause issues.像这样将您的环境链接在一起肯定会导致问题。

In the past I have use SQL Server database projects in Visual Studio.过去我在 Visual Studio 中使用过 SQL 服务器数据库项目。 These projects allow you to define the structure of your database in SQL syntax and a nice GUI.这些项目允许您以 SQL 语法和漂亮的 GUI 定义数据库的结构。

Microsoft article showing how to create one Microsoft 文章展示了如何创建一个

This means you can put the project into a git repo and then create a deployment pipeline to promote the changes through the environment stages.这意味着您可以将项目放入 git 存储库中,然后创建部署管道以通过环境阶段促进更改。

The compiled output of the project is called a dacpac and the tooling compares your target db with the structure in the dacpac and makes it match.项目编译后的 output 称为 dacpac,工具将您的目标数据库与 dacpac 中的结构进行比较并使其匹配。 You can control how it does that through config eg don't drop tables, etc.您可以通过配置控制它是如何做到的,例如不要删除表等。

Microsoft article showing deployment steps 显示部署步骤的 Microsoft 文章

Overall this will give you a more refined control over the database schema.总体而言,这将使您对数据库模式进行更精细的控制。

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

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