| title | Replicate Schema Changes | ||
|---|---|---|---|
| description | Learn how to replicate schema changes in SQL Server by using SQL Server Management Studio or Transact-SQL. | ||
| author | MashaMSFT | ||
| ms.author | mathoma | ||
| ms.date | 09/25/2024 | ||
| ms.service | sql | ||
| ms.subservice | replication | ||
| ms.topic | how-to | ||
| ms.custom |
|
||
| helpviewer_keywords |
|
||
| monikerRange | =azuresqldb-mi-current||>=sql-server-2016 |
[!INCLUDEsql-asdbmi] This topic describes how to replicate schema changes in [!INCLUDEssnoversion] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql].
If you make the following schema changes to a published article, they are propagated, by default, to [!INCLUDEmsCoName] [!INCLUDEssNoVersion] Subscribers:
-
ALTER TABLE
-
ALTER VIEW
-
ALTER PROCEDURE
-
ALTER FUNCTION
-
ALTER TRIGGER
In This Topic
-
Before you begin:
-
To replicate schema changes, using:
- The ALTER TABLE ... DROP COLUMN statement is always replicated to all Subscribers whose subscription contains the columns being dropped, even if you disable the replication of schema changes.
If you do not want to replicate schema changes for a publication, disable the replication of schema changes in the Publication Properties - <Publication> dialog box. For more information about accessing this dialog box, see View and Modify Publication Properties.
-
On the Subscription Options page of the Publication Properties - <Publication> dialog box, set the value of the Replicate schema changes property to False.
-
Select OK.
To propagate only specific schema changes, set the property to True before a schema change, and then set it to False after the change is made. Conversely, to propagate most schema changes, but not a given change, set the property to False before the schema change, and then set it to True after the change is made.
You can use replication stored procedures to specify whether these schema changes are replicated. The stored procedure that you use depends on the type of publication.
- At the Publisher on the publication database, execute sp_addpublication (Transact-SQL), specifying a value of
0for@replicate_ddl. For more information, see Create a Publication.
- At the Publisher on the publication database, execute sp_addmergepublication (Transact-SQL), specifying a value of
0for@replicate_ddl. For more information, see Create a Publication.
-
For a publication with replication of schema changes, execute sp_changepublication (Transact-SQL), specifying a value of
replicate_ddlfor@propertyand a value of0for@value. -
Execute the DDL command on the published object.
-
(Optional) Re-enable replicating schema changes by executing sp_changepublication (Transact-SQL), specifying a value of
replicate_ddlfor@propertyand a value of1for@value.
-
For a publication with replication of schema changes, execute sp_changemergepublication (Transact-SQL), specifying a value of
replicate_ddlfor@propertyand a value of0for@value. -
Execute the DDL command on the published object.
-
(Optional) Re-enable replicating schema changes by executing sp_changemergepublication (Transact-SQL), specifying a value of
replicate_ddlfor@propertyand a value of1for@value.