Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Replication (2005)
 SQL Server 2005 Transaction replication

Author  Topic 

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 11:38:20
We are implementing 2005 transaction replication on source database to target staging subscring database but we want to keep all transaction changes from source within staging subscribing tables.
If source column gets updated we want to keep old record and new updated record in staging subscriber. Transaction replication synchronizes but does not keep history on subscriber. Do we update stored proc's
anyone have examples of code or ideas??

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-11 : 12:28:42
Replication by itself does not maintain any history of changes. I have not done this but you can try modifying the procs replication uses sp_MSins<tablename, sp_upd<tableName etc to insert/update into your audit tables. I am thinking it might work except it might slow down the replication.

Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 13:51:30
I was thinking the same thing but you have to snapshot first then modify publications and then modify subscribing table and drop PK.

I am wondering if someone has better idea, code examples, etc. How do other DW processes work when they need to capture all transactions from source and migrate those to DW or DW Mart?????
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 13:51:38
I was thinking the same thing but you have to snapshot first then modify publications and then modify subscribing table and drop PK.

I am wondering if someone has better idea, code examples, etc. How do other DW processes work when they need to capture all transactions from source and migrate those to DW or DW Mart?????
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-11 : 13:57:12
quote:
Originally posted by rubble

I was thinking the same thing but you have to snapshot first then modify publications and then modify subscribing table and drop PK.



After you set up replication, go in and modify the procs at the subscriber. Nothing at the publisher level needs to be changed, If I understood you correctly.

Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-11 : 13:59:19
Why not just use triggers?

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 14:31:49
quote:
Originally posted by tkizer

Why not just use triggers?

Tara Kizer
http://weblogs.sqlteam.com/tarad/



We would have to put triggers on every column of all sourced tables then and some of our tables are 20 to 50 columns.

Do you have examples of code or other ideas??
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-11 : 14:45:26
You don't put triggers on columns. You put triggers on tables.

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 14:53:49
I know that..
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-11 : 15:03:23
Then what does this mean:

quote:

We would have to put triggers on every column of all sourced tables



Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 15:12:41
So, tara you recommend using triggers on every table and witin each table have a trigger for inserts, updates, and deletes. The Update trigger will capture data using from deleted to capture before update and from inserted to capture after update (new row)?? like capturing history??
Issue is we may need to synch and re-synch data that I have not thought about yet.

Thanks for your help though and letting me know about triggers are at the table level not column level.
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 15:12:45
So, tara you recommend using triggers on every table and witin each table have a trigger for inserts, updates, and deletes. The Update trigger will capture data using from deleted to capture before update and from inserted to capture after update (new row)?? like capturing history??
Issue is we may need to synch and re-synch data that I have not thought about yet.

Thanks for your help though and letting me know about triggers are at the table level not column level.
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 15:12:49
So, tara you recommend using triggers on every table and witin each table have a trigger for inserts, updates, and deletes. The Update trigger will capture data using from deleted to capture before update and from inserted to capture after update (new row)?? like capturing history??
Issue is we may need to synch and re-synch data that I have not thought about yet.

Thanks for your help though and letting me know about triggers are at the table level not column level.
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 15:12:53
So, tara you recommend using triggers on every table and witin each table have a trigger for inserts, updates, and deletes. The Update trigger will capture data using from deleted to capture before update and from inserted to capture after update (new row)?? like capturing history??
Issue is we may need to synch and re-synch data that I have not thought about yet.

Thanks for your help though and letting me know about triggers are at the table level not column level.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-11 : 15:24:41
Triggers are what people use for auditting data, which is what it sounds like you want to do based upon this:

quote:

to keep old record and new updated record in staging subscriber



I'm pretty sure Brett (x002548) has a blog entry that will generate the trigger code for you for all tables. Check out his blog (brettk).

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 15:25:10
I thought replication what ever type of replication captures all changes from source to the distributor or subscriber or somewhere that stores all transaction changes even multiple changes to the same record over and over again.
You can go after these changes where ever to extract.

Any ideas from anyone??
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 15:27:48
Where do I go to check out his blog?

quote:
Originally posted by tkizer

Triggers are what people use for auditting data, which is what it sounds like you want to do based upon this:

quote:

to keep old record and new updated record in staging subscriber



I'm pretty sure Brett (x002548) has a blog entry that will generate the trigger code for you for all tables. Check out his blog (brettk).

Tara Kizer
http://weblogs.sqlteam.com/tarad/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-05-11 : 15:29:00
His blog is here: http://weblogs.sqlteam.com/brettk/

And here's his trigger blog entry: http://weblogs.sqlteam.com/brettk/archive/2006/11/29/35816.aspx

Tara Kizer
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 15:34:22
Thank you
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-05-11 : 15:43:55
quote:
Originally posted by rubble

I thought replication what ever type of replication captures all changes from source to the distributor or subscriber or somewhere that stores all transaction changes even multiple changes to the same record over and over again.
You can go after these changes where ever to extract.

Any ideas from anyone??



Ntt quite right. Any transaction (whether insert/update/delete) on the publisher is executed as is on the subscriber. There's no "checking" done to see what the previous value was. So there is no history maintained anywhere, that you can go after.

Either you modify the replication procs to insert into your audit tables along with the actual tables or use Triggers as Tara suggested. Understand the performance impact of Triggers first, if that is even an issue.

Dinakar Nethi
SQL Server MVP
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

rubble
Starting Member

24 Posts

Posted - 2007-05-11 : 15:48:39
That is what I am concerned with performance on the source OLTP system.

Go to Top of Page
    Next Page

- Advertisement -