SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Training
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
SQL Azure
Developer
General DBA
ASP.NET / ADO.NET
SQL Azure

USEFUL SITES :

ASP.NET Tutorials
Windows and SQL Azure Tutorials
Cloud Hosting Magazine
SharePoint Tutorials
Windows Server Help

Write for Us

Share your SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server - Part ...
A High Level Comparison Between Oracle and SQL Server

More     
 
Latest FAQ's

Add Node to A SQL Server failover Cluster failed with invalid ...
SQL Server Destination remote server error
Setting Up Data And Log Files For SQL Server
Will Check Constraints Improve Database Performance?

More     
   
Latest Software Reviews

dbForge Review
Spotlight on ApexSQL Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Data Diff - Server-based database comparison tool ...
Spotlight on ApexSQL Doc 2008

More     

articles >> general dba >> Replicating Stored Procedure Execution

Replicating Stored Procedure Execution

By : Muthusamy Anantha Kumar
Jan 31, 2004

Page 2 / 3

Step 4

Now, let’s create the archive tables and the purge procedure on the Subscriber “MAK” [Fig 1.4]

Use sales
go
Create table Orders_Archive (Order_id int constraint Orders_PK1 primary key,
custid int, Date datetime, Total_Amount money, ship_address varchar(300),
archivedate datetime constraint Orders_archive_default default getdate())
Go
Create table Order_Details_Archive (order_details_id int constraint
order_details_PK1 primary key, Order_id int constraint Orders_archive_FK1 foreign
key references Orders_Archive(Order_Id), item_id int, quantity int, unit_price money,
discount decimal (5,2), archivedate datetime constraint Order_details_archive_default
default getdate())
Go
Create procedure Usp_Archive_Purge as
Insert into Orders_Archive (Order_id, custid, Date, Total_Amount, ship_address)
select Order_id, custid, Date, Total_Amount, ship_address from Orders
where convert(varchar(8),date,112)=convert(varchar(8),getdate()-1,112)
Insert into Order_Details_Archive
(order_details_id, Order_id, item_id , quantity , unit_price, discount )
select order_details_id, Order_id, item_id , quantity , unit_price, discount from Order_details
where order_id in (select order_id from orders where convert(varchar(8),date,112)=convert(varchar(8),getdate()-1,112))
Delete from Order_Details where
order_id in (select order_id from orders where convert(varchar(8),date,112)=convert(varchar(8),getdate()-1,112))
Delete from Orders where convert(varchar(8),date,112)=convert(varchar(8),getdate()-1,112)
Go

 

Step 5

Now, let’s add the stored procedure “USP_Archive_Purge” to the replication.

In the publisher “EBONY,” execute the following statements.


use Sales --change to your publishing database name
go
sp_addarticle
@publication ='Sales', --change to your publication
@pre_creation_cmd='none',
@article = 'USP_Archive_Purge' ,
@destination_table = 'USP_Archive_Purge' ,
@type ='proc exec',
@schema_option=0x01,
@destination_owner ='dbo',
@source_owner ='dbo',
@source_object='USP_Archive_Purge' ,
@force_invalidate_snapshot =0,
@status=0
go

exec sp_addsubscription
@publication = N'Sales', --change to your publication
@article = N'USP_Archive_Purge' ,
@subscriber = N'MAK', -- Change to your subscriber name
@destination_db = N'Sales', -- Change to your subscription database name
@sync_type = N'none',
@update_mode = N'read only' ,
@subscription_type = 'PULL' --change this to push or PULL depending on your environment
go
sp_refreshsubscriptions 'Sales' --change to your publisher name
go

 

Step 6

Execute the procedure “USP_Archive_Purge” on the publisher “EBONY” as shown below.

Use Sales
Go
Exec USP_Archive_Purge
Go

 

Results

You can see that some rows have been moved from the source table to archive table and have been deleted.

(5 row(s) affected)
(8 row(s) affected)
(8 row(s) affected)
(5 row(s) affected)

On the Replication folder in Enterprise Manager you will notice that only one transaction has been delivered. [Fig 1.3]

[Fig 1.3]


When you do “sp_browsereplcmds” on the distribution database, you can see only one command that was called, which is executing the procedure.

{call "dbo"."USP_Archive_Purge" }


<< Prev Page     Next Page>>    








C# Help and Tutorials | PHP MySQL Tutorial | Sharepoint Tutorial | Azure Tutorial | Cloud Hosting Magazine | ASP.NET Tutorials | Windows Server Help | Windows Phone Pro | Silverlight Ace | Visual Studio Tutorials | Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | SQL Server Training Videos | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 2010 Jude O'Kelly. All rights reserved