简体   繁体   English

Visual Studio 2019 中的 SQL Server 数据库项目功能

[英]SQL Server database project functionality In Visual Studio 2019

I have a SQL Server database project created in VS 2019. I'm fairly new in using it and have a couple of questions around deployments and pre-deployment scripts.我有一个在 VS 2019 中创建的 SQL Server 数据库项目。我在使用它时相当陌生,并且对部署和预部署脚本有几个问题。 I noticed another team of ours using a migrations table with their pre-deployment scripts.我注意到我们的另一个团队使用迁移表及其预部署脚本。 I created a bunch of pre-deployment scripts and added them to a PreDacpac folder.我创建了一堆预部署脚本并将它们添加到 PreDacpac 文件夹中。 It's my understanding that you can only have one pre-deployment script file so what is the proper way of including the rest of my scripts on building project and including them in dacpac file?据我了解,您只能拥有一个部署前脚本文件,那么在构建项目中包含其余脚本并将它们包含在 dacpac 文件中的正确方法是什么?

How do I make sure that any modifications to group of tables that the table data is backed up first before making any modifications to them?在对表数据进行任何修改之前,如何确保首先备份对表组的任何修改? Is there a setting for it in the db project? db 项目中是否有它的设置?

Also does anyone know where to turn off the setting for inserting code to RaisingError in build script if data exists in table?如果表中存在数据,有人知道在哪里关闭将代码插入到构建脚本中的 RaisingError 的设置吗?

Thanks谢谢

Pre-deployment scripts预部署脚本

When you add a pre-deployment script the comment at the top explains how to add multiple scripts:添加预部署脚本时,顶部的注释解释了如何添加多个脚本:

 This file contains SQL statements that will be executed before the build script.   
 Use SQLCMD syntax to include a file in the pre-deployment script.          
 Example:      :r .\myfile.sql      

Basically you have one master file that includes other script files.基本上,您有一个包含其他脚本文件的主文件。

Backup database before deployment部署前备份数据库

This depends on your deployment method.这取决于您的部署方法。 For publishing from Visual studio: Right click the project and select publish.从 Visual Studio 发布:右键单击项目并选择发布。 Click the Advanced... button to edit Advanced publish settings.单击Advanced...按钮以编辑高级发布设置。 There is an option "Back up database before deployment".有一个选项“部署前备份数据库”。

RaisingError in build script if data exists in table?如果表中存在数据,在构建脚本中引发错误?

I'm not sure what you mean by this.我不确定你的意思是什么。 But in the advanced publishing settings there is by default a property "Block incremental deployment if data loss might occur".但在高级发布设置中,默认有一个属性“如果可能发生数据丢失,则阻止增量部署”。 If you uncheck this box publishing will not be blocked when your migrations might cause data loss.如果您取消选中此框,当您的迁移可能导致数据丢失时,将不会阻止发布。 If table contains data and you add new columns then migrations wont be blocked even if this button is checked.如果表包含数据并且您添加了新列,则即使选中此按钮也不会阻止迁移。

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

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