如何将列添加到 SQL Server 2017 中复制的 table 的主键

How to add a column to the primary key of a replicated table in SQL Server 2017

我需要将 table 中的现有列添加到 table 的 PK。 table 已复制,因此我无法仅添加到 SSMS 中。有没有办法做到这一点? PK 已经是 3 列的组合,现在我需要在定义中添加第 4 列。

我想通了,这是执行此操作的脚本:

USE <db name>
GO

exec sp_dropsubscription @publication = N'<publication>', @article = N'<article>', @subscriber = N'<subscriber>', @destination_db = N'<destination db>'
GO

exec sp_droparticle @publication = N'<publication>', @article = N'<article>'
GO

ALTER TABLE [dbo].[<table name>] DROP CONSTRAINT [<constraint name>] WITH ( ONLINE = OFF )
GO

/****** Object:  Index [<index name>]    Script Date: 6/19/2020 7:44:44 AM ******/
ALTER TABLE [dbo].[<table name>] ADD  CONSTRAINT [<constraint name>] PRIMARY KEY CLUSTERED 
(
    [COL1] ASC,
    [COL2] ASC,
    [COL3] ASC, 
    [COL4] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [MFDP00_MFDP00FG08]
GO

exec sp_addarticle @publication='<publication>', @article ='<article>', @source_object='<source object>', @schema_option=<schema option>
GO

exec sp_addsubscription @publication='<publication>', @article='<article>', @subscriber='<subscriber>', @destination_db='<destination db>'
GO