首页 > 解决方案 > How to configure SQLServer DataTools project to be able to publish just views or stored procedures without comparing and deploying schema

问题描述

I have an existing database which is managed by someone else. I have sufficient rights to create some views or stored procedures. Unfortunatelly the database owner sometimes overwrites my changes and my views disappear. I want to create an SQL Server Database Project which then will allow me to just publish the views. I don't want to keep database schema in my project (it changes, it is huge and I don't care about it). I just want to have my views and sp and be able do deploy only them without comparing the schema. Is it possible?

标签: sqlsql-serversql-server-data-tools

解决方案


1)

将视图和存储过程放在一个项目中,将表放在另一个项目中,您使用“相同数据库”引用从第一个项目中引用。

只需部署带有视图/进程的 dacpac,不要将 IncludeCompositeProjects 设置为 true。

确保你没有启用 DropObjectsNotInSource,但这意味着如果你重命名或删除一个 proc/view,你需要手动删除它,但至少你不会删除表等

在投入生产之前对其进行正确测试:)

2)

您正在与“让这个数据库看起来像这个 dacpac”的 dacpac 模型作斗争,所以也许看看其他东西,准备好滚动或 flyway 或 dbup,在那里您仍然可以对您的代码进行源代码控制,但不必担心部署架构等。

如果您真的只需要更新视图和过程,那么您可以在其自己的文件中检查每个对象的源代码控制,例如:

create or alter xx

或者如果是旧版本的 sql:

if exists drop 其次是 create xx

使用类似 powershell 甚至 dos 批处理脚本来生成单个部署脚本:

ls -r *.sql | %{ "r n---file $($_) ---_n";cat $_} > ../deploy.sql

如果您需要更新的只是视图和存储的过程,那么您实际上是在实现梦想 :)


推荐阅读