SQL Server - Filter records during Transactional Replication.

Asked By Query Builder
12-Apr-07 02:09 PM
Hi All,

I have a table with a column DeletedDate which stores a logical delete
of a record.

I need to set up transactional replication for reporting purposes that
this deleted records should not be replicated to the subscriber. That
is, if i see a value on the DeletedDate, I don't want that record to
be picked up for replication.

At the same time, when someone marks the record for deletion (by
putting a date on the DeleteDate column), I want that record to be
deleted on the subscriber database. (I can also set up a job to do the
deletes on the subscriber but i'd rather let the replication take care
of it).

Can this scenario be implemented in Microsoft SQL 2000?  I would
appreciate any ideas / thoughts in this matter.

Thanks in advance,
Aravin Rajendra.
SQL Server
(1)
Replication
(1)
Table
(1)
Column
(1)
View
(1)
Date
(1)
Schema
(1)
Proc
(1)
  E replied...
12-Apr-07 02:42 PM
I think you may miss the point of Replication.

Yes, you can set up a Vertical Filter to not Replicate the DeletedDate.

However, if there is a value in DeletedDate but you only want to delete
record on subscriber, that means they (Publisher and subscriber) are non in
sync. all at.
What if next time you re-initiate the Snapshot agent again?  When it pushes
from Publisher to Subscriber, you will still get the same schema and data as
Publisher.

You may want to consider dropping records on pubisher.

Ed
  Hilary Cotter replied...
13-Apr-07 08:35 AM
Basically it looks like you are doing soft deletes.

In this case you want a filter on your table that looks like this where
deleteddate is null

Then you want to modify your modify replication proc so that if the update
for this table involves a value for the deleteddate column that it does not
update this row but rather deletes it.

But I'm a little confused - you say " if i see a value on the DeletedDate, I
don't want that record to be picked up for replication."

But then in the next statement you say "when someone marks the record for
deletion (by putting a date on the DeleteDate column), I want that record to
be
deleted on the subscriber database"

These sound like mutually exclusive statements.

--
Hilary Cotter

Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html

Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
  Ed Murphy replied...
13-Apr-07 01:00 PM
I interpreted the statements as "if DeleteDate is already non-null then
don't replicate" and "if DeleteDate becomes non-null then delete from
subscriber".  In particular, a row with DeleteDate non-null might have
some other column changed (in which case it shouldn't be replicated), or
might have DeleteDate set back to null (in which case it should be
replicated).
  Paul.Ibiso replied...
13-Apr-07 06:24 PM
Why not replicate the table as per normal and have a view on the subscriber
to filter the records you want. If it is absolutely necessary to hve the same
tablenqme you could replicate to another tablename and have the view use the
original tablename.
Paul Ibison
  Greg D. Moore \(Strider\) replied...
16-Apr-07 12:41 AM
985427C98A3A@microsoft.com...

Another option is to replace the stored procs on the subscriber with your
own, which isn't hard to do.



--
Greg Moore
SQL Server DBA Consulting           Remote and Onsite available!
Email: sql  (at)  greenms.com          http://www.greenms.com/sqlserver.html
  Paul.Ibiso replied...
16-Apr-07 09:10 AM
True - this achieves the same end and is not difficult. Probably sounds picky
but I tend to shy away from changing the setup in this sort of way if there
is a standard alternative. If you only have a few servers then there's no
problem, but if you have 100s of SQL Servers then I'd recommend using the out
of the box solution.
Rgds,
Paul Ibison
  Query Builder replied...
20-Apr-07 10:55 AM
First, Thanks for you input.

I apologize for the confusion. Ed Murphy is correct.

Here is a clear explanation of the situation.

Lets say the table has 10 records.
2 of them have a DeleteDate value in the column.

So, I want the 8 records to be replicated to the subscriber.

If a user goes and updates another record with a value in the
deleteDate, I want that record to be deleted in the subscriber. (Now
out of 10, three of them are marked with a value in the DeleteDate).

Also, if a user goes and removes the DeleteDate value on one of the 3
records, I want that record to be inserted into the subscriber table.

I am going to try the way Hilary mentioned and let everyone know the
results.

Thanks again for the help....

Regards,
Aravin
Create New Account
help
Problem with DROP CONSTRAINT SQL Server When I issue the following T-SQL 2008: ALTER TABLE ALIS.mc.LOCApp DROP CONSTRAINT LOCApp_Created_df I get the following errors: Msg 1781, Level 16, State 1, Line 1 Column already has a DEFAULT bound to it. Msg 1750, Level 16, State 0, Line 1 Object Explorer the message I get is: The Default 'LOCApp_Created_df' does not exist on the server. (SQL Manager UI) What is going on? Patrick = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = Patrick Jackman Vancouver, BC 604-874-5774 SQL Server Programming Discussions DELETED.ConcurrencyID (1) ALIS.mc.LOCApp (1) SQL Server (1) IxLOCTypeID (1
Foreign Key constraint between tblA & (tblB + tblC) ? SQL Server Greetings, Yesterday I posted a question about adding a foreign key between a table and a view (which the view would be comprised of 2 tables) and was told that this was not possible. It I INHERITED a system for a subscriber / subscription (to magazines) database. tblA is the History table, tblB is the Active Subscription table and tblC is the Inactive Subscription table. The History table is the sum of the Active and Inactive Tables (rows). If the
Question about index usage in a query SQL Server Hi there Can someone help me with an understanding with respect to how a clustered index is being used in a query I have? I have a table with 3 columns, COL1, COL2, COl3. There is a clustered index IX_FRED on COL1 ASC would really help my understanding of how the plan is constructed. Any help greatly appreciated. SQL Server Programming Discussions SQL Server 2005 (1) SQL Server (1) Uniqueidentifier (1) CREATE PROCEDURE (1) CREATE TABLE (1) CREATE INDEX (1) Nonclustered (1
Advice on Publisher / Subscriber Setup . . . When a Table on Subscriber has "Extra Columns" SQL Server Below is some basic DDL for a Patient and State table. State, as in, 50 States in the USA. Ok. Here is what I'm after I want to setup transactional (pull) replication. I have 2 pieces of information that I ONLY KNOW on the subscriber side, NOT dbo.Patient.PatientFirstVisitDate and the dbo.Patient.StateKey ON THE SUBSCRIBER SIDE, and not have replication blast away those values. Those 2 columns themselves could or could not exist on the the publisher and the subscriber ( using scripts to ensure an EXACT match). . . . . . .and then setup replication after the 2 databases already exist. The option I found to maybe pull this off have not had luck with that. I get a bcp error. However, when I do column filtering on the publisher (Aka, I say that I only want to publish the PatientUUID
Best practice on nullability and default value SQL Server For a table of about 15 columns, is it all not nullable with default values better performance or to support search (hence indexed one way or another). In one environment / database on a sql server 2000 server, I notice that all colums for every User table is nullable with default value and with the understanding that the business needs to upload the sequence of parent to child), my gut reaction was, making all columns for every table nullable is to support, or rather a work-around, for the upload process. . . What's