sql-server – DACPAC和SQL序列

我有一个Visual Studio数据库项目(DACPAC),其中包含许多sql序列.但是,当我部署DACPAC时,它总是将序列值重置为Create脚本中包含的认值(在本例中为1).例如
CREATE SEQUENCE [dbo].[MySequence]
AS INT
START WITH 1
INCREMENT BY 1;

任何人都可以建议一种方法来指示DACPAC忽略序列起始值,或者某种方式让DACPAC恢复正确的值作为部署后的步骤吗?

提前致谢

解决方法

当使用SSDT工具时,这是序列的已知问题.有几种解决方案.

>发布时忽略序列对象.
>使用自定义部署筛选器忽略起始值.
>在部署到live之后,使用sp_sequence_get_range而不是RESTART WITH来递增计数器.

1.发布时忽略序列对象

这是最简单的选项,但最尴尬,因为这意味着您必须手动部署序列.
将以下内容添加到发布配置文件

<ExcludeSequences>True</ExcludeSequences>

或者,从命令行

/p:ExcludeObjectType=Sequences

2.使用自定义部署筛选器

首先下载AgileSqlClub’s部署过滤器.
然后将以下内容添加到部署配置文件中:

<AdditionalDeploymentContributors>AgilesqlClub.DeploymentFilterContributor</AdditionalDeploymentContributors>
<AdditionalDeploymentContributorArguments>sqlPackageFilter=IgnoreName(Order_No_Seq)</AdditionalDeploymentContributorArguments>

或者,从命令行:

/p:AdditionalDeploymentContributors=AgilesqlClub.DeploymentFilterContributor
/p:AdditionalDeploymentContributorArguments="sqlPackageFilter=IgnoreName(Order_No_Seq)"

3.使用sp_sequence_get_range

为此而不是在生产服务器上使用RESTART WITH来更改起始值,请使用:

DECLARE @range_first_value sql_VARIANT;
EXEC sp_sequence_get_range
    @sequence_name = 'MySequence',@range_size = 1000,@range_first_value = @range_first_value OUTPUT;

这样,起始值将始终与部署脚本中的预期值匹配.

资源

> Connect issue – 这个链接已经死了
> Forum post discussing the issue
> MSDN for sp_sequence_get_range
> User Voice/Azure Feedback issue – 替换连接问题 – 标记为计划2018-03-16

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...