| title | Configure snapshot properties (Replication SP) | |
|---|---|---|
| description | Use replication stored procedures to configure snapshot properties for Snapshot or Transactional publications. | |
| author | MashaMSFT | |
| ms.author | mathoma | |
| ms.date | 09/25/2024 | |
| ms.service | sql | |
| ms.subservice | replication | |
| ms.topic | how-to | |
| ms.custom |
|
|
| helpviewer_keywords |
|
|
| dev_langs |
|
|
| monikerRange | =azuresqldb-mi-current||>=sql-server-2016 |
[!INCLUDEsql-asdbmi] Snapshot properties can be defined and modified programmatically using replication stored procedures, where the stored procedures used depend on the type of publication.
-
At the Publisher, execute sp_addpublication. Specify a publication name for
@publication, a value of either snapshot or continuous for@repl_freq, and one or more of the following snapshot-related parameters:@alt_snapshot_folder- specify a path if the snapshot for this publication is accessed from that location instead of or in addition to the snapshot default folder.@compress_snapshot- specify a value of true if the snapshot files in the alternate snapshot folder are compressed in the [!INCLUDEmsCoName] CAB file format.@pre_snapshot_script- specify the file name and full path of a .sql file that will be executed at the Subscriber during initialization before the initial snapshot is applied.@post_snapshot_script- specify the file name and full path of a .sql file that will be executed at the Subscriber during initialization after the initial snapshot is applied.@snapshot_in_defaultfolder- specify a value of false if the snapshot is available only in a non-default location.
For more information about creating publications, see Create a Publication.
-
At the Publisher, execute sp_addmergepublication. Specify a publication name for
@publication, a value of either snapshot or continuous for@repl_freq, and one or more of the following snapshot-related parameters:- alt_snapshot_folder - specify a path if the snapshot for this publication is accessed from that location instead of or in addition to the snapshot default folder.
@compress_snapshot- specify a value of true if the snapshot files in the alternate snapshot folder are compressed in the CAB file format.@pre_snapshot_script- specify the file name and full path of a .sql file that will be executed at the Subscriber during initialization before the initial snapshot is applied.@post_snapshot_script- specify the file name and full path of a .sql file that will be executed at the Subscriber during initialization after the initial snapshot is applied.@snapshot_in_defaultfolder- specify a value of false if the snapshot is available only in a non-default location.
-
For more information about creating publications, see Create a Publication.
-
At the Publisher on the publication database, execute sp_changepublication. Specify a value of 1 for
@force_invalidate_snapshotand one of the following values for@property:- alt_snapshot_folder -also specify a new path to the alternate snapshot folder for
@value. - compress_snapshot - also specify a value of either true or false for
@valueto indicate whether the snapshot files in the alternate snapshot folder are compressed in the CAB file format. - pre_snapshot_script - also for
@valuespecify the file name and full path of a .sql file that will be executed at the Subscriber during initialization before the initial snapshot is applied. - post_snapshot_script - also for
@valuespecify the file name and full path of a .sql file that will be executed at the Subscriber during initialization after the initial snapshot is applied. - snapshot_in_defaultfolder - also specify a value of either true or false to indicate whether the snapshot is available only in a non-default location.
- alt_snapshot_folder -also specify a new path to the alternate snapshot folder for
-
(Optional) At the Publisher on the publication database, execute sp_changepublication_snapshot. Specify
@publicationand one or more of the scheduling or security credential parameters being changed.[!IMPORTANT]
When possible, prompt users to enter security credentials at runtime. If you must store credentials in a script file, you must secure the file to prevent unauthorized access. -
Run the Replication Snapshot Agent from the command prompt or start the Snapshot Agent job to generate a new snapshot. For more information, see Create and Apply the Initial Snapshot.
-
At the Publisher on the publication database, execute sp_changemergepublication. Specify a value of 1 for
@force_invalidate_snapshotand one of the following values for@property**:- alt_snapshot_folder -also specify a new path to the alternate snapshot folder for
@value. - compress_snapshot - also specify a value of either true or false for
@valueto indicate whether the snapshot files in the alternate snapshot folder are compressed in the CAB file format. - pre_snapshot_script - also for
@valuespecify the file name and full path of a .sql file that will be executed at the Subscriber during initialization before the initial snapshot is applied. - post_snapshot_script - also for
@valuespecify the file name and full path of a .sql file that will be executed at the Subscriber during initialization after the initial snapshot is applied. - snapshot_in_defaultfolder - also specify a value of either true or false to indicate whether the snapshot is available only in a non-default location.
- alt_snapshot_folder -also specify a new path to the alternate snapshot folder for
-
Run the Replication Snapshot Agent from the command prompt or start the Snapshot Agent job to generate a new snapshot. For more information, see Create and Apply the Initial Snapshot.
This example creates a publication that uses an alternate snapshot folder and a compressed snapshot.
:::code language="sql" source="../codesnippet/tsql/configure-snapshot-prope_1.sql":::