How To Script SQL Server Replication Stored Procedures

How To Script SQL Server Replication Stored ProceduresOriginally published on

Ever wonder how to script SQL Server replication stored procedures?  If you use SQL stored procedures to replicate commands there’s a very useful procedure in SQL 2000 SP1 and up which will generate the custom insert, update, and delete procedures for all articles in a transactional publication: sp_scriptpublicationcustomprocs. It takes only one parameter – the name of the publication – and is run at the publisher. Details are available in BOL here.

sp_scriptpublicationcustomprocs relies on other stored procedures to create the scripts, some of which have been around since the SQL Server 7.0 days. These SQL replication stored procedures are used to script individual articles and take an article ID as their only parameter (Article IDs are found by querying sysarticles in the published database). For CALL syntax the procedures sp_scriptinsproc, sp_scriptdelproc, and sp_scriptupdproc will generate the insert, delete, and update procedures, respectively. For XCALL syntax use sp_scriptxupdproc to generate the update procedure and sp_scriptxdelproc to generate the delete procedure. For MCALL and SCALL syntax use sp_scriptmappedupdproc to generate the update procedure. (Side note – if you don’t understand the differences between CALL, SCALL, MCALL, and XCALL check out Specifying How Changes Are Propagated for Transactional Articles in BOL)

The ability to script some or all of the procedures necessary for a publication is very useful for many reasons. The obvious is when you already have the data at the subscriber and set up a subscription without synchronization. Or you may want to modify the scripts to do something special at the subscriber. The not so obvious situations are the ones that make life as a DBA interesting. I’ve had developers who didn’t recognize “what all those sp_MS stored procedures were” in their database and included dropping them as part of their deployments. Oops. To be fair I’ve also dropped them unintentionally in moments of stupidity. You know that checkbox that says “Connect to Subscriber and delete record of this subscription at the Subscriber also” when you delete a subscription? Leave that checked next time you drop a subscription in a central subscriber topology and you’ll find out why sp_scriptpublicationcustomprocs is so handy.

Want to Learn More About SQL Server Replication?

If you'd like to learn more about how UpSearch can support your SQL Server database replication initiative, visit SQL Server Replication or contact us today.

About the Author

Microsoft SQL Server MVP & Principal Consultant

Kendal Van Dyke

UpSearch Alum Kendal Van Dyke is a database strategist, community advocate, public speaker and blogger. He is passionate about helping leaders use Microsoft's SQL Server to solve complex problems that protect, unlock and optimize data's value.

Since 1999, Kendal has specialized in SQL Server database management solutions and provided IT strategy consulting. Kendal excels at disaster recovery, high availability planning/implementation and debugging/troubleshooting mission critical SQL Server environments.

Kendal Van Dyke served the SQL Server community as Founder and President of MagicPass, the Orlando, FL based chapter of the Professional Association for SQL Server (PASS). In 2012, Kendal served as a member of the PASS Board of Directors.

Kendal remains active in the SQL Server community as a speaker and blogger. He teaches SQL Server enthusiast and technology leaders how to protect, unlock and optimize data’s value. Since 2008, Kendal has operated a SQL Server focused blog at

Microsoft acknowledged Kendal for his support and outstanding contributions to the SQL Server community by awarding him Microsoft MVP (2011-15). Learn more about Kendal Van Dyke

SQL Server Health Check Series

This blog series will help you decide if UpSearch’s <span style=”color: #0000ff;”><a style=”color: #0000ff;” href=”” target=”_blank”>SQL Server Health Check</a></span> is right for your organization. Follow the links below to learn how you can use our assessment to identify and resolve SQL Server problems.

<li><span style=”color: #0000ff;”><a style=”color: #0000ff;” href=”” target=”_blank”>SQL Server Health Check Introduction</a></span></li>
<li><span style=”color: #0000ff;”><a style=”color: #0000ff;” href=”” target=”_blank”>SQL Server Health Check Benefits</a></span></li>
<li><span style=”color: #0000ff;”><a style=”color: #0000ff;” href=”” target=”_blank”>SQL Server Health Check Process – Step 1</a></span></li>
<li><span style=”color: #0000ff;”><a style=”color: #0000ff;” href=”” target=”_blank”>SQL Server Health Check Process – Step 2</a></span></li>
<li><span style=”color: #0000ff;”><a style=”color: #0000ff;” href=”” target=”_blank”>SQL Server Health Check Process – Step 3</a></span></li>


About UpSearch


UpSearch is a company of data management and analytics experts who enable digital maturity with Microsoft’s technologies. Its mission is to enable every leader to unlock data’s full potential. UpSearch provides full lifecycle support for SQL Server, SQL Server in Azure (IaaS), Azure SQL DB (PaaS), Azure SQL DW (PaaS), Analytics Platform System (APS), and Power BI.